![]() |
ATLAS Offline Software
|
A set of pointers, allowing concurrent, lockless queries. More...
#include <ConcurrentPtrSet.h>
Classes | |
class | const_iterator |
Iterator class. More... | |
struct | Hasher |
Hash functional for keys. More... | |
struct | Matcher |
Matching functional for keys. More... | |
Public Types | |
using | key_type = VALUE * |
Standard STL types. More... | |
using | const_key_type = const VALUE * |
using | size_type = size_t |
using | Updater_t = typename Impl_t::Updater_t |
Updater object. More... | |
using | Context_t = typename Updater_t::Context_t |
Context type. More... | |
using | Lock_t = typename Impl_t::Lock_t |
Type for external locking. More... | |
using | const_iterator_value = const key_type |
Value type for iterators. More... | |
typedef boost::iterator_range< const_iterator > | const_iterator_range |
A range defined by two iterators. More... | |
Public Member Functions | |
ConcurrentPtrSet (Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext()) | |
Constructor. More... | |
ConcurrentPtrSet (const ConcurrentPtrSet &other, Updater_t &&updater, size_t capacity=64, const Context_t &ctx=Updater_t::defaultContext()) | |
Constructor from another set. More... | |
template<class InputIterator > | |
ConcurrentPtrSet (InputIterator f, InputIterator l, Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext()) | |
Constructor from a range. More... | |
ConcurrentPtrSet (const ConcurrentPtrSet &other)=delete | |
Copy / move / assign not supported. More... | |
ConcurrentPtrSet (ConcurrentPtrSet &&other)=delete | |
ConcurrentPtrSet & | operator= (const ConcurrentPtrSet &other)=delete |
ConcurrentPtrSet & | operator= (ConcurrentPtrSet &&other)=delete |
~ConcurrentPtrSet () | |
Destructor. More... | |
size_type | size () const |
Return the number of items currently in the set. More... | |
bool | empty () const |
Test if the set is currently empty. More... | |
size_t | capacity () const |
Return the current size (capacity) of the hash table. More... | |
const_iterator_range | range () const |
Return an iterator range covering the entire set. More... | |
const_iterator | begin () const |
Iterator at the start of the set. More... | |
const_iterator | end () const |
Iterator at the end of the set. More... | |
const_iterator | cbegin () const |
Iterator at the start of the set. More... | |
const_iterator | cend () const |
Iterator at the end of the set. More... | |
bool | contains (const const_key_type key) const |
Test if a key is in the container. More... | |
size_type | count (const const_key_type key) const |
Return the number of times a given key is in the container. More... | |
const_iterator | find (const const_key_type key) const |
Look up an element in the set. More... | |
std::pair< const_iterator, const_iterator > | equal_range (const const_key_type key) const |
Return a range of iterators with entries matching key . More... | |
Lock_t | lock () |
Take a lock on the container. More... | |
std::pair< const_iterator, bool > | emplace (const key_type key, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the set. More... | |
std::pair< const_iterator, bool > | emplace (const Lock_t &lock, const key_type key, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the set, with external locking. More... | |
std::pair< const_iterator, bool > | insert (const key_type p) |
Add an element to the set. More... | |
template<class InputIterator > | |
void | insert (InputIterator first, InputIterator last) |
Insert a range of elements to the set. More... | |
void | reserve (size_type capacity, const Context_t &ctx=Updater_t::defaultContext()) |
Increase the table capacity. More... | |
void | rehash (size_type capacity) |
Increase the table capacity. More... | |
void | clear (size_t capacity, const Context_t &ctx=Updater_t::defaultContext()) |
Erase the table and change the capacity. More... | |
void | clear (const Context_t &ctx=Updater_t::defaultContext()) |
Erase the table (don't change the capacity). More... | |
void | quiescent (const Context_t &ctx) |
Called when this thread is no longer referencing anything from this container. More... | |
void | swap (ConcurrentPtrSet &other) |
Swap this container with another. More... | |
Updater_t & | updater () |
Access the Updater instance. More... | |
Private Types | |
using | Impl_t = typename detail::ConcurrentHashmapImpl< UPDATER, Hasher, Matcher > |
using | val_t = CxxUtils::detail::ConcurrentHashmapVal_t |
Representation type in the underlying map. More... | |
Private Member Functions | |
Impl_t::const_iterator | get (const const_key_type key) const |
Do a lookup in the table. More... | |
std::pair< const_iterator, bool > | put (const key_type key, const Context_t &ctx=Updater_t::defaultContext()) |
Insert an entry in the table. More... | |
std::pair< const_iterator, bool > | put (const Lock_t &lock, const key_type key, const Context_t &ctx=Updater_t::defaultContext()) |
Insert an entry in the table, with external locking. More... | |
Static Private Member Functions | |
static key_type | keyAsPtr (val_t val) |
Convert an underlying key value to a pointer. More... | |
static val_t | keyAsVal (const const_key_type p) |
Convert a pointer to an underlying key value. More... | |
Private Attributes | |
Impl_t | m_impl |
The underlying hash table. More... | |
A set of pointers, allowing concurrent, lockless queries.
This class implements a set of pointers, allowing for concurrent access from many threads. Queries can proceed without taking out a lock, while insertions are serialized with each other. Thus, this is appropriate for sets which are read-mostly.
This is based on ConcurrentHashmapImpl.
Besides the pointer target type, this class is templated on an UPDATER class, which is used to manage the underlying memory. See IsUpdater.h for details. (AthenaKernel/RCUUpdater is a concrete version that should work in the context of Athena.)
This mostly supports the interface of std::unordered_set, with a few differences / omissions:
Performance: This is the result from running the test with –perf on my machine, with gcc 12.1.1:
ConcurrentPtrSet lookup: 1.225s wall, 1.220s user + 0.000s system = 1.220s CPU (99.6%) iterate: 0.646s wall, 0.640s user + 0.000s system = 0.640s CPU (99.0%) UnorderedSet lookup: 1.894s wall, 1.880s user + 0.000s system = 1.880s CPU (99.3%) iterate: 1.064s wall, 1.060s user + 0.000s system = 1.060s CPU (99.6%) concurrent_unordered_set lookup: 5.369s wall, 5.320s user + 0.000s system = 5.320s CPU (99.1%) iterate: 4.151s wall, 4.130s user + 0.000s system = 4.130s CPU (99.5%) ck_ht lookup: 2.034s wall, 2.020s user + 0.000s system = 2.020s CPU (99.3%) iterate: 1.500s wall, 1.500s user + 0.000s system = 1.500s CPU (100.0%)
The timing for the lookup test of UnorderedSet is probably overly-optimistic, since the test doesn't do any locking in that case.
Definition at line 76 of file ConcurrentPtrSet.h.
typedef boost::iterator_range<const_iterator> CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::const_iterator_range |
A range defined by two iterators.
Definition at line 250 of file ConcurrentPtrSet.h.
using CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::const_iterator_value = const key_type |
Value type for iterators.
Definition at line 181 of file ConcurrentPtrSet.h.
using CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::const_key_type = const VALUE* |
Definition at line 90 of file ConcurrentPtrSet.h.
using CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::Context_t = typename Updater_t::Context_t |
Context type.
Definition at line 95 of file ConcurrentPtrSet.h.
|
private |
Definition at line 82 of file ConcurrentPtrSet.h.
using CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::key_type = VALUE* |
Standard STL types.
Definition at line 89 of file ConcurrentPtrSet.h.
using CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::Lock_t = typename Impl_t::Lock_t |
Type for external locking.
Definition at line 97 of file ConcurrentPtrSet.h.
using CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::size_type = size_t |
Definition at line 91 of file ConcurrentPtrSet.h.
using CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::Updater_t = typename Impl_t::Updater_t |
Updater object.
Definition at line 93 of file ConcurrentPtrSet.h.
|
private |
Representation type in the underlying map.
Definition at line 84 of file ConcurrentPtrSet.h.
CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::ConcurrentPtrSet | ( | Updater_t && | updater, |
size_type | capacity = 64 , |
||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Constructor.
updater | Object used to manage memory (see comments at the start of the class). |
capacity | The initial table capacity. (Will be rounded up to a power of two.) |
ctx | Execution context. |
CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::ConcurrentPtrSet | ( | const ConcurrentPtrSet< VALUE, UPDATER > & | other, |
Updater_t && | updater, | ||
size_t | capacity = 64 , |
||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Constructor from another set.
updater | Object used to manage memory (see comments at the start of the class). |
capacity | The initial table capacity of the new table. (Will be rounded up to a power of two.) |
ctx | Execution context. |
(Not really a copy constructor since we need to pass updater
.)
CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::ConcurrentPtrSet | ( | InputIterator | f, |
InputIterator | l, | ||
Updater_t && | updater, | ||
size_type | capacity = 64 , |
||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Constructor from a range.
f | Start iterator for the range. |
l | End iterator for the range. |
updater | Object used to manage memory (see comments at the start of the class). |
capacity | The initial table capacity of the new table. (Will be rounded up to a power of two.) |
ctx | Execution context. |
|
delete |
Copy / move / assign not supported.
|
delete |
CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::~ConcurrentPtrSet | ( | ) |
Destructor.
const_iterator CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::begin | ( | ) | const |
Iterator at the start of the set.
size_t CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::capacity | ( | ) | const |
Return the current size (capacity) of the hash table.
const_iterator CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::cbegin | ( | ) | const |
Iterator at the start of the set.
const_iterator CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::cend | ( | ) | const |
Iterator at the end of the set.
void CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::clear | ( | const Context_t & | ctx = Updater_t::defaultContext() | ) |
Erase the table (don't change the capacity).
ctx | Execution context. |
void CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::clear | ( | size_t | capacity, |
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Erase the table and change the capacity.
capacity | The new table capacity. |
ctx | Execution context. |
bool CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::contains | ( | const const_key_type | key | ) | const |
Test if a key is in the container.
key | The key to test. |
size_type CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::count | ( | const const_key_type | key | ) | const |
Return the number of times a given key is in the container.
key | The key to test. |
Returns either 0 or 1, depending on whether or not the key is in the set.
std::pair<const_iterator, bool> CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::emplace | ( | const key_type | key, |
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the set.
key | The key of the new item to add. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
std::pair<const_iterator, bool> CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::emplace | ( | const Lock_t & | lock, |
const key_type | key, | ||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the set, with external locking.
lock | The lock object returned from lock(). |
key | The key of the new item to add. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
bool CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::empty | ( | ) | const |
Test if the set is currently empty.
const_iterator CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::end | ( | ) | const |
Iterator at the end of the set.
std::pair<const_iterator, const_iterator> CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::equal_range | ( | const const_key_type | key | ) | const |
Return a range of iterators with entries matching key
.
key | The element to find. |
As keys are unique in this container, this is either a single-element range, or both iterators are equal to end().
const_iterator CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::find | ( | const const_key_type | key | ) | const |
Look up an element in the set.
key | The element to find. |
Returns either an iterator referencing the found element or end().
|
private |
Do a lookup in the table.
key | The key to look up. |
Returns an iterator of the underlying map pointing at the found entry or end();
std::pair<const_iterator, bool> CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::insert | ( | const key_type | p | ) |
Add an element to the set.
p | The item to add. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
This is the same as emplace(). Use that for the case of external locking.
void CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::insert | ( | InputIterator | first, |
InputIterator | last | ||
) |
Insert a range of elements to the set.
first | Start of the range. |
last | End of the range. |
|
staticprivate |
Convert an underlying key value to a pointer.
val | The underlying key value. |
|
staticprivate |
Convert a pointer to an underlying key value.
p | The pointer. |
Lock_t CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::lock | ( | ) |
Take a lock on the container.
Take a lock on the container. The lock can then be passed to insertion methods, allowing to factor out the locking inside loops. The lock will be released when the lock object is destroyed.
|
delete |
|
delete |
|
private |
Insert an entry in the table.
key | The new item to add. |
ctx | Execution context. |
The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
|
private |
void CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::quiescent | ( | const Context_t & | ctx | ) |
Called when this thread is no longer referencing anything from this container.
ctx | Execution context. |
const_iterator_range CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::range | ( | ) | const |
Return an iterator range covering the entire set.
void CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::rehash | ( | size_type | capacity | ) |
Increase the table capacity.
capacity | The new table capacity. |
No action will be taken if capacity
is smaller than the current capacity.
void CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::reserve | ( | size_type | capacity, |
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Increase the table capacity.
capacity | The new table capacity. |
ctx | Execution context. |
No action will be taken if capacity
is smaller than the current capacity.
size_type CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::size | ( | ) | const |
Return the number of items currently in the set.
void CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::swap | ( | ConcurrentPtrSet< VALUE, UPDATER > & | other | ) |
Swap this container with another.
other | The container with which to swap. |
This will also call swap on the Updater object; hence, the Updater object must also support swap.
This operation is NOT thread-safe. No other threads may be accessing either container during this operation.
Updater_t& CxxUtils::ConcurrentPtrSet< VALUE, UPDATER >::updater | ( | ) |
Access the Updater instance.
|
private |
The underlying hash table.
Definition at line 533 of file ConcurrentPtrSet.h.