Conditionally updates a single word or doubleword variable atomically.
int __compare_and_swap (volatile int* addr, int* old_val_addr, int new_val);
int __compare_and_swaplp (volatile long* addr, long* old_val_addr, long new_val);
Returns true (1) if the value in addr was equal to old_value and has been set to the new value. Returns false (0) if the value in addr was not equal to old_value and has been left unchanged. In either case, the contents of the memory location specified by addr are copied into the memory location specified by old_val_addr.
The __compare_and_swap function is useful when a single word value must be updated only if it has not been changed since it was last read. If you use __compare_and_swap as a locking primitive, insert a call to the __isync built-in function at the start of any critical sections.
__compare_and_swaplp is valid only in 64-bit mode.