Atomically set a flag (C11)
#include <stdatomic.h>
_Bool atomic_flag_test_and_set( volatile atomic_flag *obj );
_Bool atomic_flag_test_and_set_explicit( volatile atomic_flag *obj,
memory_order order );
The atomic_flag_test_and_set() and atomic_flag_test_and_set_explicit() functions atomically set the given atomic flag to true and return the previous value. The atomic_flag_test_and_set() function orders memory access according to memory_order_seq_cst; atomic_flag_test_and_set_explicit() orders them as specified by order.
The previous value.
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | Read the Caveats |
| Signal handler | Read the Caveats |
| Thread | Yes |
If this function is lock-free (see atomic_is_lock_free()), it's safe to call it from an ISR or signal handler.