ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
CxxUtils
CxxUtils
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
17
#include "
CxxUtils/checker_macros.h
"
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>
54
class
CachedValue
55
{
56
public
:
57
template
<
class
U>
58
friend
class
CachedValue
;
59
60
62
CachedValue
();
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>
84
CachedValue
(
const
CachedValue<U>
& other);
85
86
88
CachedValue
&
operator=
(
const
CachedValue
& other);
89
90
93
CachedValue
&
operator=
(
CachedValue
&& other)
noexcept
;
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
CachedValue.icc
checker_macros.h
Define macros for attributes used to control the static checker.
CxxUtils::CachedValue::set
void set(T &&val) const noexcept
Set the value by move, assuming it is currently invalid.
CxxUtils::CachedValue::reset
void reset()
Reset the value to invalid.
CxxUtils::CachedValue::CachedValue
CachedValue(const CachedValue &other)
Copy constructor.
CxxUtils::CachedValue::CachedValue
CachedValue(const CachedValue< U > &other)
Copy constructor from other type.
CxxUtils::CachedValue::CachedValue
CachedValue(const T &val)
Constructor from a value.
CxxUtils::CachedValue::ptr
const T * ptr() const
Return a pointer to the cached value.
CxxUtils::CachedValue::set
void set(const T &val) const
Set the value, assuming it is currently invalid.
CxxUtils::CachedValue::CachedValue
friend class CachedValue
Definition
CachedValue.h:58
CxxUtils::CachedValue::store
void store(const T &val)
Store a new value.
CxxUtils::CachedValue::m_cacheValid
std::atomic< CacheState > m_cacheValid
Transient.
Definition
CachedValue.h:140
CxxUtils::CachedValue::isValid
bool isValid() const
Test to see if the value is valid.
CxxUtils::CachedValue::operator=
CachedValue & operator=(const CachedValue &other)
Assignment.
CxxUtils::CachedValue::CachedValue
CachedValue(T &&val) noexcept
Move constructor from a value.
CxxUtils::CachedValue::CachedValue
CachedValue(CachedValue &&other) noexcept
Move constructor.
CxxUtils::CachedValue::ATLAS_THREAD_SAFE
T m_val ATLAS_THREAD_SAFE
The cached value.
Definition
CachedValue.h:134
CxxUtils::CachedValue::CachedValue
CachedValue()
Default constructor. Sets the value to invalid.
CxxUtils::CachedValue::store
void store(T &&val) noexcept
Store a new value, by move.
CxxUtils
Definition
aligned_vector.h:29
CxxUtils::CacheState
CacheState
State of the cached value; see below.
Definition
CachedValue.h:27
CxxUtils::UPDATING
@ UPDATING
Definition
CachedValue.h:29
CxxUtils::INVALID
@ INVALID
Definition
CachedValue.h:28
CxxUtils::VALID
@ VALID
Definition
CachedValue.h:30
stall.h
Emit stall instruction for use in a spin loop.
Generated on
for ATLAS Offline Software by
1.17.0