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);
93 using element_type = T;
96 return std::hash<element_type *>()(ptr.get());
112 IntrusivePtr(IntrusivePtr &&that) noexcept : ptr_{that.ptr_} { that.ptr_ =
nullptr; }
114 ~IntrusivePtr() { DecRef(ptr_); }
116 IntrusivePtr<T> &operator=(IntrusivePtr<T>
const &that) {
117 IntrusivePtr<T>{that}.swap(*
this);
120 IntrusivePtr<T> &operator=(IntrusivePtr<T> &&that)
noexcept {
129 void reset(element_type *that) {
IntrusivePtr{that}.swap(*
this); }
131 element_type &operator*() const noexcept {
return *ptr_; }
132 element_type *operator->() const noexcept {
return ptr_; }
133 element_type *get() const noexcept {
return ptr_; }
135 explicit operator bool() const noexcept {
return static_cast<bool>(ptr_); }
137 int32_t use_count() noexcept {
144 void swap(IntrusivePtr<T> &that)
noexcept {
149template <
class T,
class U>
150bool operator==(IntrusivePtr<T>
const &x, IntrusivePtr<U>
const &y)
noexcept {
151 return x.get() == y.get();
154template <
class T,
class U>
155bool operator!=(IntrusivePtr<T>
const &x, IntrusivePtr<U>
const &y)
noexcept {
156 return x.get() != y.get();
159template <
class T,
class U>
160bool operator==(IntrusivePtr<T>
const &x, U *y)
noexcept {
164template <
class T,
class U>
165bool operator!=(IntrusivePtr<T>
const &x, U *y)
noexcept {
169template <
class T,
class U>
170bool operator==(T *x, IntrusivePtr<U>
const &y)
noexcept {
174template <
class T,
class U>
175bool operator!=(T *x, IntrusivePtr<U>
const &y)
noexcept {
180bool operator<(IntrusivePtr<T>
const &x, IntrusivePtr<T>
const &y)
noexcept {
181 return std::less<T*>{}(x.get(), y.get());
185bool operator<=(IntrusivePtr<T>
const &x, IntrusivePtr<T>
const &y)
noexcept {
186 return std::less_equal<T*>{}(x.get(), y.get());
190bool operator>(IntrusivePtr<T>
const &x, IntrusivePtr<T>
const &y)
noexcept {
195bool operator>=(IntrusivePtr<T>
const &x, IntrusivePtr<T>
const &y)
noexcept {
199template <
class E,
class T,
class Y>
200std::basic_ostream<E, T> &operator<<(std::basic_ostream<E, T> &os,
201 IntrusivePtr<Y>
const &p) {
Helper class for embedding reference counting into client objects. See https://www....
Definition intrusive_ptr.h:20
Implementation of Intrusive Pointer. A smart pointer that points to an object with an embedded refere...
Definition intrusive_ptr.h:73
IntrusivePtr(T *p)
Contruct an IntrusivePtr from raw pointer. IntrusivePtr takes the ownership.
Definition intrusive_ptr.h:104
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition json.hpp:2889
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.hpp:24418
namespace of xgboost
Definition base.h:90
IntrusivePtrCell & IntrusivePtrRefCount(T const *ptr) noexcept
User defined function for returning embedded reference count.
Definition intrusive_ptr.h:94