ATLAS Offline Software
CachedValue.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_CACHEDVALUE_H
14 #define CXXUTILS_CACHEDVALUE_H
15 
16 
18 #include "CxxUtils/stall.h"
19 #include <atomic>
20 #include <utility>
21 
22 
23 namespace CxxUtils {
24 
25 
27 enum CacheState : unsigned char {
28  INVALID = 0,
29  UPDATING = 1,
30  VALID = 2
31 };
32 
33 
53 template <class T>
55 {
56 public:
57  template <class U>
58  friend class CachedValue;
59 
60 
63 
64 
66  CachedValue (const T& val);
67 
68 
70  CachedValue (T&& val) noexcept;
71 
72 
75 
76 
80 
81 
83  template <class U>
85 
86 
89 
90 
94 
95 
99  void set (const T& val) const;
100 
101 
105  void set (T&& val) const noexcept;
106 
107 
110  bool isValid() const;
111 
112 
116  const T* ptr() const;
117 
118 
120  void store (const T& val);
121 
122 
124  void store (T&& val) noexcept;
125 
126 
128  void reset();
129 
130 
131 private:
134  mutable T m_val ATLAS_THREAD_SAFE;
135 
140  mutable std::atomic<CacheState> m_cacheValid;
141 };
142 
143 
144 } // namespace CxxUtils
145 
146 
147 #include "CxxUtils/CachedValue.icc"
148 
149 
150 #endif // not CXXUTILS_CACHEDVALUE_H
CxxUtils::CachedValue::CachedValue
CachedValue(T &&val) noexcept
Move constructor from a value.
CxxUtils::VALID
@ VALID
Definition: CachedValue.h:30
CxxUtils::CachedValue::reset
void reset()
Reset the value to invalid.
CxxUtils::UPDATING
@ UPDATING
Definition: CachedValue.h:29
CxxUtils::CachedValue::ptr
const T * ptr() const
Return a pointer to the cached value.
CxxUtils::CachedValue::set
void set(T &&val) const noexcept
Set the value by move, assuming it is currently invalid.
CxxUtils::CachedValue::isValid
bool isValid() const
Test to see if the value is valid.
CxxUtils::CachedValue::store
void store(T &&val) noexcept
Store a new value, by move.
CxxUtils::CachedValue::CachedValue
CachedValue(const CachedValue &other)
Copy constructor.
CachedValue.icc
CxxUtils::INVALID
@ INVALID
Definition: CachedValue.h:28
CxxUtils::CachedValue::store
void store(const T &val)
Store a new value.
CxxUtils::CachedValue::CachedValue
CachedValue(CachedValue &&other) noexcept
Move constructor.
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::CachedValue
Cached value with atomic update.
Definition: CachedValue.h:55
CxxUtils::CachedValue::CachedValue
CachedValue(const T &val)
Constructor from a value.
CxxUtils::CachedValue::CachedValue
CachedValue()
Default constructor. Sets the value to invalid.
stall.h
Emit stall instruction for use in a spin loop.
CxxUtils::CachedValue::m_cacheValid
std::atomic< CacheState > m_cacheValid
Transient.
Definition: CachedValue.h:140
CxxUtils::CacheState
CacheState
State of the cached value; see below.
Definition: CachedValue.h:27
CxxUtils::CachedValue::CachedValue
CachedValue(const CachedValue< U > &other)
Copy constructor from other type.
CxxUtils::CachedValue::set
void set(const T &val) const
Set the value, assuming it is currently invalid.
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CxxUtils::CachedValue::operator=
CachedValue & operator=(const CachedValue &other)
Assignment.
CxxUtils::CachedValue::ATLAS_THREAD_SAFE
T m_val ATLAS_THREAD_SAFE
The cached value.
Definition: CachedValue.h:134
checker_macros.h
Define macros for attributes used to control the static checker.
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35