VolViz
A volume visualization tool
|
#include <AtomicCache.h>
Public Member Functions | |
template<class FetchOp > | |
AtomicCache (FetchOp fetchOperation) | |
void | markAsDirty () noexcept |
operator T const & () const noexcept | |
Private Attributes | |
T | value_ |
The caced value. More... | |
std::atomic_flag | dirtyFlag_ |
The atomic dirty flag. More... | |
std::function< T()> const | fetchOperation_ |
The fetch operation. More... | |
Class represening a cached value, that has a very basic thread safety. The thread saftey is as follows: the cache'd value must not be accessed from different threads (at least without external synchronization), but the cache can be marked dirty from any thread. A typical use case is to cache a derived property that depends on some shared (beween threads) resources (e.g. AtomicWrapper<> objects) and the cached value is frequently accessed but the dependent resource does not change so often.
T | the cached type |
|
inline |
Creates a dirty cache with the given fetch operation.
FetchOp | the fetch operation. It takes no parameter and returns an object convertible to T. |
|
inlinenoexcept |
Marks the cache as dirty, i.e. a fetch operations must be perfomed on the next read.
|
inlinenoexcept |
Returns the cached object. If the cache is dirty, a fetch operations is performed first.
|
mutableprivate |
The atomic dirty flag.
|
private |
The fetch operation.
|
mutableprivate |
The caced value.