aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-04-12 08:29:55 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-04-12 08:29:55 -0700
commit284195faab8a8b6c5232f722f298f3a51973d64d (patch)
treed5e5147fb8a24cc594d7fe0679c57492844ab0fb /src/core/lib/support
parent90ce723aca9d1527d410bd36f14b40424b0c6534 (diff)
Write out atomic<bool> explicitly
Diffstat (limited to 'src/core/lib/support')
-rw-r--r--src/core/lib/support/atomic_with_atm.h16
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;