using asm() to execute an atomic subtraction instruction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For a school project, I have to implement a simple atomic_sub() function in
c.  The implementation must use the asm() function.

Right now, my code looks like this

void atomic_sub( int * value, int dec_val) {
   asm ("LOCK SUB (%0), %1;\n"
           :
           : "r" (value), "r" (dec_val)
           : "memory");
}

The intention is for "value" to decrement by "dec_val" atomically, but when
I try to compile I get the following error.

"locking.c:28: Error: expecting lockable instruction after 'lock'"

This asm() call is on line 28, so this is the instruction the error is
referring to.  Does anyone know why this isn't a lockable instruction? 
According to the documentation from Intel I've read, a sub with a
destination of a memory address is lockable.  Any ideas?



--
View this message in context: http://gcc.1065356.n5.nabble.com/using-asm-to-execute-an-atomic-subtraction-instruction-tp873076.html
Sent from the gcc - Help mailing list archive at Nabble.com.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux