atomic_fetch_and(), atomic_fetch_and_explicit()

Atomically AND a value into an atomic object (C11)

Synopsis:

#include <stdatomic.h>

C atomic_fetch_and( volatile A *obj,
                    M arg );

C atomic_fetch_and_explicit( volatile A *obj,
                             M arg,
                             memory_order order );

Arguments:

obj
A pointer to the atomic object (see the atomic_* types) whose value you want to AND something with.
arg
The value you want to AND in to the object. “M” is either the non-atomic type corresponding to A if A is an atomic integer type, or ptrdiff_t if A is an atomic pointer type.
order
(atomic_fetch_and_explicit() only) The memory_order to use for the operation.

Library:

Description:

The atomic_fetch_and() and atomic_fetch_and_explicit() functions are generic functions that atomically AND the given value in to the given atomic object. The atomic_fetch_and() function orders memory access according to memory_order_seq_cst; atomic_fetch_and_explicit() orders them as specified by order.

Returns:

The previous value of the atomic object. The “C” represents the non-atomic data type that corresponds to the atomic object.

Classification:

C11

Safety:  
Cancellation point No
Interrupt handler Read the Caveats
Signal handler Read the Caveats
Thread Yes

Caveats:

If this function is lock-free (see atomic_is_lock_free()), it's safe to call it from an ISR or signal handler.