ATLAS Offline Software
CachedPointer.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_CACHEDPOINTER_H
14 #define CXXUTILS_CACHEDPOINTER_H
15 
16 
17 #include <atomic>
18 #include <cassert>
19 
20 
21 #if ATOMIC_POINTER_LOCK_FREE != 2
22 // cppcheck-suppress preprocessorErrorDirective
23 # error Code assumes lock-free atomic pointers; see comments below.
24 #endif
25 
26 
27 namespace CxxUtils {
28 
56 template <class T>
58 {
59 public:
61  typedef const T* pointer_t;
62 
63 
66 
67 
70 
71 
73  CachedPointer (const CachedPointer& other) noexcept;
74 
77 
80 
81 
83  void set (pointer_t elt) const;
84 
85 
87  void store (pointer_t elt);
88 
89 
91  pointer_t get() const;
92 
93 
95  const pointer_t* ptr() const;
96 
97 
98 private:
101  mutable std::atomic<pointer_t> m_a;
103 };
104 
105 
106 } // namespace CxxUtils
107 
108 
110 
111 
112 #endif // not CXXUTILS_CACHEDPOINTER_H
CxxUtils::CachedPointer::CachedPointer
CachedPointer(pointer_t elt)
Constructor from an element.
CxxUtils::CachedPointer::CachedPointer
CachedPointer(const CachedPointer &other) noexcept
Copy constructor.
CxxUtils::CachedPointer::m_e
pointer_t m_e
Transient.
Definition: CachedPointer.h:102
CxxUtils::CachedPointer::CachedPointer
CachedPointer(CachedPointer &&other) noexcept
Move constructor.
CxxUtils::CachedPointer::set
void set(pointer_t elt) const
Set the element, assuming it is currently null.
CxxUtils::CachedPointer::m_a
std::atomic< pointer_t > m_a
The cached element, both directly and as an atomic (recall that this is a union).
Definition: CachedPointer.h:101
CxxUtils::CachedPointer::CachedPointer
CachedPointer()
Default constructor. Sets the element to null.
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::CachedPointer::ptr
const pointer_t * ptr() const
Return a pointer to the cached element.
CxxUtils::CachedPointer::pointer_t
const T * pointer_t
The stored pointer type.
Definition: CachedPointer.h:61
CxxUtils::CachedPointer::operator=
CachedPointer & operator=(const CachedPointer &other)
Assignment.
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CxxUtils::CachedPointer::store
void store(pointer_t elt)
Store a new value to the element.
CxxUtils::CachedPointer
Cached pointer with atomic update.
Definition: CachedPointer.h:58
CxxUtils::CachedPointer::get
pointer_t get() const
Return the current value of the element.
CachedPointer.icc