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-2024 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 # error Code assumes lock-free atomic pointers; see comments below.
23 #endif
24 
25 
26 namespace CxxUtils {
27 
55 template <class T>
57 {
58 public:
60  typedef const T* pointer_t;
61 
62 
65 
66 
69 
70 
72  CachedPointer (const CachedPointer& other) noexcept;
73 
74 
77 
78 
80  void set (pointer_t elt) const;
81 
82 
84  void store (pointer_t elt);
85 
86 
88  pointer_t get() const;
89 
90 
92  const pointer_t* ptr() const;
93 
94 
95 private:
98  mutable std::atomic<pointer_t> m_a;
100 };
101 
102 } // namespace CxxUtils
103 
104 
106 
107 
108 #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:99
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:98
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:60
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:57
CxxUtils::CachedPointer::get
pointer_t get() const
Return the current value of the element.
CxxUtils::CachedPointer::operator=
CachedPointer & operator=(const CachedPointer &other) noexcept
Assignment.
CachedPointer.icc