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_7A__ == 1U) 74 #define MBED_EXCLUSIVE_ACCESS 1U 75 #define MBED_EXCLUSIVE_ACCESS_THUMB1 (__ARM_ARCH_8M_BASE__ == 1U) 78 #define MBED_EXCLUSIVE_ACCESS_ARM 1U 80 #define MBED_EXCLUSIVE_ACCESS_ARM 0U 83 #if !defined (__thumb__) 84 #define MBED_EXCLUSIVE_ACCESS_ARM 1U 86 #define MBED_EXCLUSIVE_ACCESS_ARM 0U 89 #elif (__ARM_ARCH_6M__ == 1U) 90 #define MBED_EXCLUSIVE_ACCESS 0U 92 #error "Unknown ARM architecture for exclusive access" 93 #endif // __ARM_ARCH_xxx 94 #else // __arm__ || defined __ICC_ARM__ || defined __ARM_ARCH 96 #define MBED_EXCLUSIVE_ACCESS 0U 99 #define MBED_EXCLUSIVE_ACCESS __EXCLUSIVE_ACCESS 103 #if MBED_EXCLUSIVE_ACCESS 104 #define MBED_INLINE_IF_EX inline 106 #define MBED_INLINE_IF_EX 127 #define CORE_UTIL_ATOMIC_FLAG_INIT { 0 } 216 MBED_INLINE_IF_EX
bool core_util_atomic_cas_u8(
volatile uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue);
225 MBED_INLINE_IF_EX
bool core_util_atomic_cas_u16(
volatile uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue);
231 MBED_INLINE_IF_EX
bool core_util_atomic_cas_u32(
volatile uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue);
883 #include <mstd_type_traits> 899 template<
typename T> T core_util_atomic_load(
const volatile T *valuePtr) noexcept;
901 template<
typename T> T core_util_atomic_load(
const T *valuePtr) noexcept;
903 template<
typename T>
void core_util_atomic_store(
volatile T *valuePtr, mstd::type_identity_t<T> desiredValue) noexcept;
905 template<
typename T>
void core_util_atomic_store(T *valuePtr, mstd::type_identity_t<T> desiredValue) noexcept;
907 template<
typename T> T core_util_atomic_exchange(
volatile T *ptr, mstd::type_identity_t<T> desiredValue) noexcept;
909 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;
911 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;
913 template<
typename T> T core_util_atomic_fetch_add(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
915 template<
typename T> T core_util_atomic_fetch_sub(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
917 template<
typename T> T core_util_atomic_fetch_and(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
919 template<
typename T> T core_util_atomic_fetch_or(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
921 template<
typename T> T core_util_atomic_fetch_xor(
volatile T *valuePtr, mstd::type_identity_t<T> arg) noexcept;
924 template<
typename T> T core_util_atomic_load_explicit(
const volatile T *valuePtr,
mbed_memory_order order) noexcept;
926 template<
typename T> T core_util_atomic_load_explicit(
const T *valuePtr,
mbed_memory_order order) noexcept;
928 template<
typename T>
void core_util_atomic_store_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> desiredValue,
mbed_memory_order order) noexcept;
930 template<
typename T>
void core_util_atomic_store_explicit(T *valuePtr, mstd::type_identity_t<T> desiredValue,
mbed_memory_order order) noexcept;
932 template<
typename T> T core_util_atomic_exchange_explicit(
volatile T *ptr, mstd::type_identity_t<T> desiredValue,
mbed_memory_order order) noexcept;
934 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;
936 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;
938 template<
typename T> T core_util_atomic_fetch_add_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
940 template<
typename T> T core_util_atomic_fetch_sub_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
942 template<
typename T> T core_util_atomic_fetch_and_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
944 template<
typename T> T core_util_atomic_fetch_or_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
946 template<
typename T> T core_util_atomic_fetch_xor_explicit(
volatile T *valuePtr, mstd::type_identity_t<T> arg,
mbed_memory_order order) noexcept;
949 template<
typename T>
inline T *core_util_atomic_load(T *
const volatile *valuePtr) noexcept;
951 template<
typename T>
inline T *core_util_atomic_load(T *
const *valuePtr) noexcept;
953 template<
typename T>
inline void core_util_atomic_store(T *
volatile *valuePtr, mstd::type_identity_t<T> *desiredValue) noexcept;
955 template<
typename T>
inline void core_util_atomic_store(T **valuePtr, mstd::type_identity_t<T> *desiredValue) noexcept;
957 template<
typename T>
inline T *core_util_atomic_exchange(T *
volatile *valuePtr, mstd::type_identity_t<T> *desiredValue) noexcept;
959 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;
961 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;
963 template<
typename T>
inline T *core_util_atomic_fetch_add(T *
volatile *valuePtr, ptrdiff_t arg) noexcept;
965 template<
typename T>
inline T *core_util_atomic_fetch_sub(T *
volatile *valuePtr, ptrdiff_t arg) noexcept;
968 template<
typename T>
inline T *core_util_atomic_load_explicit(T *
const volatile *valuePtr,
mbed_memory_order order) noexcept;
970 template<
typename T>
inline T *core_util_atomic_load_explicit(T *
const *valuePtr,
mbed_memory_order order) noexcept;
972 template<
typename T>
inline void core_util_atomic_store_explicit(T *
volatile *valuePtr, mstd::type_identity_t<T> *desiredValue,
mbed_memory_order order) noexcept;
974 template<
typename T>
inline void core_util_atomic_store_explicit(T **valuePtr, mstd::type_identity_t<T> *desiredValue,
mbed_memory_order order) noexcept;
976 template<
typename T>
inline T *core_util_atomic_exchange_explicit(T *
volatile *valuePtr, mstd::type_identity_t<T> *desiredValue,
mbed_memory_order order) noexcept;
978 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;
980 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;
982 template<
typename T>
inline T *core_util_atomic_fetch_add_explicit(T *
volatile *valuePtr, ptrdiff_t arg,
mbed_memory_order order) noexcept;
984 template<
typename T>
inline T *core_util_atomic_fetch_sub_explicit(T *
volatile *valuePtr, ptrdiff_t arg,
mbed_memory_order order) noexcept;
986 #endif // __cplusplus 993 #include "platform/internal/mbed_atomic_impl.h" 995 #endif // __MBED_UTIL_ATOMICL_H__
A lock-free, primitive atomic flag.