aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Soheil Hassas Yeganeh <soheil@google.com>2018-11-28 16:58:36 -0500
committerGravatar GitHub <noreply@github.com>2018-11-28 16:58:36 -0500
commite2cde10d5ada2d318b0f0cbeb01f8093579b1179 (patch)
treefc4b28c78d884d64efc1e8535db0cee4f1989854
parenta92f2acf7522809fe9bdcec4d470461c45d75fce (diff)
parent9128881b6d97059170270936a13ee7c90f35b30a (diff)
Merge pull request #17320 from soheilhy/worktree-refcounted-bench
Add GPR_ATM_INC_ADD_THEN to grpc_core::RefCount
-rw-r--r--include/grpc/impl/codegen/atm_gcc_sync.h2
-rw-r--r--include/grpc/impl/codegen/atm_windows.h2
-rw-r--r--src/core/lib/gprpp/ref_counted.h11
3 files changed, 12 insertions, 3 deletions
diff --git a/include/grpc/impl/codegen/atm_gcc_sync.h b/include/grpc/impl/codegen/atm_gcc_sync.h
index c0010a3469..728c3d5412 100644
--- a/include/grpc/impl/codegen/atm_gcc_sync.h
+++ b/include/grpc/impl/codegen/atm_gcc_sync.h
@@ -26,6 +26,8 @@
typedef intptr_t gpr_atm;
#define GPR_ATM_MAX INTPTR_MAX
#define GPR_ATM_MIN INTPTR_MIN
+#define GPR_ATM_INC_CAS_THEN(blah) blah
+#define GPR_ATM_INC_ADD_THEN(blah) blah
#define GPR_ATM_COMPILE_BARRIER_() __asm__ __volatile__("" : : : "memory")
diff --git a/include/grpc/impl/codegen/atm_windows.h b/include/grpc/impl/codegen/atm_windows.h
index f6b27e5df7..c016b90095 100644
--- a/include/grpc/impl/codegen/atm_windows.h
+++ b/include/grpc/impl/codegen/atm_windows.h
@@ -25,6 +25,8 @@
typedef intptr_t gpr_atm;
#define GPR_ATM_MAX INTPTR_MAX
#define GPR_ATM_MIN INTPTR_MIN
+#define GPR_ATM_INC_CAS_THEN(blah) blah
+#define GPR_ATM_INC_ADD_THEN(blah) blah
#define gpr_atm_full_barrier MemoryBarrier
diff --git a/src/core/lib/gprpp/ref_counted.h b/src/core/lib/gprpp/ref_counted.h
index e366445bff..98de1a3653 100644
--- a/src/core/lib/gprpp/ref_counted.h
+++ b/src/core/lib/gprpp/ref_counted.h
@@ -21,6 +21,7 @@
#include <grpc/support/port_platform.h>
+#include <grpc/support/atm.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
@@ -76,12 +77,15 @@ class RefCount {
constexpr explicit RefCount(Value init = 1) : value_(init) {}
// Increases the ref-count by `n`.
- void Ref(Value n = 1) { value_.fetch_add(n, std::memory_order_relaxed); }
+ void Ref(Value n = 1) {
+ GPR_ATM_INC_ADD_THEN(value_.fetch_add(n, std::memory_order_relaxed));
+ }
// Similar to Ref() with an assert on the ref-count being non-zero.
void RefNonZero() {
#ifndef NDEBUG
- const Value prior = value_.fetch_add(1, std::memory_order_relaxed);
+ const Value prior =
+ GPR_ATM_INC_ADD_THEN(value_.fetch_add(1, std::memory_order_relaxed));
assert(prior > 0);
#else
Ref();
@@ -90,7 +94,8 @@ class RefCount {
// Decrements the ref-count and returns true if the ref-count reaches 0.
bool Unref() {
- const Value prior = value_.fetch_sub(1, std::memory_order_acq_rel);
+ const Value prior =
+ GPR_ATM_INC_ADD_THEN(value_.fetch_sub(1, std::memory_order_acq_rel));
GPR_DEBUG_ASSERT(prior > 0);
return prior == 1;
}