ATLAS Offline Software
SimpleUpdater.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  */
13 #ifndef CXXUTILS_SIMPLEUPDATER_H
14 #define CXXUTILS_SIMPLEUPDATER_H
15 
16 
17 #include <atomic>
18 #include <vector>
19 #include <memory>
20 #include <algorithm>
21 
22 
23 namespace CxxUtils {
24 
25 
35 template <class T>
37 {
38 public:
41  struct Context_t {};
42 
44  SimpleUpdater() = default;
45 
46 
51 
52 
56  const T& get() const;
57 
58 
67  void update (std::unique_ptr<T> p, const Context_t&);
68 
69 
78  void discard (std::unique_ptr<T> p);
79 
80 
86  void quiescent (const Context_t&);
87 
88 
95  void clean();
96 
97 
106 
107 
111  static const Context_t defaultContext();
112 
113 
114 private:
116  std::atomic<const T*> m_obj = 0;
117 
119  std::vector<std::unique_ptr<T> > m_objs;
120 };
121 
122 
123 } // namespace CxxUtils
124 
125 
127 
128 
129 #endif // not CXXUTILS_SIMPLEUPDATER_H
CxxUtils::SimpleUpdater::SimpleUpdater
SimpleUpdater(SimpleUpdater &&other)
Move constructor.
CxxUtils::SimpleUpdater
Simple (non-deleting) Updater implementation.
Definition: SimpleUpdater.h:37
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
CxxUtils::SimpleUpdater::swap
void swap(SimpleUpdater &other)
Swap this object with another.
CxxUtils::SimpleUpdater::m_objs
std::vector< std::unique_ptr< T > > m_objs
List of all allocated objects.
Definition: SimpleUpdater.h:119
CxxUtils::SimpleUpdater::get
const T & get() const
Return a reference to the current object.
CxxUtils::SimpleUpdater::clean
void clean()
Delete all objects we're managing except for the current one.
CxxUtils::SimpleUpdater::update
void update(std::unique_ptr< T > p, const Context_t &)
Install a new object.
CxxUtils::SimpleUpdater::Context_t
Context object.
Definition: SimpleUpdater.h:41
CxxUtils::SimpleUpdater::SimpleUpdater
SimpleUpdater()=default
We need a default constructor.
CxxUtils
Definition: aligned_vector.h:29
SimpleUpdater.icc
CxxUtils::SimpleUpdater::discard
void discard(std::unique_ptr< T > p)
Queue an object for later deletion.
CxxUtils::SimpleUpdater::m_obj
std::atomic< const T * > m_obj
Pointer to the current object.
Definition: SimpleUpdater.h:116
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CxxUtils::SimpleUpdater::quiescent
void quiescent(const Context_t &)
Mark that an event slot is not referencing this object.
CxxUtils::SimpleUpdater::defaultContext
static const Context_t defaultContext()
Return the current event context.