struct TSharedControlBlock

template<ThreadSafetyPolicy ThreadSafety>

Common based class for TShared/TWeak control blocks.

Control blocks maintains a reference count of the shared pointer and will release the object after the reference count reaches zero.

Public

Methods

~TSharedControlBlock<ThreadSafety>

virtual ~TSharedControlBlock<ThreadSafety>() = default

GetStrongReferenceCount

u32 GetStrongReferenceCount() const

Returns the number of currently held strong references.

IncrementStrongReferenceCount

void IncrementStrongReferenceCount()

Increments the strong reference count.

As long as strong reference count is non-zero the owned object will be kept alive.

DecrementStrongReferenceCount

void DecrementStrongReferenceCount()

Decrements the strong reference count.

If the strong reference count reaches zero the owned object will be destroyed. Additionally if there are no weak resource handles alive either, control block data will be destroyed.

IncrementWeakReferenceCount

void IncrementWeakReferenceCount()

Increments the weak reference count.

This keeps the control block data alive, but not the owned object itself.

DecrementWeakReferenceCount

void DecrementWeakReferenceCount()

Decrements the weak reference count.

If this was the last weak reference and there are no strong references either, control block data will be destroyed.

IncrementStrongReferenceCountIfNonZero

bool IncrementStrongReferenceCountIfNonZero()

Increments the strong reference count, but only if it is not already at zero.

Returns true if incremented.

DestroyOwnedObject

virtual void DestroyOwnedObject() = 0

Destroys the object the control block is pointing to.

DestroySelf

virtual void DestroySelf() = 0

Destroys the control block.

Protected

Constructors

TSharedControlBlock<ThreadSafety>

TSharedControlBlock<ThreadSafety>() = default

Private

Fields

StrongReferenceCount

CounterType StrongReferenceCount

References keeping the object alive (strong handles).

WeakReferenceCount

CounterType WeakReferenceCount

References keeping the control block data alive (weak handles + 1 if any strong handle is alive).