15 #ifndef RCUTILS__STDATOMIC_HELPER_H_ 16 #define RCUTILS__STDATOMIC_HELPER_H_ 24 # pragma GCC diagnostic push 25 # if defined(__clang__) 26 # pragma clang diagnostic ignored "-Wunused-function" 34 #if defined(__has_feature) 35 #define my__has_feature(...) __has_feature(__VAR_ARGS__) 37 #define my__has_feature(...) 0 40 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ <= 4 && __GNUC_MINOR__ <= 9 43 #else // !defined(__clang__) && defined(__GNUC__) && __GNUC__ <= 4 && __GNUC_MINOR__ <= 9 46 # error "cannot be used with C++ due to a conflict with the C++ <atomic> header, see: p0943r1" 49 # if defined(__has_feature) && !my__has_feature(c_atomic) 53 # include <stdatomic.h> 56 #endif // !defined(__clang__) && defined(__GNUC__) && __GNUC__ <= 4 && __GNUC_MINOR__ <= 9 58 #define rcutils_atomic_load(object, out) (out) = atomic_load(object) 60 #define rcutils_atomic_compare_exchange_strong(object, out, expected, desired) \ 61 (out) = atomic_compare_exchange_strong(object, expected, desired) 63 #define rcutils_atomic_exchange(object, out, desired) (out) = atomic_exchange(object, desired) 65 #define rcutils_atomic_store(object, desired) atomic_store(object, desired) 67 #define rcutils_atomic_fetch_add(object, out, arg) (out) = atomic_fetch_add(object, arg) 69 #else // !defined(_WIN32) 73 #define rcutils_atomic_load(object, out) rcutils_win32_atomic_load(object, out) 75 #define rcutils_atomic_compare_exchange_strong(object, out, expected, desired) \ 76 rcutils_win32_atomic_compare_exchange_strong(object, out, expected, desired) 78 #define rcutils_atomic_exchange(object, out, desired) \ 79 rcutils_win32_atomic_exchange(object, out, desired) 81 #define rcutils_atomic_store(object, desired) rcutils_win32_atomic_store(object, desired) 83 #define rcutils_atomic_fetch_add(object, out, arg) rcutils_win32_atomic_fetch_add(object, out, arg) 85 #endif // !defined(_WIN32) 88 rcutils_atomic_load_bool(atomic_bool * a_bool)
96 rcutils_atomic_load_int64_t(atomic_int_least64_t * a_int64_t)
103 static inline uint64_t
104 rcutils_atomic_load_uint64_t(atomic_uint_least64_t * a_uint64_t)
111 static inline uintptr_t
112 rcutils_atomic_load_uintptr_t(atomic_uintptr_t * a_uintptr_t)
114 uintptr_t result = 0;
120 rcutils_atomic_compare_exchange_strong_uint_least64_t(
121 atomic_uint_least64_t * a_uint_least64_t, uint64_t * expected, uint64_t desired)
124 #if defined(__clang__) 125 # pragma clang diagnostic push 127 # pragma clang diagnostic ignored "-Wgnu-statement-expression" 130 #if defined(__clang__) 131 # pragma clang diagnostic pop 137 rcutils_atomic_exchange_bool(atomic_bool * a_bool,
bool desired)
144 static inline int64_t
145 rcutils_atomic_exchange_int64_t(atomic_int_least64_t * a_int64_t, int64_t desired)
152 static inline uint64_t
153 rcutils_atomic_exchange_uint64_t(atomic_uint_least64_t * a_uint64_t, uint64_t desired)
160 static inline uintptr_t
161 rcutils_atomic_exchange_uintptr_t(atomic_uintptr_t * a_uintptr_t, uintptr_t desired)
168 static inline uint64_t
169 rcutils_atomic_fetch_add_uint64_t(atomic_uint_least64_t * a_uint64_t, uint64_t arg)
177 # pragma GCC diagnostic pop 180 #endif // RCUTILS__STDATOMIC_HELPER_H_ #define rcutils_atomic_fetch_add(object, out, arg)
Definition: stdatomic_helper.h:67
#define rcutils_atomic_exchange(object, out, desired)
Definition: stdatomic_helper.h:63
#define rcutils_atomic_compare_exchange_strong(object, out, expected, desired)
Definition: stdatomic_helper.h:60
#define rcutils_atomic_load(object, out)
Definition: stdatomic_helper.h:58