From b5df72c050189f28103eb8aeaa1e23d399eeb413 Mon Sep 17 00:00:00 2001 From: nnoble <nnoble@google.com> Date: Mon, 8 Dec 2014 19:29:55 -0800 Subject: [PATCH] Restoring atm_sync as it was lost during The Great Migration. Change on 2014/12/08 by nnoble <nnoble@google.com> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=81636458 --- include/grpc/support/atm_gcc_sync.h | 46 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/include/grpc/support/atm_gcc_sync.h b/include/grpc/support/atm_gcc_sync.h index 30570da540..976f2977bb 100644 --- a/include/grpc/support/atm_gcc_sync.h +++ b/include/grpc/support/atm_gcc_sync.h @@ -34,36 +34,40 @@ #ifndef __GRPC_SUPPORT_ATM_GCC_SYNC_H__ #define __GRPC_SUPPORT_ATM_GCC_SYNC_H__ -/* atm_platform.h for gcc and gcc-like compilers with the - __atomic_* interface. */ +/* variant of atm_platform.h for gcc and gcc-like compiers with __sync_* + interface */ #include <grpc/support/port_platform.h> typedef gpr_intptr gpr_atm; -#define gpr_atm_full_barrier() (__atomic_thread_fence(__ATOMIC_SEQ_CST)) +#if defined(__i386) || defined(__x86_64__) +/* All loads are acquire loads and all stores are release stores. */ +#define GPR_ATM_LS_BARRIER_() __asm__ __volatile__("" : : : "memory") +#else +#define GPR_ATM_LS_BARRIER_() gpr_atm_full_barrier() +#endif -#define gpr_atm_acq_load(p) (__atomic_load_n((p), __ATOMIC_ACQUIRE)) -#define gpr_atm_rel_store(p, value) \ - (__atomic_store_n((p), (gpr_intptr)(value), __ATOMIC_RELEASE)) +#define gpr_atm_full_barrier() (__sync_synchronize()) -#define gpr_atm_no_barrier_fetch_add(p, delta) \ - (__atomic_fetch_add((p), (gpr_intptr)(delta), __ATOMIC_RELAXED)) -#define gpr_atm_full_fetch_add(p, delta) \ - (__atomic_fetch_add((p), (gpr_intptr)(delta), __ATOMIC_ACQ_REL)) - -static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n) { - return __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_RELAXED, - __ATOMIC_RELAXED); +static __inline gpr_atm gpr_atm_acq_load(const gpr_atm *p) { + gpr_atm value = *p; + GPR_ATM_LS_BARRIER_(); + return value; } -static __inline int gpr_atm_acq_cas(gpr_atm *p, gpr_atm o, gpr_atm n) { - return __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_ACQUIRE, - __ATOMIC_RELAXED); +static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) { + GPR_ATM_LS_BARRIER_(); + *p = value; } -static __inline int gpr_atm_rel_cas(gpr_atm *p, gpr_atm o, gpr_atm n) { - return __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_RELEASE, - __ATOMIC_RELAXED); -} +#undef GPR_ATM_LS_BARRIER_ + +#define gpr_atm_no_barrier_fetch_add(p, delta) \ + gpr_atm_full_fetch_add((p), (delta)) +#define gpr_atm_full_fetch_add(p, delta) (__sync_fetch_and_add((p), (delta))) + +#define gpr_atm_no_barrier_cas(p, o, n) gpr_atm_acq_cas((p), (o), (n)) +#define gpr_atm_acq_cas(p, o, n) (__sync_bool_compare_and_swap((p), (o), (n))) +#define gpr_atm_rel_cas(p, o, n) gpr_atm_acq_cas((p), (o), (n)) #endif /* __GRPC_SUPPORT_ATM_GCC_SYNC_H__ */ -- GitLab