|
P99
|
Collaboration diagram for C11 atomic operations:Modules | |
| Stub replacements of C11 atomic operations | |
| Atomic_macros | |
| Atomic_enum | |
| Atomic_types | |
| Memory Fences | |
Defines | |
| #define | atomic_compare_exchange_weak(OBJP, EXPECTED, DESIRED) |
| Atomically compare *OBJP to *EXPECTED and set it to DESIRED if they are equal. | |
| #define | atomic_exchange(OBJP, DESIRED) |
| Store DESIRED into the object behind OBJP and return its previous value. | |
| #define | atomic_fetch_add(OBJP, OPERAND) P00_FETCH_OP((OBJP), (OPERAND), __sync_fetch_and_add, +=) |
| Atomically add OPERAND to *OBJP. | |
| #define | atomic_fetch_add_conditional(OBJP, OPERAND) |
| #define | atomic_fetch_and(OBJP, OPERAND) P00_FETCH_OP((OBJP), (OPERAND), __sync_fetch_and_and, &=) |
| Atomically do a bitwise AND operation between OPERAND and *OBJP. | |
| #define | atomic_fetch_max(OBJP, OPERAND) |
| #define | atomic_fetch_or(OBJP, OPERAND) P00_FETCH_OP((OBJP), (OPERAND), __sync_fetch_and_or, |=) |
| Atomically do a bitwise OR operation between OPERAND and *OBJP. | |
| #define | atomic_fetch_sub(OBJP, OPERAND) P00_FETCH_OP((OBJP), (OPERAND), __sync_fetch_and_sub, -=) |
| Atomically subtract OPERAND from *OBJP. | |
| #define | atomic_fetch_xor(OBJP, OPERAND) P00_FETCH_OP((OBJP), (OPERAND), __sync_fetch_and_xor, ^=) |
| Atomically do a bitwise XOR operation between OPERAND and *OBJP. | |
| #define | atomic_init(OBJP, VAL) |
| Initialize the object behind OBJP with value VAL. | |
| #define | atomic_is_lock_free(OBJP) (!offsetof(__typeof__(*OBJP), p00_xval)) |
| return true if OBJP points to a lock-free object | |
| #define | atomic_load(OBJP) |
| Return the value of the object behind OBJP. | |
| #define | atomic_store(OBJP, DES) |
| Store DESIRED into the object behind OBJP. | |
| #define | P99_CRITICAL |
| Protect the following block or statement as a critical section of the program. | |
| #define | P99_FIFO(T) P99_PASTE2(p00_fifo_, T) |
| #define | P99_FIFO_APPEND(L, EL) |
| Append element EL to an atomic FIFO L. | |
| #define | P99_FIFO_CLEAR(L) |
| Atomically clear an atomic FIFO L and return a pointer to the start of the list that it previously contained. | |
| #define | P99_FIFO_DECLARE(T) |
| #define | P99_FIFO_INITIALIZER(HEAD, TAIL) |
| #define | P99_FIFO_POP(L) |
| Pop the front element from an atomic FIFO L. | |
| #define | P99_FIFO_TABULATE(TYPE, TAB, L) |
| #define | P99_LIFO(T) _Atomic(P99_PASTE2(p00_lifo_, T)) |
| #define | P99_LIFO_CLEAR(L) atomic_exchange(L, 0) |
| Atomically clear an atomic LIFO L and return a pointer to the start of the list that it previously contained. | |
| #define | P99_LIFO_DECLARE(T) |
| #define | P99_LIFO_INITIALIZER(VAL) ATOMIC_VAR_INIT((void*)VAL) |
| #define | P99_LIFO_POP(L) |
| Pop the top element from an atomic LIFO L. | |
| #define | P99_LIFO_PUSH(L, EL) |
| Push element EL into an atomic LIFO L. | |
| #define | P99_LIFO_TABULATE(TYPE, TAB, L) |
| #define | P99_LIFO_TOP(L) atomic_load(L) |
| Return a pointer to the top element of an atomic LIFO L. | |
| #define | P99_SPIN_EXCLUDE(FLAGP) |
| Protect the following block or statement as a critical section of the program by using FLAGP as a spinlock. | |
Functions | |
| void | atomic_flag_clear (volatile atomic_flag *p00_objp) |
Unconditionally set *p00_objp to false. | |
| void | atomic_flag_clear_explicit (volatile atomic_flag *p00_objp, memory_order p00_ord) |
Unconditionally set *p00_objp to false. | |
| void | atomic_flag_lock (volatile atomic_flag *p00_objp) |
| extension: spin on p00_objp setting the flag until the state before was "clear" | |
| _Bool | atomic_flag_test_and_set (volatile atomic_flag *p00_objp) |
Unconditionally set *object to true and return the previous value. | |
| _Bool | atomic_flag_test_and_set_explicit (volatile atomic_flag *p00_objp, memory_order p00_ord) |
Unconditionally set *object to true and return the previous value. | |
| _Bool | atomic_flag_trylock (volatile atomic_flag *p00_objp) |
| extension: set the flag and return true if we are the first to do so | |
| void | atomic_flag_unlock (volatile atomic_flag *p00_objp) |
| extension: clear the flag unconditionally | |
This is a stub implementation of C11 atomic types and operations.
This uses gcc extensions
__typeof__ to declare typedef or local variables of a specific type({ ... })We also use __sync_lock_test_and_set and other similar built-ins if they are available. If not, __sync_lock_test_and_set and __sync_lock_release are implemented in assembler (for 4 byte integers) and all other operations are synthesized with an atomic_flag that is used as a spinlock.
1.7.6.1