So I was reading http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html, and came across this:
type __sync_and_and_fetch (type *ptr, type value, ...)
type __sync_xor_and_fetch (type *ptr, type value, ...)
type __sync_nand_and_fetch (type *ptr, type value, ...)
These builtins perform the operation suggested by the name, and return the new value. That is,
{ *ptr op= value; return *ptr; }
{ *ptr = ~*ptr & value; return *ptr; } // nand
Is this code literal? or is it just to explain what gcc is doing atomically using c-like syntax? And if this is the direct translation, can someone explain how it is atomic?