diff --git a/include/grpc/support/sync.h b/include/grpc/support/sync.h index a7bbb38c27e..5cfeecb6017 100644 --- a/include/grpc/support/sync.h +++ b/include/grpc/support/sync.h @@ -164,6 +164,10 @@ GPRAPI void gpr_refn(gpr_refcount *r, int n); zero. . Requires *r initialized. */ GPRAPI int gpr_unref(gpr_refcount *r); +/* Return non-zero iff the reference count of *r is one, and thus is owned + by exactly one object. */ +GPRAPI int gpr_ref_is_unique(gpr_refcount *r); + /* --- Stats counters --- These calls act on the integral type gpr_stats_counter. It requires no diff --git a/src/core/lib/support/sync.c b/src/core/lib/support/sync.c index 44b83f8175a..9b5a4ac7087 100644 --- a/src/core/lib/support/sync.c +++ b/src/core/lib/support/sync.c @@ -113,6 +113,10 @@ int gpr_unref(gpr_refcount *r) { return prior == 1; } +int gpr_ref_is_unique(gpr_refcount *r) { + return gpr_atm_acq_load(&r->count) == 1; +} + void gpr_stats_init(gpr_stats_counter *c, intptr_t n) { gpr_atm_rel_store(&c->value, n); }