![]() |
ATLAS Offline Software
|
Cached value with atomic update. More...
#include <CachedValue.h>
Public Member Functions | |
CachedValue () | |
Default constructor. Sets the value to invalid. More... | |
CachedValue (const T &val) | |
Constructor from a value. More... | |
CachedValue (T &&val) noexcept | |
Move constructor from a value. More... | |
CachedValue (const CachedValue &other) | |
Copy constructor. More... | |
CachedValue (CachedValue &&other) noexcept | |
Move constructor. More... | |
template<class U > | |
CachedValue (const CachedValue< U > &other) | |
Copy constructor from other type. More... | |
CachedValue & | operator= (const CachedValue &other) |
Assignment. More... | |
CachedValue & | operator= (CachedValue &&other) noexcept |
Move. More... | |
void | set (const T &val) const |
Set the value, assuming it is currently invalid. More... | |
void | set (T &&val) const noexcept |
Set the value by move, assuming it is currently invalid. More... | |
bool | isValid () const |
Test to see if the value is valid. More... | |
const T * | ptr () const |
Return a pointer to the cached value. More... | |
void | store (const T &val) |
Store a new value. More... | |
void | store (T &&val) noexcept |
Store a new value, by move. More... | |
void | reset () |
Reset the value to invalid. More... | |
Private Attributes | |
T m_val | ATLAS_THREAD_SAFE |
The cached value. More... | |
std::atomic< CacheState > | m_cacheValid |
Transient. More... | |
Friends | |
template<class U > | |
class | CachedValue |
Cached value with atomic update.
Hold a cache of some value. The cache may be set atomically through a const method. This can happen in multiple threads, but the value set should be the same in all threads. The value can be either valid or invalid; it can be set using the set() method. (The value can also be set using the non-const store() method; however, this is not atomic and should not be done while other threads may be accessing the value.) The validity of the value may be tested with isValid(), and ptr() will get back a pointer to the value. ptr() should not be called until isValid() has returned true or set() returned.
The state of the cached value is given by m_cacheState, which can have the values: INVALID: No value has been cached. VALID: The cached value is valid. UPDATING: Some thread is in the process of setting the value.
Definition at line 54 of file CachedValue.h.
CxxUtils::CachedValue< T >::CachedValue | ( | ) |
Default constructor. Sets the value to invalid.
CxxUtils::CachedValue< T >::CachedValue | ( | const T & | val | ) |
Constructor from a value.
|
noexcept |
Move constructor from a value.
CxxUtils::CachedValue< T >::CachedValue | ( | const CachedValue< T > & | other | ) |
Copy constructor.
|
noexcept |
Move constructor.
No concurrent operations on OTHER are possible.
CxxUtils::CachedValue< T >::CachedValue | ( | const CachedValue< U > & | other | ) |
Copy constructor from other type.
bool CxxUtils::CachedValue< T >::isValid | ( | ) | const |
Test to see if the value is valid.
May spin if another thread is currently updating the value.
|
noexcept |
Move.
No concurrent operations on OTHER are possible.
CachedValue& CxxUtils::CachedValue< T >::operator= | ( | const CachedValue< T > & | other | ) |
Assignment.
const T* CxxUtils::CachedValue< T >::ptr | ( | ) | const |
void CxxUtils::CachedValue< T >::reset | ( | ) |
Reset the value to invalid.
void CxxUtils::CachedValue< T >::set | ( | const T & | val | ) | const |
Set the value, assuming it is currently invalid.
Otherwise, this method will do nothing. The value will be valid once this returns.
|
noexcept |
Set the value by move, assuming it is currently invalid.
Otherwise, this method will do nothing. The value will be valid once this returns.
void CxxUtils::CachedValue< T >::store | ( | const T & | val | ) |
Store a new value.
|
noexcept |
Store a new value, by move.
Definition at line 58 of file CachedValue.h.
|
mutableprivate |
The cached value.
Do not return a pointer to this to the user unless the state is VALID.
Definition at line 134 of file CachedValue.h.
|
mutableprivate |
Transient.
Current state of the cached value. INVALID — value has not been set. VALID — value has been set. UPDATING — value is in the process of being set by some thread.
Definition at line 140 of file CachedValue.h.