ATLAS Offline Software
Loading...
Searching...
No Matches
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*/
11
12
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
23namespace CxxUtils {
24
25
27enum CacheState : unsigned char {
31};
32
33
53template <class T>
55{
56public:
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
74 CachedValue (const CachedValue& other);
75
76
79 CachedValue (CachedValue&& other) noexcept;
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
131private:
134 mutable T m_val ATLAS_THREAD_SAFE;
135
140 mutable std::atomic<CacheState> m_cacheValid;
141};
142
143
144} // namespace CxxUtils
145
146
148
149
150#endif // not CXXUTILS_CACHEDVALUE_H
Define macros for attributes used to control the static checker.
void set(T &&val) const noexcept
Set the value by move, assuming it is currently invalid.
void reset()
Reset the value to invalid.
CachedValue(const CachedValue &other)
Copy constructor.
CachedValue(const CachedValue< U > &other)
Copy constructor from other type.
CachedValue(const T &val)
Constructor from a value.
const T * ptr() const
Return a pointer to the cached value.
void set(const T &val) const
Set the value, assuming it is currently invalid.
friend class CachedValue
Definition CachedValue.h:58
void store(const T &val)
Store a new value.
std::atomic< CacheState > m_cacheValid
Transient.
bool isValid() const
Test to see if the value is valid.
CachedValue & operator=(const CachedValue &other)
Assignment.
CachedValue(T &&val) noexcept
Move constructor from a value.
CachedValue(CachedValue &&other) noexcept
Move constructor.
T m_val ATLAS_THREAD_SAFE
The cached value.
CachedValue()
Default constructor. Sets the value to invalid.
void store(T &&val) noexcept
Store a new value, by move.
CacheState
State of the cached value; see below.
Definition CachedValue.h:27
Emit stall instruction for use in a spin loop.