KiCad PCB EDA Suite
Loading...
Searching...
No Matches
RHI_HANDLE_POOL< Tag > Class Template Reference

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
 

Detailed Description

template<typename Tag>
class RHI_HANDLE_POOL< Tag >

Thread-safe pool that allocates and recycles generation-tracked handles for device implementations.

Definition at line 100 of file rhi_handle.h.

Constructor & Destructor Documentation

◆ RHI_HANDLE_POOL()

template<typename Tag>
RHI_HANDLE_POOL< Tag >::RHI_HANDLE_POOL ( )
inline

Definition at line 103 of file rhi_handle.h.

References m_entries.

Member Function Documentation

◆ Allocate()

template<typename Tag>
RHI_HANDLE< Tag > RHI_HANDLE_POOL< Tag >::Allocate ( )
inline

Definition at line 105 of file rhi_handle.h.

References index, m_entries, m_freeList, m_mutex, RHI_HANDLE_INDEX_MASK, and RhiMakeHandle().

◆ findLive()

template<typename Tag>
template<typename POOL>
static auto RHI_HANDLE_POOL< Tag >::findLive ( POOL & aPool,
RHI_HANDLE< Tag > handle ) -> decltype( &aPool.m_entries[0] )
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().

◆ IsValid()

template<typename Tag>
bool RHI_HANDLE_POOL< Tag >::IsValid ( RHI_HANDLE< Tag > handle) const
inline

Definition at line 174 of file rhi_handle.h.

References findLive(), m_mutex, and RHI_HANDLE_POOL< Tag >::Entry::pendingDestroy.

◆ MarkPendingDestroy()

template<typename Tag>
bool RHI_HANDLE_POOL< Tag >::MarkPendingDestroy ( RHI_HANDLE< Tag > handle)
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.

Returns
true only for the call that claimed the slot. Callers enqueue the release only then, so concurrent destroys of one handle never free it twice.

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().

◆ Release()

template<typename Tag>
void RHI_HANDLE_POOL< Tag >::Release ( RHI_HANDLE< Tag > handle)
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().

Member Data Documentation

◆ m_entries

template<typename Tag>
std::vector<Entry> RHI_HANDLE_POOL< Tag >::m_entries
private

Definition at line 196 of file rhi_handle.h.

Referenced by Allocate(), and RHI_HANDLE_POOL().

◆ m_freeList

template<typename Tag>
std::vector<uint32_t> RHI_HANDLE_POOL< Tag >::m_freeList
private

Definition at line 197 of file rhi_handle.h.

Referenced by Allocate(), and Release().

◆ m_mutex

template<typename Tag>
std::mutex RHI_HANDLE_POOL< Tag >::m_mutex
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().


The documentation for this class was generated from the following file: