KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SHARDED_CACHE< KEY, VALUE, SHARDS > Class Template Reference

A concurrent key/value cache split into independently locked shards. More...

#include <sharded_cache.h>

Classes

struct  SHARD
 

Public Member Functions

bool Get (const KEY &aKey, VALUE &aValue) const
 Look up a key. Returns false on a miss and leaves aValue untouched.
 
void Set (const KEY &aKey, const VALUE &aValue)
 
void Clear ()
 
bool Empty () const
 

Private Member Functions

std::size_t Size () const
 Only Clear() needs this; an exact concurrent size has no sound external use, so private.
 
SHARDshardFor (const KEY &aKey)
 
const SHARDshardFor (const KEY &aKey) const
 

Private Attributes

std::array< SHARD, SHARDS > m_shards
 

Static Private Attributes

static constexpr std::size_t PARALLEL_CLEAR_THRESHOLD = 100000
 Entry count above which Clear() fans its per-shard deallocation across the worker pool.
 

Detailed Description

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
class SHARDED_CACHE< KEY, VALUE, SHARDS >

A concurrent key/value cache split into independently locked shards.

The DRC expression evaluator populates per-item-pair predicate caches from every worker thread at once. A single mutex over one map serializes all of them, so the multi-threaded check collapses to single-threaded throughput. Striping the map across many shards, each with its own lock, lets threads working on different keys proceed without contending. The shard is chosen by the key hash, so a given key always maps to the same shard and the cache stays coherent.

Definition at line 40 of file sharded_cache.h.

Member Function Documentation

◆ Clear()

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
void SHARDED_CACHE< KEY, VALUE, SHARDS >::Clear ( )
inline

Definition at line 66 of file sharded_cache.h.

References GetKiCadThreadPool(), m_shards, PARALLEL_CLEAR_THRESHOLD, Size(), and tp.

◆ Empty()

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
bool SHARDED_CACHE< KEY, VALUE, SHARDS >::Empty ( ) const
inline

Definition at line 95 of file sharded_cache.h.

References m_shards.

◆ Get()

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
bool SHARDED_CACHE< KEY, VALUE, SHARDS >::Get ( const KEY & aKey,
VALUE & aValue ) const
inline

◆ Set()

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
void SHARDED_CACHE< KEY, VALUE, SHARDS >::Set ( const KEY & aKey,
const VALUE & aValue )
inline

◆ shardFor() [1/2]

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
SHARD & SHARDED_CACHE< KEY, VALUE, SHARDS >::shardFor ( const KEY & aKey)
inlineprivate

Definition at line 132 of file sharded_cache.h.

References m_shards.

Referenced by Get(), and Set().

◆ shardFor() [2/2]

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
const SHARD & SHARDED_CACHE< KEY, VALUE, SHARDS >::shardFor ( const KEY & aKey) const
inlineprivate

Definition at line 137 of file sharded_cache.h.

References m_shards.

◆ Size()

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
std::size_t SHARDED_CACHE< KEY, VALUE, SHARDS >::Size ( ) const
inlineprivate

Only Clear() needs this; an exact concurrent size has no sound external use, so private.

Definition at line 113 of file sharded_cache.h.

References m_shards.

Referenced by Clear().

Member Data Documentation

◆ m_shards

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
std::array<SHARD, SHARDS> SHARDED_CACHE< KEY, VALUE, SHARDS >::m_shards
private

Definition at line 142 of file sharded_cache.h.

Referenced by Clear(), Empty(), shardFor(), shardFor(), and Size().

◆ PARALLEL_CLEAR_THRESHOLD

template<typename KEY, typename VALUE, std::size_t SHARDS = 256>
std::size_t SHARDED_CACHE< KEY, VALUE, SHARDS >::PARALLEL_CLEAR_THRESHOLD = 100000
staticconstexprprivate

Entry count above which Clear() fans its per-shard deallocation across the worker pool.

Definition at line 110 of file sharded_cache.h.

Referenced by Clear().


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