|
KiCad PCB EDA Suite
|
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. | |
| SHARD & | shardFor (const KEY &aKey) |
| const SHARD & | shardFor (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. | |
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.
|
inline |
Definition at line 66 of file sharded_cache.h.
References GetKiCadThreadPool(), m_shards, PARALLEL_CLEAR_THRESHOLD, Size(), and tp.
|
inline |
Definition at line 95 of file sharded_cache.h.
References m_shards.
|
inline |
Look up a key. Returns false on a miss and leaves aValue untouched.
Definition at line 44 of file sharded_cache.h.
References SHARDED_CACHE< KEY, VALUE, SHARDS >::SHARD::map, SHARDED_CACHE< KEY, VALUE, SHARDS >::SHARD::mutex, shardFor(), and VALUE.
Referenced by enclosedByAreaFunc(), getFieldFunc(), intersectsAreaFunc(), intersectsBackCourtyardFunc(), intersectsCourtyardFunc(), and intersectsFrontCourtyardFunc().
|
inline |
Definition at line 58 of file sharded_cache.h.
References SHARDED_CACHE< KEY, VALUE, SHARDS >::SHARD::map, SHARDED_CACHE< KEY, VALUE, SHARDS >::SHARD::mutex, shardFor(), and VALUE.
Referenced by enclosedByAreaFunc(), getFieldFunc(), intersectsAreaFunc(), intersectsBackCourtyardFunc(), intersectsCourtyardFunc(), intersectsFrontCourtyardFunc(), and DRC_TEST_PROVIDER_DISALLOW::Run().
|
inlineprivate |
Definition at line 132 of file sharded_cache.h.
References m_shards.
|
inlineprivate |
Definition at line 137 of file sharded_cache.h.
References m_shards.
|
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().
|
private |
Definition at line 142 of file sharded_cache.h.
Referenced by Clear(), Empty(), shardFor(), shardFor(), and Size().
|
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().