19 #ifndef GRPC_CORE_LIB_GPRPP_REF_COUNTED_PTR_H
20 #define GRPC_CORE_LIB_GPRPP_REF_COUNTED_PTR_H
24 #include <type_traits>
48 value_ = other.value_;
49 other.value_ =
nullptr;
54 value_ =
static_cast<T*
>(other.value_);
55 other.value_ =
nullptr;
61 other.value_ =
nullptr;
67 other.value_ =
nullptr;
73 if (other.value_ !=
nullptr) other.value_->IncrementRefCount();
74 value_ = other.value_;
79 static_assert(std::has_virtual_destructor<T>::value,
80 "T does not have a virtual dtor");
81 if (other.value_ !=
nullptr) other.value_->IncrementRefCount();
82 value_ =
static_cast<T*
>(other.value_);
90 if (other.value_ !=
nullptr) other.value_->IncrementRefCount();
96 static_assert(std::has_virtual_destructor<T>::value,
97 "T does not have a virtual dtor");
100 if (other.value_ !=
nullptr) other.value_->IncrementRefCount();
106 if (value_ !=
nullptr) value_->Unref();
113 if (value_ !=
nullptr) value_->Unref();
117 T* value =
nullptr) {
118 if (value_ !=
nullptr) value_->Unref(location, reason);
121 template <
typename Y>
123 static_assert(std::has_virtual_destructor<T>::value,
124 "T does not have a virtual dtor");
125 if (value_ !=
nullptr) value_->Unref();
126 value_ =
static_cast<T*
>(value);
128 template <
typename Y>
130 Y* value =
nullptr) {
131 static_assert(std::has_virtual_destructor<T>::value,
132 "T does not have a virtual dtor");
133 if (value_ !=
nullptr) value_->Unref(location, reason);
134 value_ =
static_cast<T*
>(value);
147 T*
get()
const {
return value_; }
152 template <
typename Y>
154 return value_ == other.value_;
157 template <
typename Y>
159 return value_ == other;
162 bool operator==(std::nullptr_t)
const {
return value_ ==
nullptr; }
164 template <
typename Y>
166 return value_ != other.value_;
169 template <
typename Y>
171 return value_ != other;
174 bool operator!=(std::nullptr_t)
const {
return value_ !=
nullptr; }
177 template <
typename Y>
185 template <
typename T>
193 template <
typename Y>
201 value_ = other.value_;
202 other.value_ =
nullptr;
204 template <
typename Y>
207 value_ =
static_cast<T*
>(other.value_);
208 other.value_ =
nullptr;
214 other.value_ =
nullptr;
217 template <
typename Y>
220 other.value_ =
nullptr;
226 if (other.value_ !=
nullptr) other.value_->IncrementWeakRefCount();
227 value_ = other.value_;
229 template <
typename Y>
232 static_assert(std::has_virtual_destructor<T>::value,
233 "T does not have a virtual dtor");
234 if (other.value_ !=
nullptr) other.value_->IncrementWeakRefCount();
235 value_ =
static_cast<T*
>(other.value_);
243 if (other.value_ !=
nullptr) other.value_->IncrementWeakRefCount();
247 template <
typename Y>
249 static_assert(std::has_virtual_destructor<T>::value,
250 "T does not have a virtual dtor");
253 if (other.value_ !=
nullptr) other.value_->IncrementWeakRefCount();
259 if (value_ !=
nullptr) value_->WeakUnref();
266 if (value_ !=
nullptr) value_->WeakUnref();
270 T* value =
nullptr) {
271 if (value_ !=
nullptr) value_->WeakUnref(location, reason);
274 template <
typename Y>
276 static_assert(std::has_virtual_destructor<T>::value,
277 "T does not have a virtual dtor");
278 if (value_ !=
nullptr) value_->WeakUnref();
279 value_ =
static_cast<T*
>(value);
281 template <
typename Y>
283 Y* value =
nullptr) {
284 static_assert(std::has_virtual_destructor<T>::value,
285 "T does not have a virtual dtor");
286 if (value_ !=
nullptr) value_->WeakUnref(location, reason);
287 value_ =
static_cast<T*
>(value);
300 T*
get()
const {
return value_; }
305 template <
typename Y>
307 return value_ == other.value_;
310 template <
typename Y>
312 return value_ == other;
315 bool operator==(std::nullptr_t)
const {
return value_ ==
nullptr; }
317 template <
typename Y>
319 return value_ != other.value_;
322 template <
typename Y>
324 return value_ != other;
327 bool operator!=(std::nullptr_t)
const {
return value_ !=
nullptr; }
330 template <
typename Y>
336 template <
typename T,
typename... Args>
341 template <
typename T>
343 return p1.
get() < p2.
get();
346 template <
typename T>
348 return p1.
get() < p2.
get();
Definition: debug_location.h:31
Definition: ref_counted_ptr.h:35
bool operator!=(std::nullptr_t) const
Definition: ref_counted_ptr.h:174
RefCountedPtr & operator=(const RefCountedPtr &other)
Definition: ref_counted_ptr.h:87
RefCountedPtr & operator=(RefCountedPtr &&other) noexcept
Definition: ref_counted_ptr.h:59
bool operator==(const Y *other) const
Definition: ref_counted_ptr.h:158
RefCountedPtr(RefCountedPtr< Y > &&other) noexcept
Definition: ref_counted_ptr.h:53
bool operator==(const RefCountedPtr< Y > &other) const
Definition: ref_counted_ptr.h:153
bool operator!=(const RefCountedPtr< Y > &other) const
Definition: ref_counted_ptr.h:165
bool operator!=(const Y *other) const
Definition: ref_counted_ptr.h:170
void reset(Y *value=nullptr)
Definition: ref_counted_ptr.h:122
RefCountedPtr & operator=(RefCountedPtr< Y > &&other) noexcept
Definition: ref_counted_ptr.h:65
T * get() const
Definition: ref_counted_ptr.h:147
T * operator->() const
Definition: ref_counted_ptr.h:150
void reset(const DebugLocation &location, const char *reason, Y *value=nullptr)
Definition: ref_counted_ptr.h:129
RefCountedPtr & operator=(const RefCountedPtr< Y > &other)
Definition: ref_counted_ptr.h:95
T * release()
Definition: ref_counted_ptr.h:141
~RefCountedPtr()
Definition: ref_counted_ptr.h:105
RefCountedPtr(const RefCountedPtr< Y > &other)
Definition: ref_counted_ptr.h:78
bool operator==(std::nullptr_t) const
Definition: ref_counted_ptr.h:162
void swap(RefCountedPtr &other)
Definition: ref_counted_ptr.h:109
RefCountedPtr(std::nullptr_t)
Definition: ref_counted_ptr.h:39
RefCountedPtr(Y *value)
Definition: ref_counted_ptr.h:44
RefCountedPtr()
Definition: ref_counted_ptr.h:37
T & operator*() const
Definition: ref_counted_ptr.h:149
void reset(const DebugLocation &location, const char *reason, T *value=nullptr)
Definition: ref_counted_ptr.h:116
void reset(T *value=nullptr)
Definition: ref_counted_ptr.h:112
RefCountedPtr(const RefCountedPtr &other)
Definition: ref_counted_ptr.h:72
RefCountedPtr(RefCountedPtr &&other) noexcept
Definition: ref_counted_ptr.h:47
Definition: ref_counted_ptr.h:186
bool operator!=(std::nullptr_t) const
Definition: ref_counted_ptr.h:327
WeakRefCountedPtr(Y *value)
Definition: ref_counted_ptr.h:195
void swap(WeakRefCountedPtr &other)
Definition: ref_counted_ptr.h:262
T * operator->() const
Definition: ref_counted_ptr.h:303
WeakRefCountedPtr & operator=(WeakRefCountedPtr< Y > &&other) noexcept
Definition: ref_counted_ptr.h:218
T * release()
Definition: ref_counted_ptr.h:294
WeakRefCountedPtr(WeakRefCountedPtr &&other) noexcept
Definition: ref_counted_ptr.h:200
bool operator!=(const Y *other) const
Definition: ref_counted_ptr.h:323
bool operator==(std::nullptr_t) const
Definition: ref_counted_ptr.h:315
WeakRefCountedPtr & operator=(WeakRefCountedPtr &&other) noexcept
Definition: ref_counted_ptr.h:212
void reset(Y *value=nullptr)
Definition: ref_counted_ptr.h:275
bool operator!=(const WeakRefCountedPtr< Y > &other) const
Definition: ref_counted_ptr.h:318
WeakRefCountedPtr & operator=(const WeakRefCountedPtr< Y > &other)
Definition: ref_counted_ptr.h:248
void reset(const DebugLocation &location, const char *reason, T *value=nullptr)
Definition: ref_counted_ptr.h:269
T & operator*() const
Definition: ref_counted_ptr.h:302
WeakRefCountedPtr()
Definition: ref_counted_ptr.h:188
WeakRefCountedPtr & operator=(const WeakRefCountedPtr &other)
Definition: ref_counted_ptr.h:240
~WeakRefCountedPtr()
Definition: ref_counted_ptr.h:258
void reset(const DebugLocation &location, const char *reason, Y *value=nullptr)
Definition: ref_counted_ptr.h:282
bool operator==(const Y *other) const
Definition: ref_counted_ptr.h:311
WeakRefCountedPtr(const WeakRefCountedPtr &other)
Definition: ref_counted_ptr.h:225
T * get() const
Definition: ref_counted_ptr.h:300
WeakRefCountedPtr(std::nullptr_t)
Definition: ref_counted_ptr.h:190
void reset(T *value=nullptr)
Definition: ref_counted_ptr.h:265
WeakRefCountedPtr(const WeakRefCountedPtr< Y > &other)
Definition: ref_counted_ptr.h:231
WeakRefCountedPtr(WeakRefCountedPtr< Y > &&other) noexcept
Definition: ref_counted_ptr.h:206
bool operator==(const WeakRefCountedPtr< Y > &other) const
Definition: ref_counted_ptr.h:306
Round Robin Policy.
Definition: backend_metric.cc:26
RefCountedPtr< T > MakeRefCounted(Args &&... args)
Definition: ref_counted_ptr.h:337
bool operator<(const RefCountedPtr< T > &p1, const RefCountedPtr< T > &p2)
Definition: ref_counted_ptr.h:342