19 #ifndef GRPC_CORE_LIB_GPRPP_REF_COUNTED_H
20 #define GRPC_CORE_LIB_GPRPP_REF_COUNTED_H
71 template <
typename TraceFlagT = TraceFlag>
82 trace_flag_(trace_flag),
91 if (trace_flag_ !=
nullptr && trace_flag_->
enabled()) {
93 trace_flag_->
name(),
this, prior, prior + n);
102 if (trace_flag_ !=
nullptr && trace_flag_->
enabled()) {
104 trace_flag_->
name(),
this, location.
file(), location.
line(),
105 prior, prior + n, reason);
120 if (trace_flag_ !=
nullptr && trace_flag_->
enabled()) {
122 trace_flag_->
name(),
this, prior, prior + 1);
132 if (trace_flag_ !=
nullptr && trace_flag_->
enabled()) {
134 trace_flag_->
name(),
this, location.
file(), location.
line(),
135 prior, prior + 1, reason);
148 if (trace_flag_ !=
nullptr && trace_flag_->
enabled()) {
149 const Value prior = get();
151 trace_flag_->
name(),
this, prior, prior + 1);
158 if (trace_flag_ !=
nullptr && trace_flag_->
enabled()) {
159 const Value prior = get();
161 "%s:%p %s:%d ref_if_non_zero "
162 "%" PRIdPTR
" -> %" PRIdPTR
" %s",
163 trace_flag_->
name(),
this, location.
file(), location.
line(),
164 prior, prior + 1, reason);
178 auto* trace_flag = trace_flag_;
182 if (trace_flag !=
nullptr && trace_flag->enabled()) {
184 trace_flag->name(),
this, prior, prior - 1);
194 auto* trace_flag = trace_flag_;
198 if (trace_flag !=
nullptr && trace_flag->enabled()) {
200 trace_flag->name(),
this, location.
file(), location.
line(), prior,
216 TraceFlag* trace_flag_;
218 Atomic<Value> value_;
247 template <
typename Child,
typename Impl = PolymorphicRefCount>
260 IncrementRefCount(location, reason);
270 delete static_cast<Child*
>(
this);
275 delete static_cast<Child*
>(
this);
292 template <
typename TraceFlagT = TraceFlag>
294 intptr_t initial_refcount = 1)
295 : refs_(initial_refcount, trace_flag) {}
299 template <
typename T>
302 void IncrementRefCount() { refs_.
Ref(); }
303 void IncrementRefCount(
const DebugLocation& location,
const char* reason) {
304 refs_.
Ref(location, reason);
bool IncrementIfNonzero(MemoryOrder load_order=MemoryOrder::ACQUIRE)
Definition: atomic.h:84
T FetchSub(Arg arg, MemoryOrder order=MemoryOrder::SEQ_CST)
Definition: atomic.h:77
T Load(MemoryOrder order) const
Definition: atomic.h:44
T FetchAdd(Arg arg, MemoryOrder order=MemoryOrder::SEQ_CST)
Definition: atomic.h:71
Definition: debug_location.h:31
int line() const
Definition: debug_location.h:35
const char * file() const
Definition: debug_location.h:34
Definition: ref_counted.h:49
~NonPolymorphicRefCount()=default
Definition: ref_counted.h:41
virtual ~PolymorphicRefCount()=default
Definition: ref_counted.h:62
void Ref(Value n=1)
Definition: ref_counted.h:88
void RefNonZero()
Definition: ref_counted.h:117
intptr_t Value
Definition: ref_counted.h:64
bool RefIfNonZero(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:156
bool Unref(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:190
constexpr RefCount(Value init=1, TraceFlagT *trace_flag=nullptr)
Definition: ref_counted.h:72
void Ref(const DebugLocation &location, const char *reason, Value n=1)
Definition: ref_counted.h:99
bool Unref()
Definition: ref_counted.h:174
bool RefIfNonZero()
Definition: ref_counted.h:146
void RefNonZero(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:129
Definition: ref_counted.h:248
void Unref()
Definition: ref_counted.h:268
RefCounted & operator=(const RefCounted &)=delete
RefCountedPtr< Child > Ref(const DebugLocation &location, const char *reason) GRPC_MUST_USE_RESULT
Definition: ref_counted.h:258
bool RefIfNonZero(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:280
RefCounted(TraceFlagT *trace_flag=nullptr, intptr_t initial_refcount=1)
Definition: ref_counted.h:293
RefCounted(const RefCounted &)=delete
bool RefIfNonZero()
Definition: ref_counted.h:279
void Unref(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:273
RefCountedPtr< Child > Ref() GRPC_MUST_USE_RESULT
Definition: ref_counted.h:253
Definition: ref_counted_ptr.h:35
bool enabled()
Definition: trace.h:80
const char * name() const
Definition: trace.h:68
#define GPR_DEBUG_ASSERT(x)
Definition: log.h:103
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
Log a message.
#define GPR_INFO
Definition: log.h:56
Internal thread interface.
Definition: backoff.h:26