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-2025 CERN for the benefit of the ATLAS collaboration.
4  */
14 #include "CxxUtils/IsUpdater.h"
16 #include "boost/iterator/iterator_facade.hpp"
17 #include <type_traits>
18 #include <ranges>
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 requires (detail::IsUpdater<UPDATER>)
76 class ConcurrentPtrSet
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 
108  ConcurrentPtrSet (Updater_t&& updater,
109  size_type capacity = 64,
110  const Context_t& ctx = Updater_t::defaultContext());
111 
112 
123  ConcurrentPtrSet (const ConcurrentPtrSet& other,
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 
148  ConcurrentPtrSet (const ConcurrentPtrSet& other) = delete;
149  ConcurrentPtrSet (ConcurrentPtrSet&& other) = delete;
150  ConcurrentPtrSet& operator= (const ConcurrentPtrSet& other) = delete;
151  ConcurrentPtrSet& operator= (ConcurrentPtrSet&& other) = delete;
152 
153 
157  ~ConcurrentPtrSet();
158 
159 
163  size_type size() const;
164 
165 
169  bool empty() const;
170 
171 
175  size_t capacity() const;
176 
177 
181  using const_iterator_value = const key_type;
182 
183 
193  class const_iterator
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 
241  key_type dereference() const;
242 
243 
245  typename Impl_t::const_iterator m_impl;
246  };
247 
248 
250  using const_iterator_range = CxxUtils::iterator_range<const_iterator>;
251 
252 
256  const_iterator_range range() const;
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 
296  size_type count (const const_key_type key) const;
297 
298 
305  const_iterator find (const const_key_type key) const;
306 
307 
315  std::pair<const_iterator, const_iterator>
316  equal_range (const const_key_type key) const;
317 
318 
327  Lock_t lock();
328 
329 
340  std::pair<const_iterator, bool>
341  emplace (const key_type key,
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 
441  void swap (ConcurrentPtrSet& other);
442 
443 
447  Updater_t& updater();
448 
449 
450 private:
455  static key_type keyAsPtr (val_t val);
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 
533  Impl_t m_impl;
534 };
535 
536 
537 } // namespace CxxUtils
538 
539 
541 
542 
543 #endif // not CXXUTILS_CONCURRENTPTRSET_H
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
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:40
IsUpdater.h
Concept check for Updater class used by concurrent classes.
ConcurrentPtrSet.icc
skel.it
it
Definition: skel.GENtoEVGEN.py:407
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:157
CxxUtils::iterator_range
Simple range from a pair of iterators.
Definition: iterator_range.h:37
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
columnar::operator=
AccessorTemplate & operator=(AccessorTemplate &&that)
Definition: VectorColumn.h:88
CxxUtils::detail::ConcurrentHashmapImpl
Hash table allowing concurrent, lockless reads.
Definition: ConcurrentHashmapImpl.h:200
XMLtoHeader.count
count
Definition: XMLtoHeader.py:84
CxxUtils::fpcompare::equal
bool equal(double a, double b)
Compare two FP numbers, working around x87 precision issues.
Definition: fpcompare.h:114
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
calibdata.valid
list valid
Definition: calibdata.py:44
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
CxxUtils
Definition: aligned_vector.h:29
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
VALUE
#define VALUE(TESTED)
Definition: expect.h:59
hist_file_dump.f
f
Definition: hist_file_dump.py:140
CxxUtils::requires
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
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
iterator_range.h
Simple range from a pair of iterators.
CxxUtils::end
auto end(range_with_at< T > &s)
Definition: range_with_at.h:69
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DeMoScan.first
bool first
Definition: DeMoScan.py:534
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
columnar::operator()
decltype(auto) operator()(ObjectId< CI, CM > id) const noexcept
Definition: ColumnAccessor.h:173
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
CxxUtils::begin
auto begin(range_with_at< T > &s)
Definition: range_with_at.h:65
ConcurrentHashmapImpl.h
Hash table allowing concurrent, lockless reads.