Closed mihkhub closed 6 years ago
bool __sync_bool_compare_and_swap (type *ptr, type oldval, type newval, ...);
type __sync_val_compare_and_swap (type *ptr, type oldval, type newval, ...);
These built-in functions perform an atomic compare and swap. That is, if the
current value of *ptr
is oldval
, then write newval
into *ptr
.
The “bool” version returns true if the comparison is successful and newval
is
written. The “val” version returns the contents of *ptr
before the operation.
type __sync_fetch_and_and (type *ptr, type value, ...);
These built-in functions perform the operation suggested by the name, and returns the value that had previously been in memory. That is,
{ tmp = *ptr; *ptr op= value; return tmp; };
{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; }; // nand
These built-in functions 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
GCC allows any integral scalar or pointer type that is 1, 2, 4 or 8 bytes in length.