17 #ifndef GRPC_CORE_LIB_GPRPP_DUAL_REF_COUNTED_H
18 #define GRPC_CORE_LIB_GPRPP_DUAL_REF_COUNTED_H
47 template <
typename Child>
72 strong_refs, strong_refs - 1, weak_refs, weak_refs + 1);
91 strong_refs - 1, weak_refs, weak_refs + 1, reason);
107 uint64_t prev_ref_pair =
refs_.load(std::memory_order_acquire);
114 trace_,
this, strong_refs, strong_refs + 1, weak_refs);
117 if (strong_refs == 0)
return nullptr;
118 }
while (!
refs_.compare_exchange_weak(
120 std::memory_order_acq_rel, std::memory_order_acquire));
126 uint64_t prev_ref_pair =
refs_.load(std::memory_order_acquire);
133 "%s:%p %s:%d ref_if_non_zero %d -> %d (weak_refs=%d) %s",
134 trace_,
this, location.file(), location.line(), strong_refs,
135 strong_refs + 1, weak_refs, reason);
142 if (strong_refs == 0)
return nullptr;
143 }
while (!
refs_.compare_exchange_weak(
145 std::memory_order_acq_rel, std::memory_order_acquire));
165 const char* trace =
trace_;
172 if (trace !=
nullptr) {
174 weak_refs, weak_refs - 1, strong_refs);
179 delete static_cast<Child*
>(
this);
187 const char* trace =
trace_;
194 if (trace !=
nullptr) {
195 gpr_log(
GPR_INFO,
"%s:%p %s:%d weak_unref %d -> %d (refs=%d) %s", trace,
196 this, location.
file(), location.
line(), weak_refs, weak_refs - 1,
197 strong_refs, reason);
206 delete static_cast<Child*
>(
this);
233 template <
typename T>
236 template <
typename T>
241 return (
static_cast<uint64_t>(strong) << 32) +
static_cast<int64_t>(weak);
244 return static_cast<uint32_t>(ref_pair >> 32);
247 return static_cast<uint32_t>(ref_pair & 0xffffffff
u);
259 strong_refs, strong_refs + 1, weak_refs);
274 this, location.
file(), location.
line(), strong_refs,
275 strong_refs + 1, weak_refs, reason);
293 weak_refs, weak_refs + 1, strong_refs);
300 const char* reason) {
308 this, location.
file(), location.
line(), weak_refs, weak_refs + 1,
309 strong_refs, reason);