diff options
Diffstat (limited to 'src/core/lib/support')
-rw-r--r-- | src/core/lib/support/atomic_with_atm.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/core/lib/support/atomic_with_atm.h b/src/core/lib/support/atomic_with_atm.h index e7fea01878..55727f1dee 100644 --- a/src/core/lib/support/atomic_with_atm.h +++ b/src/core/lib/support/atomic_with_atm.h @@ -41,17 +41,21 @@ namespace grpc_core { enum MemoryOrderRelaxed { memory_order_relaxed }; template <class T> -class atomic { +class atomic; + +template <> +class atomic<bool> { public: - static_assert(sizeof(T) <= sizeof(gpr_atm), - "Atomics of size > sizeof(gpr_atm) are not supported"); - atomic() { gpr_atm_no_barrier_store(&x_, static_cast<gpr_atm>(T())); } + atomic() { gpr_atm_no_barrier_store(&x_, static_cast<gpr_atm>(false)); } + explicit atomic(bool x) { + gpr_atm_no_barrier_store(&x_, static_cast<gpr_atm>(x)); + } - bool compare_exchange_strong(T& expected, T update, MemoryOrderRelaxed, + bool compare_exchange_strong(bool& expected, bool update, MemoryOrderRelaxed, MemoryOrderRelaxed) { if (!gpr_atm_no_barrier_cas(&x_, static_cast<gpr_atm>(expected), static_cast<gpr_atm>(update))) { - expected = static_cast<T>(gpr_atm_no_barrier_load(&x_)); + expected = gpr_atm_no_barrier_load(&x_) != 0; return false; } return true; |