QBasicAtomicInt::ref() - what the hell is this?
Hi, my app suddenly crashed inside the QBasicAtomicInt::ref() function. I see it's because of some foolishly uninitialized pointers, so I should be able to remedy the situation shortly. So what happened and how to debug it is out of question. Rather, I'm baffled by the function itself:
Code:
inline bool QBasicAtomicInt::ref()
{
unsigned char ret;
asm volatile("lock\n"
"incl %0\n"
"setne %1"
: "=m" (_q_value), "=qm" (ret)
: "m" (_q_value)
: "memory");
return ret != 0;
}
What is it supposed to do? How does it do it? How does asm keyword combine with volatile? Why are asm commands quoted? What are the colons ( : ) doing here? What could '"m" (_q_value)' possibly mean? Please, someone, explain the magic to me :)
Re: QBasicAtomicInt::ref() - what the hell is this?
I am not an asm junkie, but as far as I can tell, most (all?) your questions are answered here:
http://www.ibiblio.org/gferg/ldp/GCC...WTO.html#ss5.4
Re: QBasicAtomicInt::ref() - what the hell is this?
It's an atomic reference counter.
Re: QBasicAtomicInt::ref() - what the hell is this?
Thanks for the answer, that's some interesting reading material. I was only familiar with Intel syntax before :)
Re: QBasicAtomicInt::ref() - what the hell is this?
When this happens, it usually means an object has been double deleted. Use a memory checker like valgrind to go over your code to find the place.