Krita Source Code Documentation
Loading...
Searching...
No Matches
ConcurrentMap< K, V, KT, VT > Class Template Reference

#include <concurrent_map.h>

Classes

class  Iterator
 
class  Mutator
 

Public Types

typedef Leapfrog< ConcurrentMapDetails
 
typedef quint32 Hash
 
typedef K Key
 
typedef KT KeyTraits
 
typedef V Value
 
typedef VT ValueTraits
 

Public Member Functions

Value assign (Key key, Value desired)
 
 ConcurrentMap (quint64 capacity=Details::InitialSize)
 
Value erase (Key key)
 
Value exchange (Key key, Value desired)
 
Mutator find (Key key)
 
Value get (Key key)
 
QSBRgetGC ()
 
Mutator insertOrFind (Key key)
 
bool migrationInProcess ()
 
void publishTableMigration (typename Details::TableMigration *migration)
 
 ~ConcurrentMap ()
 

Private Attributes

QSBR m_gc
 
Atomic< typename Details::Table * > m_root
 

Detailed Description

template<typename K, typename V, class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
class ConcurrentMap< K, V, KT, VT >

Definition at line 18 of file concurrent_map.h.

Member Typedef Documentation

◆ Details

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
typedef Leapfrog<ConcurrentMap> ConcurrentMap< K, V, KT, VT >::Details

Definition at line 26 of file concurrent_map.h.

◆ Hash

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
typedef quint32 ConcurrentMap< K, V, KT, VT >::Hash

Definition at line 25 of file concurrent_map.h.

◆ Key

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
typedef K ConcurrentMap< K, V, KT, VT >::Key

Definition at line 21 of file concurrent_map.h.

◆ KeyTraits

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
typedef KT ConcurrentMap< K, V, KT, VT >::KeyTraits

Definition at line 23 of file concurrent_map.h.

◆ Value

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
typedef V ConcurrentMap< K, V, KT, VT >::Value

Definition at line 22 of file concurrent_map.h.

◆ ValueTraits

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
typedef VT ConcurrentMap< K, V, KT, VT >::ValueTraits

Definition at line 24 of file concurrent_map.h.

Constructor & Destructor Documentation

◆ ConcurrentMap()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
ConcurrentMap< K, V, KT, VT >::ConcurrentMap ( quint64 capacity = Details::InitialSize)
inline

Definition at line 33 of file concurrent_map.h.

33 : m_root(Details::Table::create(capacity))
34 {
35 }
Atomic< typename Details::Table * > m_root

◆ ~ConcurrentMap()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
ConcurrentMap< K, V, KT, VT >::~ConcurrentMap ( )
inline

Definition at line 37 of file concurrent_map.h.

38 {
39 typename Details::Table* table = m_root.loadNonatomic();
40 table->destroy();
41 m_gc.flush();
42 }
void flush()
Definition qsbr.h:99

References Leapfrog< Map >::Table::destroy(), QSBR::flush(), ConcurrentMap< K, V, KT, VT >::m_gc, and ConcurrentMap< K, V, KT, VT >::m_root.

Member Function Documentation

◆ assign()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Value ConcurrentMap< K, V, KT, VT >::assign ( Key key,
Value desired )
inline

Definition at line 279 of file concurrent_map.h.

280 {
281 Mutator iter(*this, key);
282 return iter.exchangeValue(desired);
283 }

References ConcurrentMap< K, V, KT, VT >::Mutator::exchangeValue().

◆ erase()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Value ConcurrentMap< K, V, KT, VT >::erase ( Key key)
inline

Definition at line 291 of file concurrent_map.h.

292 {
293 Mutator iter(*this, key, false);
294 return iter.eraseValue();
295 }

References ConcurrentMap< K, V, KT, VT >::Mutator::eraseValue().

◆ exchange()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Value ConcurrentMap< K, V, KT, VT >::exchange ( Key key,
Value desired )
inline

Definition at line 285 of file concurrent_map.h.

286 {
287 Mutator iter(*this, key);
288 return iter.exchangeValue(desired);
289 }

References ConcurrentMap< K, V, KT, VT >::Mutator::exchangeValue().

◆ find()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Mutator ConcurrentMap< K, V, KT, VT >::find ( Key key)
inline

Definition at line 253 of file concurrent_map.h.

254 {
255 return Mutator(*this, key, false);
256 }

◆ get()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Value ConcurrentMap< K, V, KT, VT >::get ( Key key)
inline

Definition at line 259 of file concurrent_map.h.

260 {
261 Hash hash = KeyTraits::hash(key);
262 for (;;) {
263 typename Details::Table* table = m_root.load(Consume);
264 typename Details::Cell* cell = Details::find(hash, table);
265 if (!cell) {
266 return Value(ValueTraits::NullValue);
267 }
268
269 Value value = cell->value.load(Consume);
270 if (value != Value(ValueTraits::Redirect)) {
271 return value; // Found an existing value
272 }
273 // We've been redirected to a new table. Help with the migration.
274 table->jobCoordinator.participate();
275 // Try again in the new table.
276 }
277 }
float value(const T *src, size_t ch)
@ Consume
Definition atomic.h:58
static Cell * find(Hash hash, Table *table)
Definition leapfrog.h:157
union Value::@1 value

References Consume, Leapfrog< Map >::find(), Leapfrog< Map >::Table::jobCoordinator, Atomic< T >::load(), ConcurrentMap< K, V, KT, VT >::m_root, SimpleJobCoordinator::participate(), Leapfrog< Map >::Cell::value, and value().

◆ getGC()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
QSBR & ConcurrentMap< K, V, KT, VT >::getGC ( )
inline

Definition at line 44 of file concurrent_map.h.

45 {
46 return m_gc;
47 }

References ConcurrentMap< K, V, KT, VT >::m_gc.

◆ insertOrFind()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Mutator ConcurrentMap< K, V, KT, VT >::insertOrFind ( Key key)
inline

Definition at line 248 of file concurrent_map.h.

249 {
250 return Mutator(*this, key);
251 }

◆ migrationInProcess()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
bool ConcurrentMap< K, V, KT, VT >::migrationInProcess ( )
inline

Definition at line 49 of file concurrent_map.h.

50 {
51 return quint64(m_root.loadNonatomic()->jobCoordinator.loadConsume()) > 1;
52 }

References ConcurrentMap< K, V, KT, VT >::m_root.

◆ publishTableMigration()

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
void ConcurrentMap< K, V, KT, VT >::publishTableMigration ( typename Details::TableMigration * migration)
inline

Definition at line 56 of file concurrent_map.h.

57 {
58 m_root.store(migration->m_destination, Release);
59 // Caller will GC the TableMigration and the source table.
60 }
@ Release
Definition atomic.h:60

References Leapfrog< Map >::TableMigration::m_destination, ConcurrentMap< K, V, KT, VT >::m_root, and Release.

Member Data Documentation

◆ m_gc

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
QSBR ConcurrentMap< K, V, KT, VT >::m_gc
private

Definition at line 30 of file concurrent_map.h.

◆ m_root

template<typename K , typename V , class KT = DefaultKeyTraits<K>, class VT = DefaultValueTraits<V>>
Atomic<typename Details::Table*> ConcurrentMap< K, V, KT, VT >::m_root
private

Definition at line 29 of file concurrent_map.h.


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