15 #ifndef RCUTILS__STDATOMIC_HELPER_H_ 16 #define RCUTILS__STDATOMIC_HELPER_H_ 23 # pragma GCC diagnostic push 24 # if defined(__clang__) 25 # pragma clang diagnostic ignored "-Wunused-function" 33 #if defined(__has_feature) 34 #define my__has_feature(...) __has_feature(__VAR_ARGS__) 36 #define my__has_feature(...) 0 39 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ <= 4 && __GNUC_MINOR__ <= 9 42 #else // !defined(__clang__) && defined(__GNUC__) && __GNUC__ <= 4 && __GNUC_MINOR__ <= 9 45 # error "cannot be used with C++ due to a conflict with the C++ <atomic> header, see: p0943r1" 48 # if defined(__has_feature) && !my__has_feature(c_atomic) 52 # include <stdatomic.h> 55 #endif // !defined(__clang__) && defined(__GNUC__) && __GNUC__ <= 4 && __GNUC_MINOR__ <= 9 57 #define rcutils_atomic_load(object, out) (out) = atomic_load(object) 59 #define rcutils_atomic_compare_exchange_strong(object, out, expected, desired) \ 60 (out) = atomic_compare_exchange_strong(object, expected, desired) 62 #define rcutils_atomic_exchange(object, out, desired) (out) = atomic_exchange(object, desired) 64 #define rcutils_atomic_store(object, desired) atomic_store(object, desired) 66 #define rcutils_atomic_fetch_add(object, out, arg) (out) = atomic_fetch_add(object, arg) 68 #else // !defined(_WIN32) 72 #define rcutils_atomic_load(object, out) rcutils_win32_atomic_load(object, out) 74 #define rcutils_atomic_compare_exchange_strong(object, out, expected, desired) \ 75 rcutils_win32_atomic_compare_exchange_strong(object, out, expected, desired) 77 #define rcutils_atomic_exchange(object, out, desired) \ 78 rcutils_win32_atomic_exchange(object, out, desired) 80 #define rcutils_atomic_store(object, desired) rcutils_win32_atomic_store(object, desired) 82 #define rcutils_atomic_fetch_add(object, out, arg) rcutils_win32_atomic_fetch_add(object, out, arg) 84 #endif // !defined(_WIN32) 87 rcutils_atomic_load_bool(atomic_bool * a_bool)
95 rcutils_atomic_load_int64_t(atomic_int_least64_t * a_int64_t)
102 static inline uint64_t
103 rcutils_atomic_load_uint64_t(atomic_uint_least64_t * a_uint64_t)
110 static inline uintptr_t
111 rcutils_atomic_load_uintptr_t(atomic_uintptr_t * a_uintptr_t)
113 uintptr_t result = 0;
119 rcutils_atomic_compare_exchange_strong_uint_least64_t(
120 atomic_uint_least64_t * a_uint_least64_t, uint64_t * expected, uint64_t desired)
123 #if defined(__clang__) 124 # pragma clang diagnostic push 126 # pragma clang diagnostic ignored "-Wgnu-statement-expression" 129 #if defined(__clang__) 130 # pragma clang diagnostic pop 136 rcutils_atomic_exchange_bool(atomic_bool * a_bool,
bool desired)
143 static inline int64_t
144 rcutils_atomic_exchange_int64_t(atomic_int_least64_t * a_int64_t, int64_t desired)
151 static inline uint64_t
152 rcutils_atomic_exchange_uint64_t(atomic_uint_least64_t * a_uint64_t, uint64_t desired)
159 static inline uintptr_t
160 rcutils_atomic_exchange_uintptr_t(atomic_uintptr_t * a_uintptr_t, uintptr_t desired)
167 static inline uint64_t
168 rcutils_atomic_fetch_add_uint64_t(atomic_uint_least64_t * a_uint64_t, uint64_t arg)
176 # pragma GCC diagnostic pop 179 #endif // RCUTILS__STDATOMIC_HELPER_H_ #define rcutils_atomic_fetch_add(object, out, arg)
Definition: stdatomic_helper.h:66
#define rcutils_atomic_exchange(object, out, desired)
Definition: stdatomic_helper.h:62
#define rcutils_atomic_compare_exchange_strong(object, out, expected, desired)
Definition: stdatomic_helper.h:59
#define rcutils_atomic_load(object, out)
Definition: stdatomic_helper.h:57