Go to the documentation of this file.
6 #ifndef XGBOOST_INTRUSIVE_PTR_H_
7 #define XGBOOST_INTRUSIVE_PTR_H_
21 std::atomic<int32_t> count_;
24 std::int32_t IncRef() noexcept {
25 return count_.fetch_add(1, std::memory_order_relaxed);
27 std::int32_t DecRef() noexcept {
28 return count_.fetch_sub(1, std::memory_order_release);
30 bool IsZero()
const {
return Count() == 0; }
34 int32_t
Count()
const {
return count_.load(std::memory_order_relaxed); }
82 std::atomic_thread_fence(std::memory_order_acquire);
95 return std::hash<element_type *>()(ptr.get());
134 explicit operator bool() const noexcept {
return static_cast<bool>(
ptr_); }
148 template <
class T,
class U>
150 return x.get() == y.get();
153 template <
class T,
class U>
155 return x.get() != y.get();
158 template <
class T,
class U>
163 template <
class T,
class U>
168 template <
class T,
class U>
173 template <
class T,
class U>
180 return std::less<T*>{}(x.get(), y.get());
185 return std::less_equal<T*>{}(x.get(), y.get());
198 template <
class E,
class T,
class Y>
199 std::basic_ostream<E, T> &
operator<<(std::basic_ostream<E, T> &os,
213 template <
typename T>
216 #endif // XGBOOST_INTRUSIVE_PTR_H_
Implementation of Intrusive Pointer. A smart pointer that points to an object with an embedded refere...
Definition: intrusive_ptr.h:72
IntrusivePtr(IntrusivePtr &&that) noexcept
Definition: intrusive_ptr.h:111
Definition: intrusive_ptr.h:93
void swap(xgboost::IntrusivePtr< T > &x, xgboost::IntrusivePtr< T > &y) noexcept
Definition: intrusive_ptr.h:208
bool operator<(IntrusivePtr< T > const &x, IntrusivePtr< T > const &y) noexcept
Definition: intrusive_ptr.h:179
bool operator>(IntrusivePtr< T > const &x, IntrusivePtr< T > const &y) noexcept
Definition: intrusive_ptr.h:189
IntrusivePtr< T > & operator=(IntrusivePtr< T > const &that)
Definition: intrusive_ptr.h:115
std::basic_ostream< E, T > & operator<<(std::basic_ostream< E, T > &os, IntrusivePtr< Y > const &p)
Definition: intrusive_ptr.h:199
void reset()
Definition: intrusive_ptr.h:124
int32_t Count() const
Definition: intrusive_ptr.h:34
element_type * get() const noexcept
Definition: intrusive_ptr.h:132
IntrusivePtrCell & IntrusivePtrRefCount(T const *ptr) noexcept
User defined function for returing embedded reference count.
bool operator<=(IntrusivePtr< T > const &x, IntrusivePtr< T > const &y) noexcept
Definition: intrusive_ptr.h:184
void swap(IntrusivePtr< T > &that) noexcept
Definition: intrusive_ptr.h:143
IntrusivePtr(T *p)
Contruct an IntrusivePtr from raw pointer. IntrusivePtr takes the ownership.
Definition: intrusive_ptr.h:103
int32_t use_count() noexcept
Definition: intrusive_ptr.h:136
bool operator!=(IntrusivePtr< T > const &x, IntrusivePtr< U > const &y) noexcept
Definition: intrusive_ptr.h:154
IntrusivePtr< T > & operator=(IntrusivePtr< T > &&that) noexcept
Definition: intrusive_ptr.h:119
~IntrusivePtr()
Definition: intrusive_ptr.h:113
Helper class for embedding reference counting into client objects. See https://www....
Definition: intrusive_ptr.h:19
void reset(element_type *that)
Definition: intrusive_ptr.h:128
element_type * operator->() const noexcept
Definition: intrusive_ptr.h:131
element_type & operator*() const noexcept
Definition: intrusive_ptr.h:130
T * ptr_
Definition: intrusive_ptr.h:89
bool operator>=(IntrusivePtr< T > const &x, IntrusivePtr< T > const &y) noexcept
Definition: intrusive_ptr.h:194
Definition: intrusive_ptr.h:206
IntrusivePtr() noexcept=default
IntrusivePtrCell() noexcept
Definition: intrusive_ptr.h:33
std::size_t operator()(IntrusivePtr< element_type > const &ptr) const noexcept
Definition: intrusive_ptr.h:94
bool operator==(IntrusivePtr< T > const &x, IntrusivePtr< U > const &y) noexcept
Definition: intrusive_ptr.h:149
namespace of xgboost
Definition: base.h:110