Sets the word or doubleword specified by addr to the value of val and returns the original value of addr, in a single atomic operation.
unsigned int __fetch_and_swap (volatile unsigned int* addr, unsigned int val);
unsigned long __fetch_and_swaplp (volatile unsigned long* addr, unsigned long val);
This operation is useful when a variable is shared between several threads or processes, and one thread needs to update the value of the variable without losing the value that was originally stored in the location.
__fetch_and_swaplp is valid only in 64-bit mode.