12 #ifndef ROC_CORE_ATOMIC_OPS_H_
13 #define ROC_CORE_ATOMIC_OPS_H_
27 __atomic_thread_fence(__ATOMIC_ACQUIRE);
32 __atomic_thread_fence(__ATOMIC_RELEASE);
37 __atomic_thread_fence(__ATOMIC_SEQ_CST);
47 return __atomic_load_n(&var, __ATOMIC_RELAXED);
52 return __atomic_load_n(&var, __ATOMIC_ACQUIRE);
57 return __atomic_load_n(&var, __ATOMIC_SEQ_CST);
66 template <
class T1,
class T2>
static inline void store_relaxed(T1& var, T2 val) {
67 __atomic_store_n(&var, val, __ATOMIC_RELAXED);
71 template <
class T1,
class T2>
static inline void store_release(T1& var, T2 val) {
72 __atomic_store_n(&var, val, __ATOMIC_RELEASE);
76 template <
class T1,
class T2>
static inline void store_seq_cst(T1& var, T2 val) {
77 __atomic_store_n(&var, val, __ATOMIC_SEQ_CST);
87 return __atomic_exchange_n(&var, val, __ATOMIC_RELAXED);
92 return __atomic_exchange_n(&var, val, __ATOMIC_ACQUIRE);
97 return __atomic_exchange_n(&var, val, __ATOMIC_RELEASE);
102 return __atomic_exchange_n(&var, val, __ATOMIC_ACQ_REL);
107 return __atomic_exchange_n(&var, val, __ATOMIC_SEQ_CST);
116 template <
class T1,
class T2>
118 return __atomic_compare_exchange_n(&var, &exp, des, 0, __ATOMIC_RELAXED,
123 template <
class T1,
class T2>
125 return __atomic_compare_exchange_n(&var, &exp, des, 0, __ATOMIC_ACQUIRE,
130 template <
class T1,
class T2>
132 return __atomic_compare_exchange_n(&var, &exp, des, 0, __ATOMIC_RELEASE,
137 template <
class T1,
class T2>
139 return __atomic_compare_exchange_n(&var, &exp, des, 0, __ATOMIC_ACQ_REL,
144 template <
class T1,
class T2>
146 return __atomic_compare_exchange_n(&var, &exp, des, 0, __ATOMIC_SEQ_CST,
157 return __atomic_fetch_add(&var, val, __ATOMIC_RELAXED);
162 return __atomic_fetch_add(&var, val, __ATOMIC_ACQUIRE);
167 return __atomic_fetch_add(&var, val, __ATOMIC_RELEASE);
172 return __atomic_fetch_add(&var, val, __ATOMIC_SEQ_CST);
182 return __atomic_fetch_sub(&var, val, __ATOMIC_RELAXED);
187 return __atomic_fetch_sub(&var, val, __ATOMIC_ACQUIRE);
192 return __atomic_fetch_sub(&var, val, __ATOMIC_RELEASE);
197 return __atomic_fetch_sub(&var, val, __ATOMIC_SEQ_CST);
207 return __atomic_fetch_and(&var, val, __ATOMIC_RELAXED);
212 return __atomic_fetch_and(&var, val, __ATOMIC_ACQUIRE);
217 return __atomic_fetch_and(&var, val, __ATOMIC_RELEASE);
222 return __atomic_fetch_and(&var, val, __ATOMIC_SEQ_CST);
232 return __atomic_fetch_or(&var, val, __ATOMIC_RELAXED);
237 return __atomic_fetch_or(&var, val, __ATOMIC_ACQUIRE);
242 return __atomic_fetch_or(&var, val, __ATOMIC_RELEASE);
247 return __atomic_fetch_or(&var, val, __ATOMIC_SEQ_CST);
257 return __atomic_fetch_xor(&var, val, __ATOMIC_RELAXED);
262 return __atomic_fetch_xor(&var, val, __ATOMIC_ACQUIRE);
267 return __atomic_fetch_xor(&var, val, __ATOMIC_RELEASE);
272 return __atomic_fetch_xor(&var, val, __ATOMIC_SEQ_CST);
Atomic operations. This wrapper exists because on non-C11 compilers we use another implementation.
static T1 fetch_and_release(T1 &var, T2 val)
Atomic fetch-and (release barrier).
static T1 fetch_or_acquire(T1 &var, T2 val)
Atomic fetch-or (acquire barrier).
static T1 exchange_release(T1 &var, T2 val)
Atomic exchange (release barrier).
static void store_relaxed(T1 &var, T2 val)
Atomic store (no barrier).
static T1 fetch_add_release(T1 &var, T2 val)
Atomic add-and-fetch (release barrier).
static void fence_seq_cst()
Full memory barrier.
static T1 fetch_or_release(T1 &var, T2 val)
Atomic fetch-or (release barrier).
static void fence_acquire()
Acquire memory barrier.
static T1 exchange_seq_cst(T1 &var, T2 val)
Atomic exchange (full barrier).
static T1 fetch_or_relaxed(T1 &var, T2 val)
Atomic fetch-or (no barrier).
static T1 exchange_relaxed(T1 &var, T2 val)
Atomic exchange (no barrier).
static T1 exchange_acquire(T1 &var, T2 val)
Atomic exchange (acquire barrier).
static T1 fetch_sub_seq_cst(T1 &var, T2 val)
Atomic sub-and-fetch (full barrier).
static bool compare_exchange_acq_rel(T1 &var, T1 &exp, T2 des)
Atomic compare-and-swap (acquire-release barrier).
static void store_seq_cst(T1 &var, T2 val)
Atomic store (full barrier).
static T load_relaxed(const T &var)
Atomic load (no barrier).
static T1 fetch_or_seq_cst(T1 &var, T2 val)
Atomic fetch-or (full barrier).
static bool compare_exchange_seq_cst(T1 &var, T1 &exp, T2 des)
Atomic compare-and-swap (full barrier).
static T load_acquire(const T &var)
Atomic load (acquire barrier).
static bool compare_exchange_acquire(T1 &var, T1 &exp, T2 des)
Atomic compare-and-swap (acquire barrier).
static void store_release(T1 &var, T2 val)
Atomic store (release barrier).
static void fence_release()
Release memory barrier.
static T1 fetch_xor_relaxed(T1 &var, T2 val)
Atomic fetch-xor (no barrier).
static T1 fetch_and_seq_cst(T1 &var, T2 val)
Atomic fetch-and (full barrier).
static T1 fetch_add_seq_cst(T1 &var, T2 val)
Atomic add-and-fetch (full barrier).
static T1 exchange_acq_rel(T1 &var, T2 val)
Atomic exchange (acquire-release barrier).
static T1 fetch_and_acquire(T1 &var, T2 val)
Atomic fetch-and (acquire barrier).
static T1 fetch_xor_acquire(T1 &var, T2 val)
Atomic fetch-xor (acquire barrier).
static T1 fetch_add_acquire(T1 &var, T2 val)
Atomic add-and-fetch (acquire barrier).
static bool compare_exchange_relaxed(T1 &var, T1 &exp, T2 des)
Atomic compare-and-swap (no barrier).
static T1 fetch_sub_release(T1 &var, T2 val)
Atomic sub-and-fetch (release barrier).
static T1 fetch_sub_relaxed(T1 &var, T2 val)
Atomic fetch-sub (no barrier).
static T1 fetch_and_relaxed(T1 &var, T2 val)
Atomic fetch-and (no barrier).
static T1 fetch_sub_acquire(T1 &var, T2 val)
Atomic sub-and-fetch (acquire barrier).
static T1 fetch_xor_release(T1 &var, T2 val)
Atomic fetch-xor (release barrier).
static T1 fetch_xor_seq_cst(T1 &var, T2 val)
Atomic fetch-xor (full barrier).
static bool compare_exchange_release(T1 &var, T1 &exp, T2 des)
Atomic compare-and-swap (release barrier).
static T load_seq_cst(const T &var)
Atomic load (full barrier).
static T1 fetch_add_relaxed(T1 &var, T2 val)
Atomic fetch-add (no barrier).