9#ifndef ZEPHYR_INCLUDE_SYS_ATOMIC_H_
10#define ZEPHYR_INCLUDE_SYS_ATOMIC_H_
26#if defined(CONFIG_ATOMIC_OPERATIONS_C)
29#elif defined(CONFIG_ATOMIC_OPERATIONS_ARCH)
59#define ATOMIC_INIT(i) (i)
70#define ATOMIC_PTR_INIT(p) (p)
76#define ATOMIC_BITS (sizeof(atomic_val_t) * 8)
77#define ATOMIC_MASK(bit) BIT((unsigned long)(bit) & (ATOMIC_BITS - 1U))
78#define ATOMIC_ELEM(addr, bit) ((addr) + ((bit) / ATOMIC_BITS))
90#define ATOMIC_BITMAP_SIZE(num_bits) (ROUND_UP(num_bits, ATOMIC_BITS) / ATOMIC_BITS)
111#define ATOMIC_DEFINE(name, num_bits) \
112 atomic_t name[ATOMIC_BITMAP_SIZE(num_bits)]
131 return (1 & (val >> (bit & (ATOMIC_BITS - 1)))) != 0;
152 old =
atomic_and(ATOMIC_ELEM(target, bit), ~mask);
154 return (old & mask) != 0;
175 old =
atomic_or(ATOMIC_ELEM(target, bit), mask);
177 return (old & mask) != 0;
195 (void)
atomic_and(ATOMIC_ELEM(target, bit), ~mask);
213 (void)
atomic_or(ATOMIC_ELEM(target, bit), mask);
233 (void)
atomic_or(ATOMIC_ELEM(target, bit), mask);
235 (void)
atomic_and(ATOMIC_ELEM(target, bit), ~mask);
long atomic_t
Definition atomic_types.h:15
atomic_t atomic_val_t
Definition atomic_types.h:16
atomic_ptr_t atomic_ptr_val_t
Definition atomic_types.h:18
void * atomic_ptr_t
Definition atomic_types.h:17
atomic_val_t atomic_or(atomic_t *target, atomic_val_t value)
Atomic bitwise inclusive OR.
static void atomic_set_bit(atomic_t *target, int bit)
Atomically set a bit.
Definition atomic.h:209
atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value)
Atomic bitwise exclusive OR (XOR).
static bool atomic_test_bit(const atomic_t *target, int bit)
Atomically test a bit.
Definition atomic.h:127
static void atomic_clear_bit(atomic_t *target, int bit)
Atomically clear a bit.
Definition atomic.h:191
atomic_ptr_val_t atomic_ptr_get(const atomic_ptr_t *target)
Atomic get a pointer value.
atomic_val_t atomic_get(const atomic_t *target)
Atomic get.
atomic_ptr_val_t atomic_ptr_set(atomic_ptr_t *target, atomic_ptr_val_t value)
Atomic get-and-set for pointer values.
atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value)
Atomic bitwise NAND.
atomic_val_t atomic_and(atomic_t *target, atomic_val_t value)
Atomic bitwise AND.
atomic_val_t atomic_add(atomic_t *target, atomic_val_t value)
Atomic addition.
static bool atomic_test_and_clear_bit(atomic_t *target, int bit)
Atomically test and clear a bit.
Definition atomic.h:147
atomic_ptr_val_t atomic_ptr_clear(atomic_ptr_t *target)
Atomic clear of a pointer value.
atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
Atomic get-and-set.
static bool atomic_test_and_set_bit(atomic_t *target, int bit)
Atomically set a bit.
Definition atomic.h:170
atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value)
Atomic subtraction.
atomic_val_t atomic_clear(atomic_t *target)
Atomic clear.
bool atomic_ptr_cas(atomic_ptr_t *target, atomic_ptr_val_t old_value, atomic_ptr_val_t new_value)
Atomic compare-and-set with pointer values.
atomic_val_t atomic_inc(atomic_t *target)
Atomic increment.
bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
Atomic compare-and-set.
atomic_val_t atomic_dec(atomic_t *target)
Atomic decrement.
static void atomic_set_bit_to(atomic_t *target, int bit, bool val)
Atomically set a bit to a given value.
Definition atomic.h:228