12 #ifndef __UT_INTRUSIVEPTR_H_INCLUDED__
13 #define __UT_INTRUSIVEPTR_H_INCLUDED__
19 #include <hboost/intrusive_ptr.hpp>
110 template <
typename Y>
120 template <
typename T,
typename... ArgsT>
136 return counter.relaxedLoad();
142 (
void)counter.add(1);
147 (
void)counter.add(refs_to_add);
153 return counter.add(-1);
158 return counter.add(-
int32(refs_to_remove));
176 int32 r = counter.relaxedLoad();
183 if (counter.compareExchangeWeak(
211 counter += refs_to_add;
222 return (counter -= refs_to_remove);
239 typename Deleter = std::default_delete<DerivedT>,
244 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
248 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
252 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
255 typename CounterPolicyT::pod_type refs_to_add) noexcept;
257 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
260 typename CounterPolicyT::pod_type refs_to_remove) noexcept;
281 typename CounterPolicyT
307 return CounterPolicyT::load(myRefCount);
315 return CounterPolicyT::conditionalIncrement(myRefCount);
328 friend void intrusive_ptr_add_ref<DerivedT,Deleter,CounterPolicyT>(
331 friend void intrusive_ptr_release<DerivedT,Deleter,CounterPolicyT>(
334 friend void intrusive_ptr_add_ref<DerivedT,Deleter,CounterPolicyT>(
336 typename CounterPolicyT::pod_type refs_to_add) noexcept;
337 friend void intrusive_ptr_release<DerivedT,Deleter,CounterPolicyT>(
339 typename CounterPolicyT::pod_type refs_to_remove) noexcept;
343 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
348 CounterPolicyT::increment(p->myRefCount);
350 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
355 if (CounterPolicyT::decrement(p->myRefCount) == 0)
362 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
366 typename CounterPolicyT::pod_type refs_to_add) noexcept
368 CounterPolicyT::increment(p->myRefCount, refs_to_add);
370 template <
typename DerivedT,
typename Deleter,
typename CounterPolicyT>
374 typename CounterPolicyT::pod_type refs_to_remove) noexcept
376 if (CounterPolicyT::decrement(p->myRefCount, refs_to_remove) == 0)
386 template <
typename T>
387 struct DefaultClearer;
389 template <
typename T>
395 {
return v.get() ==
nullptr; }
398 static const bool clearNeedsDestruction =
false;
402 #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.
SYS_FORCE_INLINE UT_IntrusivePtr< T > & operator=(UT_IntrusivePtr< Y > &&that)
Any reordering the compiler or hardware chooses to do is okay.
static void clearConstruct(UT_IntrusivePtr< T > *p)
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.