VolViz
A volume visualization tool
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Public Member Functions | Private Attributes | List of all members
VolViz::AtomicCache< T > Class Template Reference

#include <AtomicCache.h>

+ Collaboration diagram for VolViz::AtomicCache< T >:

Public Member Functions

template<class FetchOp >
 AtomicCache (FetchOp fetchOperation)
 
void markAsDirty () noexcept
 
 operator T const & () const noexcept
 

Private Attributes

value_
 The caced value. More...
 
std::atomic_flag dirtyFlag_
 The atomic dirty flag. More...
 
std::function< T()> const fetchOperation_
 The fetch operation. More...
 

Detailed Description

template<class T>
class VolViz::AtomicCache< T >

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.

Template Parameters
Tthe cached type

Constructor & Destructor Documentation

template<class T>
template<class FetchOp >
VolViz::AtomicCache< T >::AtomicCache ( FetchOp  fetchOperation)
inline

Creates a dirty cache with the given fetch operation.

Template Parameters
FetchOpthe fetch operation. It takes no parameter and returns an object convertible to T.
Note
At construction no fetch operation is issued.

Member Function Documentation

template<class T>
void VolViz::AtomicCache< T >::markAsDirty ( )
inlinenoexcept

Marks the cache as dirty, i.e. a fetch operations must be perfomed on the next read.

Note
this method is thread safe.
template<class T>
VolViz::AtomicCache< T >::operator T const & ( ) const
inlinenoexcept

Returns the cached object. If the cache is dirty, a fetch operations is performed first.

Note
This method must not be called from more than one thread.

Member Data Documentation

template<class T>
std::atomic_flag VolViz::AtomicCache< T >::dirtyFlag_
mutableprivate

The atomic dirty flag.

template<class T>
std::function<T()> const VolViz::AtomicCache< T >::fetchOperation_
private

The fetch operation.

template<class T>
T VolViz::AtomicCache< T >::value_
mutableprivate

The caced value.


The documentation for this class was generated from the following file: