struct ResourceHandleData

Data that is shared between all resource handles.

Public

Constructors

ResourceHandleData

ResourceHandleData() = default

ResourceHandleData

ResourceHandleData(const UUID &id)

ResourceHandleData

ResourceHandleData(const SPtr<Resource> &object, const UUID &id)

Methods

IncrementStrongReferenceCount

void IncrementStrongReferenceCount()

Increments the strong reference count.

As long as strong reference count is non-zero the handle will keep the managed resource alive.

DecrementStrongReferenceCount

void DecrementStrongReferenceCount()

Decrements the strong reference count.

If the strong reference count reaches zero the managed resource will be destroyed. Additionally if there are no weak resource handles alive either, resource handle data will also be destroyed.

IncrementWeakReferenceCount

void IncrementWeakReferenceCount()

Increments the weak reference count.

This keeps the resource handle data alive, but not the managed resource itself.

DecrementWeakReferenceCount

void DecrementWeakReferenceCount()

Decrements the weak reference count.

If this was the last weak reference and there are no strong references either, handle 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.

DestroyManagedResource

void DestroyManagedResource()

Destroys the resource the handle is pointing to.

DestroySelf

void DestroySelf()

Destroys the handle data.

Fields

Object

SPtr<Resource> Object

Id

UUID Id

IsCreated

bool IsCreated

StrongReferenceCount

std::atomic<std::uint32_t> StrongReferenceCount

References keeping the resource alive (strong handles).

WeakReferenceCount

std::atomic<std::uint32_t> WeakReferenceCount

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