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 enabled()
Definition: trace.h:80
#define GPR_INFO
Definition: log.h:56
const char * name() const
Definition: trace.h:68
const char * file() const
Definition: debug_location.h:34
intptr_t Value
Definition: ref_counted.h:64
void RefNonZero()
Definition: ref_counted.h:117
RefCountedPtr< Child > Ref() GRPC_MUST_USE_RESULT
Definition: ref_counted.h:253
Definition: debug_location.h:31
bool RefIfNonZero()
Definition: ref_counted.h:146
void Ref(Value n=1)
Definition: ref_counted.h:88
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
Log a message.
T FetchAdd(Arg arg, MemoryOrder order=MemoryOrder::SEQ_CST)
Definition: atomic.h:71
bool RefIfNonZero(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:280
Definition: ref_counted.h:62
bool RefIfNonZero(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:156
Definition: ref_counted.h:41
Internal thread interface.
Definition: backoff.h:26
void Unref(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:273
constexpr RefCount(Value init=1, TraceFlagT *trace_flag=nullptr)
Definition: ref_counted.h:72
~NonPolymorphicRefCount()=default
Definition: ref_counted_ptr.h:35
void Ref(const DebugLocation &location, const char *reason, Value n=1)
Definition: ref_counted.h:99
int line() const
Definition: debug_location.h:35
bool IncrementIfNonzero(MemoryOrder load_order=MemoryOrder::ACQUIRE)
Definition: atomic.h:84
T Load(MemoryOrder order) const
Definition: atomic.h:44
void Unref()
Definition: ref_counted.h:268
bool Unref()
Definition: ref_counted.h:174
bool Unref(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:190
Definition: ref_counted.h:248
T FetchSub(Arg arg, MemoryOrder order=MemoryOrder::SEQ_CST)
Definition: atomic.h:77
RefCounted(const RefCounted &)=delete
RefCounted & operator=(const RefCounted &)=delete
#define GPR_DEBUG_ASSERT(x)
Definition: log.h:103
RefCounted(TraceFlagT *trace_flag=nullptr, intptr_t initial_refcount=1)
Definition: ref_counted.h:293
void RefNonZero(const DebugLocation &location, const char *reason)
Definition: ref_counted.h:129
bool RefIfNonZero()
Definition: ref_counted.h:279
RefCountedPtr< Child > Ref(const DebugLocation &location, const char *reason) GRPC_MUST_USE_RESULT
Definition: ref_counted.h:258
Definition: ref_counted.h:49
virtual ~PolymorphicRefCount()=default