|
KiCad PCB EDA Suite
|
Thread-safe pool that allocates and recycles generation-tracked handles for device implementations. More...
#include <rhi_handle.h>
Classes | |
| struct | Entry |
Public Member Functions | |
| RHI_HANDLE_POOL () | |
| RHI_HANDLE< Tag > | Allocate () |
| bool | MarkPendingDestroy (RHI_HANDLE< Tag > handle) |
| Make a handle invalid while keeping its slot out of the free list until Release(). | |
| void | Release (RHI_HANDLE< Tag > handle) |
| bool | IsValid (RHI_HANDLE< Tag > handle) const |
Static Private Member Functions | |
| template<typename POOL> | |
| static auto | findLive (POOL &aPool, RHI_HANDLE< Tag > handle) -> decltype(&aPool.m_entries[0]) |
| Return the entry of a handle that is alive at its generation, or nullptr. | |
Private Attributes | |
| std::mutex | m_mutex |
| Handles are allocated and released from both the UI and render threads, and Allocate() can reallocate m_entries while IsValid() reads it. | |
| std::vector< Entry > | m_entries |
| std::vector< uint32_t > | m_freeList |
Thread-safe pool that allocates and recycles generation-tracked handles for device implementations.
Definition at line 100 of file rhi_handle.h.
|
inline |
Definition at line 103 of file rhi_handle.h.
References m_entries.
|
inline |
Definition at line 105 of file rhi_handle.h.
References index, m_entries, m_freeList, m_mutex, RHI_HANDLE_INDEX_MASK, and RhiMakeHandle().
|
inlinestaticprivate |
Return the entry of a handle that is alive at its generation, or nullptr.
The caller holds m_mutex.
Definition at line 203 of file rhi_handle.h.
References index, RhiHandleGeneration(), and RhiHandleIndex().
Referenced by IsValid(), MarkPendingDestroy(), and Release().
|
inline |
Definition at line 174 of file rhi_handle.h.
References findLive(), m_mutex, and RHI_HANDLE_POOL< Tag >::Entry::pendingDestroy.
|
inline |
Make a handle invalid while keeping its slot out of the free list until Release().
Deferred release needs this because the GPU resource outlives the handle, and a recycled slot would let the pending release destroy an unrelated resource.
Definition at line 138 of file rhi_handle.h.
References findLive(), m_mutex, and RHI_HANDLE_POOL< Tag >::Entry::pendingDestroy.
Referenced by RHI_DEVICE::deferDestroy().
|
inline |
A wrapped generation would let a very old handle match a new resource, so retire the slot. The 20-bit index space absorbs the rare leak.
Definition at line 150 of file rhi_handle.h.
References RHI_HANDLE_POOL< Tag >::Entry::alive, findLive(), RHI_HANDLE_POOL< Tag >::Entry::generation, m_freeList, m_mutex, RHI_HANDLE_POOL< Tag >::Entry::pendingDestroy, RHI_HANDLE_GEN_MASK, and RhiHandleIndex().
Referenced by RhiReleasePooledResource().
|
private |
Definition at line 196 of file rhi_handle.h.
Referenced by Allocate(), and RHI_HANDLE_POOL().
|
private |
Definition at line 197 of file rhi_handle.h.
Referenced by Allocate(), and Release().
|
mutableprivate |
Handles are allocated and released from both the UI and render threads, and Allocate() can reallocate m_entries while IsValid() reads it.
Definition at line 195 of file rhi_handle.h.
Referenced by Allocate(), IsValid(), MarkPendingDestroy(), and Release().