ATLAS Offline Software
ConcurrentPtrSet.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  * Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration.
4  */
14 #include "CxxUtils/concepts.h"
15 #include "CxxUtils/IsUpdater.h"
16 #include "boost/iterator/iterator_facade.hpp"
17 #include "boost/range/iterator_range.hpp"
18 #include <type_traits>
19 
20 
21 #ifndef CXXUTILS_CONCURRENTPTRSET_H
22 #define CXXUTILS_CONCURRENTPTRSET_H
23 
24 
25 namespace CxxUtils {
26 
27 
74 template <class VALUE, template <class> class UPDATER>
75 ATH_REQUIRES (detail::IsUpdater<UPDATER>)
77 {
78 private:
80  struct Hasher;
81  struct Matcher;
85 
86 
87 public:
89  using key_type = VALUE*;
90  using const_key_type = const VALUE*;
91  using size_type = size_t;
93  using Updater_t = typename Impl_t::Updater_t;
95  using Context_t = typename Updater_t::Context_t;
97  using Lock_t = typename Impl_t::Lock_t;
98 
99 
109  size_type capacity = 64,
110  const Context_t& ctx = Updater_t::defaultContext());
111 
112 
124  Updater_t&& updater,
125  size_t capacity = 64,
126  const Context_t& ctx = Updater_t::defaultContext());
127 
128 
139  template <class InputIterator>
140  ConcurrentPtrSet (InputIterator f,
141  InputIterator l,
142  Updater_t&& updater,
143  size_type capacity = 64,
144  const Context_t& ctx = Updater_t::defaultContext());
145 
146 
150  ConcurrentPtrSet& operator= (const ConcurrentPtrSet& other) = delete;
151  ConcurrentPtrSet& operator= (ConcurrentPtrSet&& other) = delete;
152 
153 
158 
159 
163  size_type size() const;
164 
165 
169  bool empty() const;
170 
171 
175  size_t capacity() const;
176 
177 
182 
183 
194  : public boost::iterator_facade<const_iterator,
195  const const_iterator_value,
196  std::bidirectional_iterator_tag,
197  const const_iterator_value>
198  {
199  public:
204  const_iterator (typename Impl_t::const_iterator it);
205 
206 
212  bool valid() const;
213 
214 
215  private:
217  friend class boost::iterator_core_access;
218 
219 
223  void increment();
224 
225 
229  void decrement();
230 
231 
235  bool equal (const const_iterator& other) const;
236 
237 
242 
243 
245  typename Impl_t::const_iterator m_impl;
246  };
247 
248 
250  typedef boost::iterator_range<const_iterator> const_iterator_range;
251 
252 
257 
258 
262  const_iterator begin() const;
263 
264 
268  const_iterator end() const;
269 
270 
274  const_iterator cbegin() const;
275 
276 
280  const_iterator cend() const;
281 
282 
287  bool contains (const const_key_type key) const;
288 
289 
297 
298 
305  const_iterator find (const const_key_type key) const;
306 
307 
315  std::pair<const_iterator, const_iterator>
317 
318 
328 
329 
340  std::pair<const_iterator, bool>
342  const Context_t& ctx = Updater_t::defaultContext());
343 
344 
356  std::pair<const_iterator, bool>
357  emplace (const Lock_t& lock,
358  const key_type key,
359  const Context_t& ctx = Updater_t::defaultContext());
360 
361 
373  std::pair<const_iterator, bool> insert (const key_type p);
374 
375 
381  template <class InputIterator>
382  void insert (InputIterator first, InputIterator last);
383 
384 
393  void reserve (size_type capacity,
394  const Context_t& ctx = Updater_t::defaultContext());
395 
396 
404  void rehash (size_type capacity);
405 
406 
412  void clear (size_t capacity,
413  const Context_t& ctx = Updater_t::defaultContext());
414 
415 
420  void clear (const Context_t& ctx = Updater_t::defaultContext());
421 
422 
428  void quiescent (const Context_t& ctx);
429 
430 
442 
443 
448 
449 
450 private:
456 
457 
462  static val_t keyAsVal (const const_key_type p);
463 
464 
472  typename Impl_t::const_iterator get (const const_key_type key) const;
473 
474 
484  std::pair<const_iterator, bool>
485  put (const key_type key,
486  const Context_t& ctx = Updater_t::defaultContext());
487 
488 
499  std::pair<const_iterator, bool>
500  put (const Lock_t& lock,
501  const key_type key,
502  const Context_t& ctx = Updater_t::defaultContext());
503 
504 
511  struct Hasher
512  {
514  size_t operator() (const val_t p) const;
516  size_t operator() (const const_key_type p) const;
518  std::hash<const_key_type> m_hash;
519  };
520 
521 
525  struct Matcher
526  {
528  bool operator() (const val_t a, const val_t b) const;
529  };
530 
531 
534 };
535 
536 
537 } // namespace CxxUtils
538 
539 
541 
542 
543 #endif // not CXXUTILS_CONCURRENTPTRSET_H
CxxUtils::ConcurrentPtrSet::find
const_iterator find(const const_key_type key) const
Look up an element in the set.
CxxUtils::ConcurrentPtrSet::Matcher
Matching functional for keys.
Definition: ConcurrentPtrSet.h:526
CxxUtils::ConcurrentPtrSet::const_iterator::decrement
void decrement()
iterator_facade requirement: Decrement the iterator.
CxxUtils::ConcurrentPtrSet::Hasher::m_hash
std::hash< const_key_type > m_hash
Hash functional.
Definition: ConcurrentPtrSet.h:518
CxxUtils::ConcurrentPtrSet::ConcurrentPtrSet
ConcurrentPtrSet(Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor.
CxxUtils::ConcurrentPtrSet::const_iterator::const_iterator
const_iterator(typename Impl_t::const_iterator it)
Constructor.
CxxUtils::detail::ConcurrentHashmapVal_t
uintptr_t ConcurrentHashmapVal_t
Type used for keys and values — an unsigned big enough to hold a pointer.
Definition: ConcurrentHashmapImpl.h:41
CxxUtils::ConcurrentPtrSet< CondContBase, CxxUtils::SimpleUpdater >::Impl_t
typename detail::ConcurrentHashmapImpl< CxxUtils::SimpleUpdater, Hasher, Matcher > Impl_t
Definition: ConcurrentPtrSet.h:82
CxxUtils::ConcurrentPtrSet::const_iterator::equal
bool equal(const const_iterator &other) const
iterator_facade requirement: Equality test.
CxxUtils::ConcurrentPtrSet::count
size_type count(const const_key_type key) const
Return the number of times a given key is in the container.
IsUpdater.h
Concept check for Updater class used by concurrent classes.
CxxUtils::ConcurrentPtrSet::const_iterator
Iterator class.
Definition: ConcurrentPtrSet.h:198
CxxUtils::ConcurrentPtrSet< CondContBase, CxxUtils::SimpleUpdater >::val_t
CxxUtils::detail::ConcurrentHashmapVal_t val_t
Representation type in the underlying map.
Definition: ConcurrentPtrSet.h:84
ConcurrentPtrSet.icc
skel.it
it
Definition: skel.GENtoEVGEN.py:396
CxxUtils::ConcurrentPtrSet::size
size_type size() const
Return the number of items currently in the set.
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
CxxUtils::ConcurrentPtrSet::key_type
VALUE * key_type
Standard STL types.
Definition: ConcurrentPtrSet.h:89
CxxUtils::ConcurrentPtrSet::put
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.
CxxUtils::detail::ConcurrentHashmapImpl< UPDATER, Hasher, Matcher >
CxxUtils::ConcurrentPtrSet::capacity
size_t capacity() const
Return the current size (capacity) of the hash table.
CxxUtils::ConcurrentPtrSet< CondContBase, CxxUtils::SimpleUpdater >::Lock_t
typename Impl_t::Lock_t Lock_t
Type for external locking.
Definition: ConcurrentPtrSet.h:97
CxxUtils::ConcurrentPtrSet::ConcurrentPtrSet
ConcurrentPtrSet(const ConcurrentPtrSet &other, Updater_t &&updater, size_t capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor from another set.
CxxUtils::ConcurrentPtrSet::cbegin
const_iterator cbegin() const
Iterator at the start of the set.
CxxUtils::ConcurrentPtrSet::range
const_iterator_range range() const
Return an iterator range covering the entire set.
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
CxxUtils::ConcurrentPtrSet::clear
void clear(const Context_t &ctx=Updater_t::defaultContext())
Erase the table (don't change the capacity).
CxxUtils::ConcurrentPtrSet::reserve
void reserve(size_type capacity, const Context_t &ctx=Updater_t::defaultContext())
Increase the table capacity.
CxxUtils::ConcurrentPtrSet::updater
Updater_t & updater()
Access the Updater instance.
CxxUtils::ConcurrentPtrSet::insert
std::pair< const_iterator, bool > insert(const key_type p)
Add an element to the set.
CxxUtils::ConcurrentPtrSet< CondContBase, CxxUtils::SimpleUpdater >::Updater_t
typename Impl_t::Updater_t Updater_t
Updater object.
Definition: ConcurrentPtrSet.h:93
CxxUtils::ConcurrentPtrSet::keyAsPtr
static key_type keyAsPtr(val_t val)
Convert an underlying key value to a pointer.
CondContBase
Base class for all conditions containers.
Definition: CondCont.h:140
CxxUtils::ConcurrentPtrSet::lock
Lock_t lock()
Take a lock on the container.
CxxUtils::ConcurrentPtrSet::end
const_iterator end() const
Iterator at the end of the set.
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::ConcurrentPtrSet::cend
const_iterator cend() const
Iterator at the end of the set.
CxxUtils::ConcurrentPtrSet::empty
bool empty() const
Test if the set is currently empty.
CxxUtils::ConcurrentPtrSet::ConcurrentPtrSet
ConcurrentPtrSet(const ConcurrentPtrSet &other)=delete
Copy / move / assign not supported.
VALUE
#define VALUE(TESTED)
Definition: expect.h:59
CxxUtils::ConcurrentPtrSet::const_iterator::valid
bool valid() const
Test if this iterator is valid.
CxxUtils::ConcurrentPtrSet::swap
void swap(ConcurrentPtrSet &other)
Swap this container with another.
CxxUtils::ConcurrentPtrSet::get
Impl_t::const_iterator get(const const_key_type key) const
Do a lookup in the table.
hist_file_dump.f
f
Definition: hist_file_dump.py:135
CxxUtils::ConcurrentPtrSet::const_iterator::increment
void increment()
iterator_facade requirement: Increment the iterator.
CxxUtils::ConcurrentPtrSet::begin
const_iterator begin() const
Iterator at the start of the set.
CxxUtils::ConcurrentPtrSet::contains
bool contains(const const_key_type key) const
Test if a key is in the container.
CxxUtils::ConcurrentPtrSet::put
std::pair< const_iterator, bool > put(const key_type key, const Context_t &ctx=Updater_t::defaultContext())
Insert an entry in the table.
CxxUtils::ConcurrentPtrSet::keyAsVal
static val_t keyAsVal(const const_key_type p)
Convert a pointer to an underlying key value.
CxxUtils::ConcurrentPtrSet::const_iterator::dereference
key_type dereference() const
iterator_facade requirement: Dereference the iterator.
CxxUtils::ConcurrentPtrSet::const_iterator::m_impl
Impl_t::const_iterator m_impl
The iterator on the underlying table.
Definition: ConcurrentPtrSet.h:245
CxxUtils::ConcurrentPtrSet
A set of pointers, allowing concurrent, lockless queries.
Definition: ConcurrentPtrSet.h:77
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CxxUtils::ConcurrentPtrSet::Hasher
Hash functional for keys.
Definition: ConcurrentPtrSet.h:512
CxxUtils::ConcurrentPtrSet::emplace
std::pair< const_iterator, bool > emplace(const key_type key, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the set.
CxxUtils::ConcurrentPtrSet::m_impl
Impl_t m_impl
The underlying hash table.
Definition: ConcurrentPtrSet.h:533
concepts.h
Compatibility helpers for using some pieces of C++20 concepts with older compilers.
CxxUtils::ConcurrentPtrSet< CondContBase, CxxUtils::SimpleUpdater >::Context_t
typename Updater_t::Context_t Context_t
Context type.
Definition: ConcurrentPtrSet.h:95
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CxxUtils::ConcurrentPtrSet::equal_range
std::pair< const_iterator, const_iterator > equal_range(const const_key_type key) const
Return a range of iterators with entries matching key.
CxxUtils::ConcurrentPtrSet::insert
void insert(InputIterator first, InputIterator last)
Insert a range of elements to the set.
DeMoScan.first
bool first
Definition: DeMoScan.py:536
CxxUtils::ConcurrentPtrSet::~ConcurrentPtrSet
~ConcurrentPtrSet()
Destructor.
CxxUtils::ConcurrentPtrSet< CondContBase, CxxUtils::SimpleUpdater >::size_type
size_t size_type
Definition: ConcurrentPtrSet.h:91
CxxUtils::ATH_REQUIRES
ATH_REQUIRES(detail::IsConcurrentHashmapPayload< KEY > &&detail::IsConcurrentHashmapPayload< VALUE > &&detail::IsUpdater< UPDATER > &&detail::IsHash< HASHER, KEY > &&detail::IsBinaryPredicate< MATCHER, KEY >) class ConcurrentMap
Hash map from integers/pointers allowing concurrent, lockless reads.
Definition: ConcurrentMap.h:94
CxxUtils::ConcurrentPtrSet::clear
void clear(size_t capacity, const Context_t &ctx=Updater_t::defaultContext())
Erase the table and change the capacity.
CxxUtils::ConcurrentPtrSet::const_key_type
const VALUE * const_key_type
Definition: ConcurrentPtrSet.h:90
CxxUtils::ConcurrentPtrSet::emplace
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.
CxxUtils::ConcurrentPtrSet::rehash
void rehash(size_type capacity)
Increase the table capacity.
CxxUtils::ConcurrentPtrSet::quiescent
void quiescent(const Context_t &ctx)
Called when this thread is no longer referencing anything from this container.
CxxUtils::ConcurrentPtrSet::const_iterator_range
boost::iterator_range< const_iterator > const_iterator_range
A range defined by two iterators.
Definition: ConcurrentPtrSet.h:250
CxxUtils::ConcurrentPtrSet::ConcurrentPtrSet
ConcurrentPtrSet(InputIterator f, InputIterator l, Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext())
Constructor from a range.
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
CxxUtils::ConcurrentPtrSet::ConcurrentPtrSet
ConcurrentPtrSet(ConcurrentPtrSet &&other)=delete
ConcurrentHashmapImpl.h
Hash table allowing concurrent, lockless reads.