QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstHw::GstHwImportCache< Key, Resource, Capacity > Class Template Reference

#include <GstHwImportCache.h>

Classes

struct  Hit

Public Types

using DestroyFn = void (*)(Resource&)
using CanDestroyFn = bool (*)(const Resource&)
using EntryId = std::uint64_t
 Identifies one inserted entry for pin()/unpin(), also after it is parked; never 0.

Public Member Functions

 GstHwImportCache (DestroyFn destroy, CanDestroyFn destroyableHere=nullptr)
 ~GstHwImportCache ()
 Static teardown: entries still pinned or not destroyable on this thread are leaked, never destroyed unsafely.
 GstHwImportCache (const GstHwImportCache &)=delete
GstHwImportCache & operator= (const GstHwImportCache &)=delete
Hit find (const Key &key)
 MRU-promoting lookup. The resource pointer is invalidated by the next insert/eraseIf/clear on this cache.
Hit insert (const Key &key, Resource resource)
void pin (EntryId id) noexcept
 Keeps entry id from being destroyed until a matching unpin(); no-op for an unknown id.
void unpin (EntryId id) noexcept
 Releases one pin(). A parked entry is destroyed by the next drainDeferred() once its last pin is gone.
template<class Pred>
void eraseIf (Pred pred)
 Removes every live entry for which pred(key, resource) holds.
void clear ()
void drainDeferred ()
 Destroys parked entries that are unpinned and destroyable on the calling thread.
std::size_t size () const noexcept
std::size_t parkedCount () const noexcept
 Entries removed from the cache but not yet destroyed (pinned, or awaiting their owner thread).

Detailed Description

template<class Key, class Resource, std::size_t Capacity>
class GstHw::GstHwImportCache< Key, Resource, Capacity >

Bounded LRU cache for GPU import resources sized for the handful of buffers a decoder pool recycles: a flat array searched linearly, so lookups and inserts never allocate. Serves the AHardwareBuffer path (EGLImages).

Pinned entries (a frame bundle still samples them) are never destroyed: eviction skips them, and erase/clear park them until unpinned. Entries removed where destroyableHere rejects them (e.g. off the render thread that owns the GPU object) are parked as well; drainDeferred() destroys parked entries once both conditions allow it. Not internally synchronized — the caller serializes access.

Definition at line 19 of file GstHwImportCache.h.

Member Typedef Documentation

◆ CanDestroyFn

template<class Key, class Resource, std::size_t Capacity>
using GstHw::GstHwImportCache< Key, Resource, Capacity >::CanDestroyFn = bool (*)(const Resource&)

Definition at line 23 of file GstHwImportCache.h.

◆ DestroyFn

template<class Key, class Resource, std::size_t Capacity>
using GstHw::GstHwImportCache< Key, Resource, Capacity >::DestroyFn = void (*)(Resource&)

Definition at line 22 of file GstHwImportCache.h.

◆ EntryId

template<class Key, class Resource, std::size_t Capacity>
using GstHw::GstHwImportCache< Key, Resource, Capacity >::EntryId = std::uint64_t

Identifies one inserted entry for pin()/unpin(), also after it is parked; never 0.

Definition at line 25 of file GstHwImportCache.h.

Constructor & Destructor Documentation

◆ GstHwImportCache() [1/2]

template<class Key, class Resource, std::size_t Capacity>
GstHw::GstHwImportCache< Key, Resource, Capacity >::GstHwImportCache ( DestroyFn destroy,
CanDestroyFn destroyableHere = nullptr )
inlineexplicit

Definition at line 35 of file GstHwImportCache.h.

Referenced by GstHwImportCache(), and operator=().

◆ ~GstHwImportCache()

template<class Key, class Resource, std::size_t Capacity>
GstHw::GstHwImportCache< Key, Resource, Capacity >::~GstHwImportCache ( )
inline

Static teardown: entries still pinned or not destroyable on this thread are leaked, never destroyed unsafely.

Definition at line 41 of file GstHwImportCache.h.

References clear(), and drainDeferred().

◆ GstHwImportCache() [2/2]

template<class Key, class Resource, std::size_t Capacity>
GstHw::GstHwImportCache< Key, Resource, Capacity >::GstHwImportCache ( const GstHwImportCache< Key, Resource, Capacity > & )
delete

References GstHwImportCache().

Member Function Documentation

◆ clear()

template<class Key, class Resource, std::size_t Capacity>
void GstHw::GstHwImportCache< Key, Resource, Capacity >::clear ( )
inline

Definition at line 125 of file GstHwImportCache.h.

References eraseIf().

Referenced by ~GstHwImportCache().

◆ drainDeferred()

template<class Key, class Resource, std::size_t Capacity>
void GstHw::GstHwImportCache< Key, Resource, Capacity >::drainDeferred ( )
inline

Destroys parked entries that are unpinned and destroyable on the calling thread.

Definition at line 131 of file GstHwImportCache.h.

Referenced by ~GstHwImportCache().

◆ eraseIf()

template<class Key, class Resource, std::size_t Capacity>
template<class Pred>
void GstHw::GstHwImportCache< Key, Resource, Capacity >::eraseIf ( Pred pred)
inline

Removes every live entry for which pred(key, resource) holds.

Definition at line 116 of file GstHwImportCache.h.

Referenced by clear().

◆ find()

template<class Key, class Resource, std::size_t Capacity>
Hit GstHw::GstHwImportCache< Key, Resource, Capacity >::find ( const Key & key)
inline

MRU-promoting lookup. The resource pointer is invalidated by the next insert/eraseIf/clear on this cache.

Definition at line 51 of file GstHwImportCache.h.

◆ insert()

template<class Key, class Resource, std::size_t Capacity>
Hit GstHw::GstHwImportCache< Key, Resource, Capacity >::insert ( const Key & key,
Resource resource )
inline

Stores resource under key, replacing any entry for it and evicting the least recently used unpinned entry when full. Fails, retiring resource, when every slot is pinned.

Definition at line 64 of file GstHwImportCache.h.

◆ operator=()

template<class Key, class Resource, std::size_t Capacity>
GstHwImportCache & GstHw::GstHwImportCache< Key, Resource, Capacity >::operator= ( const GstHwImportCache< Key, Resource, Capacity > & )
delete

References GstHwImportCache().

◆ parkedCount()

template<class Key, class Resource, std::size_t Capacity>
std::size_t GstHw::GstHwImportCache< Key, Resource, Capacity >::parkedCount ( ) const
inlinenoexcept

Entries removed from the cache but not yet destroyed (pinned, or awaiting their owner thread).

Definition at line 153 of file GstHwImportCache.h.

◆ pin()

template<class Key, class Resource, std::size_t Capacity>
void GstHw::GstHwImportCache< Key, Resource, Capacity >::pin ( EntryId id)
inlinenoexcept

Keeps entry id from being destroyed until a matching unpin(); no-op for an unknown id.

Definition at line 99 of file GstHwImportCache.h.

◆ size()

template<class Key, class Resource, std::size_t Capacity>
std::size_t GstHw::GstHwImportCache< Key, Resource, Capacity >::size ( ) const
inlinenoexcept

Definition at line 143 of file GstHwImportCache.h.

◆ unpin()

template<class Key, class Resource, std::size_t Capacity>
void GstHw::GstHwImportCache< Key, Resource, Capacity >::unpin ( EntryId id)
inlinenoexcept

Releases one pin(). A parked entry is destroyed by the next drainDeferred() once its last pin is gone.

Definition at line 107 of file GstHwImportCache.h.


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