__fetch_and_add, __builtin_ppc_fetch_and_add, __fetch_and_addlp, __builtin_ppc_fetch_and_addlp
Purpose
Clears and sets bits in the word or doubleword specified by addr by ADD-ing that value with the value specified by val, in a single atomic operation, and returns the original value of addr.
Prototype
int __builtin_ppc_fetch_and_add (volatile int* addr, int val);
long __builtin_ppc_fetch_and_addlp (volatile long* addr, long val);
int __fetch_and_add (volatile int* addr, int val);
long __fetch_and_addlp (volatile long* addr, long val);
- The built-in function in the form of
__name
is a synonym of the built-in function in the form of__builtin_ppc_name
. - The built-in function in the form of
__name
is provided for compatibility with IBM® XL C/C++ for AIX® 16.1.0 or earlier releases. This built-in function form might be deprecated in the future.
Parameters
- addr
- The address of the variable to be ADDed. Must be aligned on a 4-byte boundary for a single word and on an 8-byte boundary for a doubleword.
- value
- The value by which the value in addr is to be ADDed.
Usage
This operation is useful when a variable containing bit flags is shared between several threads or processes.
__fetch_and_addlp
is valid only in 64-bit mode.
This function generates the hardware instruction but does not act as an
instruction movement barrier within the compiler. If that is needed, you must also use the
__fence
function.