Go to the documentation of this file.
136 #ifndef ATOMIC_UTILS_H
137 #define ATOMIC_UTILS_H
142 #include "atomic_utils_arch.h"
150 #if !defined(HAS_ATOMIC_BIT) || defined(DOXYGEN)
574 uint16_t subtrahend);
582 uint32_t subtrahend);
590 uint64_t subtrahend);
700 #define CONCAT(a, b) a ## b
705 #define CONCAT4(a, b, c, d) a ## b ## c ## d
714 #define ATOMIC_LOAD_IMPL(name, type) \
715 static inline type CONCAT(atomic_load_, name)(const type *var) \
717 unsigned state = irq_disable(); \
722 type result = *((const volatile type *)var); \
723 irq_restore(state); \
727 #ifndef HAS_ATOMIC_LOAD_U8
730 #ifndef HAS_ATOMIC_LOAD_U16
733 #ifndef HAS_ATOMIC_LOAD_U32
736 #ifndef HAS_ATOMIC_LOAD_U64
747 #define ATOMIC_STORE_IMPL(name, type) \
748 static inline void CONCAT(atomic_store_, name)(type *dest, type val) \
750 unsigned state = irq_disable(); \
755 *((volatile type *)dest) = val; \
756 irq_restore(state); \
759 #ifndef HAS_ATOMIC_STORE_U8
762 #ifndef HAS_ATOMIC_STORE_U16
765 #ifndef HAS_ATOMIC_STORE_U32
768 #ifndef HAS_ATOMIC_STORE_U64
781 #define ATOMIC_FETCH_OP_IMPL(opname, op, name, type) \
782 static inline void CONCAT4(atomic_fetch_, opname, _, name)(type *dest, \
785 unsigned state = irq_disable(); \
790 volatile type *tmp = dest; \
791 *tmp = *tmp op val; \
792 irq_restore(state); \
795 #ifndef HAS_ATOMIC_FETCH_ADD_U8
798 #ifndef HAS_ATOMIC_FETCH_ADD_U16
801 #ifndef HAS_ATOMIC_FETCH_ADD_U32
804 #ifndef HAS_ATOMIC_FETCH_ADD_U64
808 #ifndef HAS_ATOMIC_FETCH_SUB_U8
811 #ifndef HAS_ATOMIC_FETCH_SUB_U16
814 #ifndef HAS_ATOMIC_FETCH_SUB_U32
817 #ifndef HAS_ATOMIC_FETCH_SUB_U64
821 #ifndef HAS_ATOMIC_FETCH_OR_U8
824 #ifndef HAS_ATOMIC_FETCH_OR_U16
827 #ifndef HAS_ATOMIC_FETCH_OR_U32
830 #ifndef HAS_ATOMIC_FETCH_OR_U64
834 #ifndef HAS_ATOMIC_FETCH_XOR_U8
837 #ifndef HAS_ATOMIC_FETCH_XOR_U16
840 #ifndef HAS_ATOMIC_FETCH_XOR_U32
843 #ifndef HAS_ATOMIC_FETCH_XOR_U64
847 #ifndef HAS_ATOMIC_FETCH_AND_U8
850 #ifndef HAS_ATOMIC_FETCH_AND_U16
853 #ifndef HAS_ATOMIC_FETCH_AND_U32
856 #ifndef HAS_ATOMIC_FETCH_AND_U64
860 #ifndef HAS_ATOMIC_BIT
928 #if defined(HAS_ATOMIC_FETCH_ADD_U8) || !defined(HAS_ATOMIC_STORE_U8)
938 #if defined(HAS_ATOMIC_FETCH_ADD_U16) || !defined(HAS_ATOMIC_STORE_U16)
948 #if defined(HAS_ATOMIC_FETCH_ADD_U32) || !defined(HAS_ATOMIC_STORE_U32)
958 #if defined(HAS_ATOMIC_FETCH_ADD_U64) || !defined(HAS_ATOMIC_STORE_U64)
969 #if defined(HAS_ATOMIC_FETCH_SUB_U8) || !defined(HAS_ATOMIC_STORE_U8)
979 #if defined(HAS_ATOMIC_FETCH_SUB_U16) || !defined(HAS_ATOMIC_STORE_U16)
989 #if defined(HAS_ATOMIC_FETCH_SUB_U32) || !defined(HAS_ATOMIC_STORE_U32)
999 #if defined(HAS_ATOMIC_FETCH_SUB_U64) || !defined(HAS_ATOMIC_STORE_U64)
1010 #if defined(HAS_ATOMIC_FETCH_OR_U8) || !defined(HAS_ATOMIC_STORE_U8)
1020 #if defined(HAS_ATOMIC_FETCH_OR_U16) || !defined(HAS_ATOMIC_STORE_U16)
1030 #if defined(HAS_ATOMIC_FETCH_OR_U32) || !defined(HAS_ATOMIC_STORE_U32)
1040 #if defined(HAS_ATOMIC_FETCH_OR_U64) || !defined(HAS_ATOMIC_STORE_U64)
1051 #if defined(HAS_ATOMIC_FETCH_XOR_U8) || !defined(HAS_ATOMIC_STORE_U8)
1061 #if defined(HAS_ATOMIC_FETCH_XOR_U16) || !defined(HAS_ATOMIC_STORE_U16)
1071 #if defined(HAS_ATOMIC_FETCH_XOR_U32) || !defined(HAS_ATOMIC_STORE_U32)
1081 #if defined(HAS_ATOMIC_FETCH_XOR_U64) || !defined(HAS_ATOMIC_STORE_U64)
1092 #if defined(HAS_ATOMIC_FETCH_AND_U8) || !defined(HAS_ATOMIC_STORE_U8)
1102 #if defined(HAS_ATOMIC_FETCH_AND_U16) || !defined(HAS_ATOMIC_STORE_U16)
1112 #if defined(HAS_ATOMIC_FETCH_AND_U32) || !defined(HAS_ATOMIC_STORE_U32)
1122 #if defined(HAS_ATOMIC_FETCH_AND_U64) || !defined(HAS_ATOMIC_STORE_U64)
static atomic_bit_u32_t atomic_bit_u32(uint32_t *dest, uint8_t bit)
Create a reference to a bit in an uint32_t
static void atomic_fetch_and_u64(uint64_t *dest, uint64_t val)
Atomic version of *dest &= val
static void atomic_fetch_or_u8(uint8_t *dest, uint8_t val)
Atomic version of *dest |= val
static void atomic_fetch_or_u64(uint64_t *dest, uint64_t val)
Atomic version of *dest |= val
static void atomic_fetch_and_u8(uint8_t *dest, uint8_t val)
Atomic version of *dest &= val
Type specifying a bit in an uint64_t
static atomic_bit_u8_t atomic_bit_u8(uint8_t *dest, uint8_t bit)
Create a reference to a bit in an uint8_t
static void atomic_store_u32(uint32_t *dest, uint32_t val)
Store an uint32_t atomically.
static void semi_atomic_fetch_sub_u32(uint32_t *dest, uint32_t subtrahend)
Semi-atomically subtract a value from a given value.
static void atomic_fetch_or_u16(uint16_t *dest, uint16_t val)
Atomic version of *dest |= val
static void semi_atomic_fetch_xor_u8(uint8_t *dest, uint8_t val)
Semi-atomic version of *dest ^= val
static void atomic_fetch_sub_u8(uint8_t *dest, uint8_t subtrahend)
Atomically subtract a value from a given value.
uint8_t mask
Bitmask used for setting the bit.
static void atomic_fetch_or_u32(uint32_t *dest, uint32_t val)
Atomic version of *dest |= val
static void atomic_store_u64(uint64_t *dest, uint64_t val)
Store an uint64_t atomically.
static void atomic_fetch_xor_u32(uint32_t *dest, uint32_t val)
Atomic version of *dest ^= val
static void atomic_clear_bit_u32(atomic_bit_u32_t bit)
Atomic version of *dest &= ~(1 << bit)
static void atomic_clear_bit_u16(atomic_bit_u16_t bit)
Atomic version of *dest &= ~(1 << bit)
static void atomic_fetch_and_u16(uint16_t *dest, uint16_t val)
Atomic version of *dest &= val
static void atomic_set_bit_u16(atomic_bit_u16_t bit)
Atomic version of *dest |= (1 << bit)
static void semi_atomic_fetch_sub_u8(uint8_t *dest, uint8_t subtrahend)
Semi-atomically subtract a value from a given value.
static void atomic_set_bit_u8(atomic_bit_u8_t bit)
Atomic version of *dest |= (1 << bit)
static void atomic_clear_bit_u64(atomic_bit_u64_t bit)
Atomic version of *dest &= ~(1 << bit)
static void atomic_clear_bit_u8(atomic_bit_u8_t bit)
Atomic version of *dest &= ~(1 << bit)
static void semi_atomic_fetch_or_u32(uint32_t *dest, uint32_t val)
Semi-atomic version of *dest |= val
static void semi_atomic_fetch_and_u8(uint8_t *dest, uint8_t val)
Semi-atomic version of *dest &= val
static void atomic_fetch_add_u64(uint64_t *dest, uint64_t summand)
Atomically add a value onto a given value.
uint32_t mask
Bitmask used for setting the bit.
static void atomic_store_u16(uint16_t *dest, uint16_t val)
Store an uint16_t atomically.
uint32_t * dest
Memory containing the bit to set/clear.
#define ATOMIC_STORE_IMPL(name, type)
Generates a static inline function implementing atomic_store_u<width>()
uint64_t mask
Bitmask used for setting the bit.
static uint16_t atomic_load_u16(const uint16_t *var)
Load an uint16_t atomically.
static void atomic_fetch_add_u8(uint8_t *dest, uint8_t summand)
Atomically add a value onto a given value.
static void atomic_store_u8(uint8_t *dest, uint8_t val)
Store an uint8_t atomically.
static atomic_bit_u64_t atomic_bit_u64(uint64_t *dest, uint8_t bit)
Create a reference to a bit in an uint64_t
#define ATOMIC_FETCH_OP_IMPL(opname, op, name, type)
Generates a static inline function implementing atomic_fecth_<op>_u<width>()
Type specifying a bit in an uint16_t
static void semi_atomic_fetch_and_u64(uint64_t *dest, uint64_t val)
Semi-atomic version of *dest &= val
static atomic_bit_u16_t atomic_bit_u16(uint16_t *dest, uint8_t bit)
Create a reference to a bit in an uint16_t
static void semi_atomic_fetch_and_u32(uint32_t *dest, uint32_t val)
Semi-atomic version of *dest &= val
static void semi_atomic_fetch_sub_u16(uint16_t *dest, uint16_t subtrahend)
Semi-atomically subtract a value from a given value.
static void atomic_fetch_add_u32(uint32_t *dest, uint32_t summand)
Atomically add a value onto a given value.
uint8_t * dest
Memory containing the bit to set/clear.
static void semi_atomic_fetch_or_u64(uint64_t *dest, uint64_t val)
Semi-atomic version of *dest |= val
static uint32_t atomic_load_u32(const uint32_t *var)
Load an uint32_t atomically.
static void semi_atomic_fetch_xor_u32(uint32_t *dest, uint32_t val)
Semi-atomic version of *dest ^= val
static void semi_atomic_fetch_sub_u64(uint64_t *dest, uint64_t subtrahend)
Semi-atomically subtract a value from a given value.
static void atomic_fetch_xor_u8(uint8_t *dest, uint8_t val)
Atomic version of *dest ^= val
Type specifying a bit in an uint8_t
static void atomic_fetch_sub_u16(uint16_t *dest, uint16_t subtrahend)
Atomically subtract a value from a given value.
static void atomic_fetch_sub_u64(uint64_t *dest, uint64_t subtrahend)
Atomically subtract a value from a given value.
static void atomic_fetch_xor_u64(uint64_t *dest, uint64_t val)
Atomic version of *dest ^= val
static void semi_atomic_fetch_add_u32(uint32_t *dest, uint32_t summand)
Semi-atomically add a value onto a given value.
static void semi_atomic_fetch_or_u16(uint16_t *dest, uint16_t val)
Semi-atomic version of *dest |= val
static void semi_atomic_fetch_or_u8(uint8_t *dest, uint8_t val)
Semi-atomic version of *dest |= val
static void semi_atomic_fetch_add_u8(uint8_t *dest, uint8_t summand)
Semi-atomically add a value onto a given value.
static void atomic_fetch_sub_u32(uint32_t *dest, uint32_t subtrahend)
Atomically subtract a value from a given value.
static void semi_atomic_fetch_xor_u64(uint64_t *dest, uint64_t val)
Semi-atomic version of *dest ^= val
#define ATOMIC_LOAD_IMPL(name, type)
Generates a static inline function implementing atomic_load_u<width>()
static uint64_t atomic_load_u64(const uint64_t *var)
Load an uint64_t atomically.
static void atomic_fetch_add_u16(uint16_t *dest, uint16_t summand)
Atomically add a value onto a given value.
uint64_t * dest
Memory containing the bit to set/clear.
Type specifying a bit in an uint32_t
static void semi_atomic_fetch_and_u16(uint16_t *dest, uint16_t val)
Semi-atomic version of *dest &= val
static uint8_t atomic_load_u8(const uint8_t *var)
Load an uint8_t atomically.
static void semi_atomic_fetch_add_u16(uint16_t *dest, uint16_t summand)
Semi-atomically add a value onto a given value.
static void semi_atomic_fetch_xor_u16(uint16_t *dest, uint16_t val)
Semi-atomic version of *dest ^= val
static void atomic_fetch_xor_u16(uint16_t *dest, uint16_t val)
Atomic version of *dest ^= val
uint16_t mask
Bitmask used for setting the bit.
static void semi_atomic_fetch_add_u64(uint64_t *dest, uint64_t summand)
Semi-atomically add a value onto a given value.
uint16_t * dest
Memory containing the bit to set/clear.
static void atomic_set_bit_u32(atomic_bit_u32_t bit)
Atomic version of *dest |= (1 << bit)
static void atomic_set_bit_u64(atomic_bit_u64_t bit)
Atomic version of *dest |= (1 << bit)
static void atomic_fetch_and_u32(uint32_t *dest, uint32_t val)
Atomic version of *dest &= val