19 #ifndef __MBED_UTIL_ATOMIC_H__ 20 #define __MBED_UTIL_ATOMIC_H__ 27 #include "platform/mbed_toolchain.h" 57 mbed_memory_order_relaxed = 0x00,
58 mbed_memory_order_consume = 0x01,
59 mbed_memory_order_acquire = 0x02,
60 mbed_memory_order_release = 0x04,
61 mbed_memory_order_acq_rel = 0x06,
62 mbed_memory_order_seq_cst = 0x16
66 #ifndef MBED_EXCLUSIVE_ACCESS 67 #ifndef __EXCLUSIVE_ACCESS 68 #if defined __arm__ || defined __ICC_ARM__ || defined __ARM_ARCH 69 #if ((__ARM_ARCH_7M__ == 1U) || \ 70 (__ARM_ARCH_7EM__ == 1U) || \ 71 (__ARM_ARCH_8M_BASE__ == 1U) || \ 72 (__ARM_ARCH_8M_MAIN__ == 1U) || \ 73 (__ARM_ARCH_8_1M_MAIN__ == 1U)) || \ 74 (__ARM_ARCH_7A__ == 1U) 75 #define MBED_EXCLUSIVE_ACCESS 1U 76 #define MBED_EXCLUSIVE_ACCESS_THUMB1 (__ARM_ARCH_8M_BASE__ == 1U) 79 #define MBED_EXCLUSIVE_ACCESS_ARM 1U 81 #define MBED_EXCLUSIVE_ACCESS_ARM 0U 84 #if !defined (__thumb__) 85 #define MBED_EXCLUSIVE_ACCESS_ARM 1U 87 #define MBED_EXCLUSIVE_ACCESS_ARM 0U 90 #elif (__ARM_ARCH_6M__ == 1U) 91 #define MBED_EXCLUSIVE_ACCESS 0U 92 #elif defined __aarch64__ // Apple M1 Mac 93 #define MBED_EXCLUSIVE_ACCESS 0U 95 #error "Unknown ARM architecture for exclusive access" 96 #endif // __ARM_ARCH_xxx 97 #else // __arm__ || defined __ICC_ARM__ || defined __ARM_ARCH 99 #define MBED_EXCLUSIVE_ACCESS 0U 102 #define MBED_EXCLUSIVE_ACCESS __EXCLUSIVE_ACCESS 106 #if MBED_EXCLUSIVE_ACCESS 107 #define MBED_INLINE_IF_EX inline 109 #define MBED_INLINE_IF_EX 130 #define CORE_UTIL_ATOMIC_FLAG_INIT { 0 } 219 MBED_INLINE_IF_EX
bool core_util_atomic_cas_u8(
volatile uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue);
228 MBED_INLINE_IF_EX
bool core_util_atomic_cas_u16(
volatile uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue);
234 MBED_INLINE_IF_EX
bool core_util_atomic_cas_u32(
volatile uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue);
886 #include <mstd_type_traits> 902 template<
typename T> T core_util_atomic_load(
const volatile T *valuePtr) noexcept;
904 template<
typename T> T core_util_atomic_load(
const T *valuePtr) noexcept;
906 template<
typename T>
void core_util_atomic_store(
volatile T *valuePtr, mstd::type_identity_t<T> desiredValue) noexcept;
908 template<
typename T>
void core_util_atomic_store(T *valuePtr, mstd::type_identity_t<T> desiredValue) noexcept;
910 template<
typename T> T core_util_atomic_exchange(
volatile T *ptr, mstd::type_identity_t<T> desiredValue) noexcept;
912 template<
typename T>
bool core_util_atomic_compare_exchange_strong(
volatile T *ptr, mstd::type_identity_t<T> *expectedCurrentValue, mstd::type_identity_t<T> desiredValue) noexcept;
914 template<
typename T>
bool core_util_atomic_compare_exchange_weak(
volatile T *ptr, mstd::type_identity_t<T> *expectedCurrentValue, mstd::type_identity_t<T> desiredValue) noexcept;
916 template<
typename T> T core_util_atomic_fetch_add(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
918 template<
typename T> T core_util_atomic_fetch_sub(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
920 template<
typename T> T core_util_atomic_fetch_and(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
922 template<
typename T> T core_util_atomic_fetch_or(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
924 template<
typename T> T core_util_atomic_fetch_xor(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
927 template<
typename T> T core_util_atomic_load_explicit(
const volatile T *valuePtr,
mbed_memory_order order) noexcept;
929 template<
typename T> T core_util_atomic_load_explicit(
const T *valuePtr,
mbed_memory_order order) noexcept;
931 template<
typename T>
void core_util_atomic_store_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> desiredValue,
mbed_memory_order order) noexcept;
933 template<
typename T>
void core_util_atomic_store_explicit(T *valuePtr, mstd::type_identity_t<T> desiredValue,
mbed_memory_order order) noexcept;
935 template<
typename T> T core_util_atomic_exchange_explicit(
volatile T *ptr, mstd::type_identity_t<T> desiredValue,
mbed_memory_order order) noexcept;
937 template<
typename T>
bool core_util_atomic_compare_exchange_strong_explicit(
volatile T *ptr, mstd::type_identity_t<T> *expectedCurrentValue, mstd::type_identity_t<T> desiredValue,
mbed_memory_order success,
mbed_memory_order failure) noexcept;
939 template<
typename T>
bool core_util_atomic_compare_exchange_weak_explicit(
volatile T *ptr, mstd::type_identity_t<T> *expectedCurrentValue, mstd::type_identity_t<T> desiredValue,
mbed_memory_order success,
mbed_memory_order failure) noexcept;
941 template<
typename T> T core_util_atomic_fetch_add_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
943 template<
typename T> T core_util_atomic_fetch_sub_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
945 template<
typename T> T core_util_atomic_fetch_and_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
947 template<
typename T> T core_util_atomic_fetch_or_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
949 template<
typename T> T core_util_atomic_fetch_xor_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
952 template<
typename T>
inline T *core_util_atomic_load(T *
const volatile *valuePtr) noexcept;
954 template<
typename T>
inline T *core_util_atomic_load(T *
const *valuePtr) noexcept;
956 template<
typename T>
inline void core_util_atomic_store(T *
volatile *valuePtr, mstd::type_identity_t<T> *desiredValue) noexcept;
958 template<
typename T>
inline void core_util_atomic_store(T **valuePtr, mstd::type_identity_t<T> *desiredValue) noexcept;
960 template<
typename T>
inline T *core_util_atomic_exchange(T *
volatile *valuePtr, mstd::type_identity_t<T> *desiredValue) noexcept;
962 template<
typename T>
inline bool core_util_atomic_compare_exchange_strong(T *
volatile *ptr, mstd::type_identity_t<T> **expectedCurrentValue, mstd::type_identity_t<T> *desiredValue) noexcept;
964 template<
typename T>
inline bool core_util_atomic_compare_exchange_weak(T *
volatile *ptr, mstd::type_identity_t<T> **expectedCurrentValue, mstd::type_identity_t<T> *desiredValue) noexcept;
966 template<
typename T>
inline T *core_util_atomic_fetch_add(T *
volatile *valuePtr, ptrdiff_t arg) noexcept;
968 template<
typename T>
inline T *core_util_atomic_fetch_sub(T *
volatile *valuePtr, ptrdiff_t arg) noexcept;
971 template<
typename T>
inline T *core_util_atomic_load_explicit(T *
const volatile *valuePtr,
mbed_memory_order order) noexcept;
973 template<
typename T>
inline T *core_util_atomic_load_explicit(T *
const *valuePtr,
mbed_memory_order order) noexcept;
975 template<
typename T>
inline void core_util_atomic_store_explicit(T *
volatile *valuePtr, mstd::type_identity_t<T> *desiredValue,
mbed_memory_order order) noexcept;
977 template<
typename T>
inline void core_util_atomic_store_explicit(T **valuePtr, mstd::type_identity_t<T> *desiredValue,
mbed_memory_order order) noexcept;
979 template<
typename T>
inline T *core_util_atomic_exchange_explicit(T *
volatile *valuePtr, mstd::type_identity_t<T> *desiredValue,
mbed_memory_order order) noexcept;
981 template<
typename T>
inline bool core_util_atomic_compare_exchange_strong_explicit(T *
volatile *ptr, mstd::type_identity_t<T> **expectedCurrentValue, mstd::type_identity_t<T> *desiredValue,
mbed_memory_order success,
mbed_memory_order failure) noexcept;
983 template<
typename T>
inline bool core_util_atomic_compare_exchange_weak_explicit(T *
volatile *ptr, mstd::type_identity_t<T> **expectedCurrentValue, mstd::type_identity_t<T> *desiredValue,
mbed_memory_order success,
mbed_memory_order failure) noexcept;
985 template<
typename T>
inline T *core_util_atomic_fetch_add_explicit(T *
volatile *valuePtr, ptrdiff_t arg,
mbed_memory_order order) noexcept;
987 template<
typename T>
inline T *core_util_atomic_fetch_sub_explicit(T *
volatile *valuePtr, ptrdiff_t arg,
mbed_memory_order order) noexcept;
989 #endif // __cplusplus 996 #include "platform/internal/mbed_atomic_impl.h" 998 #endif // __MBED_UTIL_ATOMICL_H__
A lock-free, primitive atomic flag.