12 #ifndef __UT_INTRUSIVEPTR_H_INCLUDED__
13 #define __UT_INTRUSIVEPTR_H_INCLUDED__
19 #include <hboost/smart_ptr/intrusive_ptr.hpp>
113 template <
typename Y>
125 template <
typename T>
130 return SYSpointerHash(p.get());
136 template <
typename T,
typename... ArgsT>
152 return counter.relaxedLoad();
158 (
void)counter.add(1);
163 (
void)counter.add(refs_to_add);
169 return counter.add(-1);
174 return counter.add(-
int32(refs_to_remove));
192 int32 r = counter.relaxedLoad();
199 if (counter.compareExchangeWeak(
227 counter += refs_to_add;
238 return (counter -= refs_to_remove);
255 typename Deleter = std::default_delete<DerivedT>,
260 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
264 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
268 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
271 typename CounterPolicyT::pod_type refs_to_add) noexcept;
273 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
276 typename CounterPolicyT::pod_type refs_to_remove) noexcept;
297 typename CounterPolicyT
323 return CounterPolicyT::load(myRefCount);
331 return CounterPolicyT::conditionalIncrement(myRefCount);
344 friend void intrusive_ptr_add_ref<DerivedT,Deleter,CounterPolicyT>(
347 friend void intrusive_ptr_release<DerivedT,Deleter,CounterPolicyT>(
350 friend void intrusive_ptr_add_ref<DerivedT,Deleter,CounterPolicyT>(
352 typename CounterPolicyT::pod_type refs_to_add) noexcept;
353 friend void intrusive_ptr_release<DerivedT,Deleter,CounterPolicyT>(
355 typename CounterPolicyT::pod_type refs_to_remove) noexcept;
359 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
364 CounterPolicyT::increment(p->myRefCount);
366 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
371 if (CounterPolicyT::decrement(p->myRefCount) == 0)
378 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
382 typename CounterPolicyT::pod_type refs_to_add) noexcept
384 CounterPolicyT::increment(p->myRefCount, refs_to_add);
386 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
390 typename CounterPolicyT::pod_type refs_to_remove) noexcept
392 if (CounterPolicyT::decrement(p->myRefCount, refs_to_remove) == 0)
402 template <
typename T>
403 struct DefaultClearer;
405 template <
typename T>
411 {
return v.get() ==
nullptr; }
414 static const bool clearNeedsDestruction =
false;
418 #endif // __UT_INTRUSIVEPTR_H_INCLUDED__
SYS_FORCE_INLINE UT_IntrusivePtr(T *p, bool add_ref)
SYS_FORCE_INLINE bool conditionalAddRef() noexcept
static SYS_FORCE_INLINE void increment(type &counter, pod_type refs_to_add) noexcept
static SYS_FORCE_INLINE void increment(type &counter, pod_type refs_to_add) noexcept
SYS_FORCE_INLINE UT_IntrusivePtr() noexcept
void intrusive_ptr_release(const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *p) noexcept
static SYS_FORCE_INLINE void increment(type &counter) noexcept
UT_IntrusivePtr< T > UTmakeIntrusive(ArgsT &&...args)
Constructs an object of type T wrapped in a UT_IntrusivePtr.
SYS_FORCE_INLINE UT_IntrusivePtr(T *p)
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
SYS_AtomicInt< int32 > SYS_AtomicInt32
static SYS_FORCE_INLINE bool conditionalIncrement(type &counter) noexcept
SYS_FORCE_INLINE UT_IntrusivePtr(const UT_IntrusivePtr< Y > &p)
A reference counter base class for use with UT_IntrusivePtr.
void intrusive_ptr_add_ref(const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *p) noexcept
NON Thread-safe policy for UT_IntrusiveRefCounter.
UT_IntrusiveRefCounter & operator=(const UT_IntrusiveRefCounter &) noexcept
Assignment operator: Does not modify counter.
static bool isClear(const UT_IntrusivePtr< T > &v)
SYS_FORCE_INLINE uint32 use_count() const noexcept
Return current counter.
SYS_FORCE_INLINE UT_IntrusivePtr< T > & operator=(UT_IntrusivePtr< T > &&that)
SYS_FORCE_INLINE UT_IntrusivePtr< T > & operator=(const UT_IntrusivePtr< T > &that)
Wrapper around hboost::intrusive_ptr.
SYS_FORCE_INLINE UT_IntrusivePtr(const UT_IntrusivePtr< T > &p)
SYS_FORCE_INLINE UT_IntrusiveRefCounter(const UT_IntrusiveRefCounter &) noexcept
Copy constructor: Sets counter to 0.
constexpr SYS_MemoryOrder SYS_MEMORY_ORDER_RELAXED
Any reordering the compiler or hardware chooses to do is okay.
SYS_FORCE_INLINE UT_IntrusivePtr< T > & operator=(UT_IntrusivePtr< Y > &&that)
static void clearConstruct(UT_IntrusivePtr< T > *p)
size_t operator()(const UT_IntrusivePtr< T > &p) const
static SYS_FORCE_INLINE uint32 decrement(type &counter, pod_type refs_to_remove) noexcept
static void clear(UT_IntrusivePtr< T > &v)
SYS_FORCE_INLINE UT_IntrusivePtr(UT_IntrusivePtr< T > &&p)
static SYS_FORCE_INLINE bool conditionalIncrement(type &counter) noexcept
static SYS_FORCE_INLINE uint32 decrement(type &counter, pod_type refs_to_remove) noexcept
LeafData & operator=(const LeafData &)=delete
static SYS_FORCE_INLINE uint32 decrement(type &counter) noexcept
static SYS_FORCE_INLINE uint32 load(const type &counter) noexcept
**If you just want to fire and args
SYS_FORCE_INLINE ~UT_IntrusiveRefCounter()
Destructor: Only derived classes can destruct this.
SYS_FORCE_INLINE UT_IntrusivePtr< T > & operator=(const UT_IntrusivePtr< Y > &that)
SYS_FORCE_INLINE UT_IntrusiveRefCounter() noexcept
Default constructor: Sets counter to 0.
static SYS_FORCE_INLINE uint32 decrement(type &counter) noexcept
SYS_FORCE_INLINE UT_IntrusivePtr(UT_IntrusivePtr< Y > &&p)
static SYS_FORCE_INLINE uint32 load(const type &counter) noexcept
Thread-safe policy for UT_IntrusiveRefCounter.
static SYS_FORCE_INLINE void increment(type &counter) noexcept
A simple intrusive pointer, modeled after std::shared_ptr.