19 #ifndef GRPC_IMPL_CODEGEN_ATM_GCC_ATOMIC_H
20 #define GRPC_IMPL_CODEGEN_ATM_GCC_ATOMIC_H
31 #define GPR_ATM_MAX INTPTR_MAX
32 #define GPR_ATM_MIN INTPTR_MIN
34 #ifdef GPR_LOW_LEVEL_COUNTERS
35 extern gpr_atm gpr_counter_atm_cas;
36 extern gpr_atm gpr_counter_atm_add;
37 #define GPR_ATM_INC_COUNTER(counter) \
38 __atomic_fetch_add(&counter, 1, __ATOMIC_RELAXED)
39 #define GPR_ATM_INC_CAS_THEN(blah) \
40 (GPR_ATM_INC_COUNTER(gpr_counter_atm_cas), blah)
41 #define GPR_ATM_INC_ADD_THEN(blah) \
42 (GPR_ATM_INC_COUNTER(gpr_counter_atm_add), blah)
44 #define GPR_ATM_INC_CAS_THEN(blah) blah
45 #define GPR_ATM_INC_ADD_THEN(blah) blah
48 #define gpr_atm_full_barrier() (__atomic_thread_fence(__ATOMIC_SEQ_CST))
50 #define gpr_atm_acq_load(p) (__atomic_load_n((p), __ATOMIC_ACQUIRE))
51 #define gpr_atm_no_barrier_load(p) (__atomic_load_n((p), __ATOMIC_RELAXED))
52 #define gpr_atm_rel_store(p, value) \
53 (__atomic_store_n((p), (intptr_t)(value), __ATOMIC_RELEASE))
54 #define gpr_atm_no_barrier_store(p, value) \
55 (__atomic_store_n((p), (intptr_t)(value), __ATOMIC_RELAXED))
57 #define gpr_atm_no_barrier_fetch_add(p, delta) \
58 GPR_ATM_INC_ADD_THEN( \
59 __atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_RELAXED))
60 #define gpr_atm_full_fetch_add(p, delta) \
61 GPR_ATM_INC_ADD_THEN( \
62 __atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_ACQ_REL))
66 p, &o, n, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED));
71 p, &o, n, 0, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED));
76 p, &o, n, 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED));
81 p, &o, n, 0, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED));
84 #define gpr_atm_full_xchg(p, n) \
85 GPR_ATM_INC_CAS_THEN(__atomic_exchange_n((p), (n), __ATOMIC_ACQ_REL))