6 #ifndef XGBOOST_INTRUSIVE_PTR_H_
7 #define XGBOOST_INTRUSIVE_PTR_H_
22 std::atomic<int32_t> count_ {0};
25 std::int32_t IncRef() noexcept {
26 return count_.fetch_add(1, std::memory_order_relaxed);
28 std::int32_t DecRef() noexcept {
29 return count_.fetch_sub(1, std::memory_order_release);
31 bool IsZero()
const {
return Count() == 0; }
35 int32_t
Count()
const {
return count_.load(std::memory_order_relaxed); }
83 std::atomic_thread_fence(std::memory_order_acquire);
96 return std::hash<element_type *>()(ptr.get());
135 explicit operator bool() const noexcept {
return static_cast<bool>(
ptr_); }
149 template <
class T,
class U>
151 return x.get() == y.get();
154 template <
class T,
class U>
156 return x.get() != y.get();
159 template <
class T,
class U>
164 template <
class T,
class U>
169 template <
class T,
class U>
174 template <
class T,
class U>
181 return std::less<T*>{}(x.get(), y.get());
186 return std::less_equal<T*>{}(x.get(), y.get());
199 template <
class E,
class T,
class Y>
200 std::basic_ostream<E, T> &
operator<<(std::basic_ostream<E, T> &os,
201 IntrusivePtr<Y>
const &p) {
214 template <
typename T>
Helper class for embedding reference counting into client objects. See https://www....
Definition: intrusive_ptr.h:20
int32_t Count() const
Definition: intrusive_ptr.h:35
IntrusivePtrCell() noexcept=default
Implementation of Intrusive Pointer. A smart pointer that points to an object with an embedded refere...
Definition: intrusive_ptr.h:73
IntrusivePtr< T > & operator=(IntrusivePtr< T > &&that) noexcept
Definition: intrusive_ptr.h:120
element_type & operator*() const noexcept
Definition: intrusive_ptr.h:131
void reset(element_type *that)
Definition: intrusive_ptr.h:129
IntrusivePtr< T > & operator=(IntrusivePtr< T > const &that)
Definition: intrusive_ptr.h:116
IntrusivePtr(IntrusivePtr &&that) noexcept
Definition: intrusive_ptr.h:112
void swap(IntrusivePtr< T > &that) noexcept
Definition: intrusive_ptr.h:144
element_type * get() const noexcept
Definition: intrusive_ptr.h:133
~IntrusivePtr()
Definition: intrusive_ptr.h:114
IntrusivePtr() noexcept=default
T * ptr_
Definition: intrusive_ptr.h:90
T element_type
Definition: intrusive_ptr.h:93
int32_t use_count() noexcept
Definition: intrusive_ptr.h:137
IntrusivePtr(T *p)
Contruct an IntrusivePtr from raw pointer. IntrusivePtr takes the ownership.
Definition: intrusive_ptr.h:104
element_type * operator->() const noexcept
Definition: intrusive_ptr.h:132
void reset()
Definition: intrusive_ptr.h:125
Definition: intrusive_ptr.h:207
void swap(xgboost::IntrusivePtr< T > &x, xgboost::IntrusivePtr< T > &y) noexcept
Definition: intrusive_ptr.h:209
Core data structure for multi-target trees.
Definition: base.h:87
bool operator!=(IntrusivePtr< T > const &x, IntrusivePtr< U > const &y) noexcept
Definition: intrusive_ptr.h:155
bool operator==(IntrusivePtr< T > const &x, IntrusivePtr< U > const &y) noexcept
Definition: intrusive_ptr.h:150
IntrusivePtrCell & IntrusivePtrRefCount(T const *ptr) noexcept
User defined function for returning embedded reference count.
std::ostream & operator<<(std::ostream &os, DeviceOrd ord)
bool operator>=(IntrusivePtr< T > const &x, IntrusivePtr< T > const &y) noexcept
Definition: intrusive_ptr.h:195
bool operator>(IntrusivePtr< T > const &x, IntrusivePtr< T > const &y) noexcept
Definition: intrusive_ptr.h:190
bool operator<=(IntrusivePtr< T > const &x, IntrusivePtr< T > const &y) noexcept
Definition: intrusive_ptr.h:185
bool operator<(IntrusivePtr< T > const &x, IntrusivePtr< T > const &y) noexcept
Definition: intrusive_ptr.h:180
Definition: intrusive_ptr.h:94
std::size_t operator()(IntrusivePtr< element_type > const &ptr) const noexcept
Definition: intrusive_ptr.h:95