Jamba C++ API  5.0.0
AtomicValue< T > Class Template Reference

This is the lock free version of the AtomicValue. More...

#include <Concurrent.h>

Inherits SingleElementStorage< T >.

Public Member Functions

 AtomicValue (std::unique_ptr< T > iValue)
 
T const * get ()
 
void get (T &oElement)
 Copy the value to oElement. More...
 
void get (T *oElement)
 Copy the value to *oElement. More...
 
getCopy ()
 
void set (T const &iValue)
 Copy the value to make it accessible to get. More...
 
void set (T const *iValue)
 Copy the value to make it accessible to get. More...
 
template<class ElementModifier >
void update (ElementModifier const &iElementModifier)
 Use this flavor to avoid copy. More...
 
template<class ElementModifier >
bool updateIf (ElementModifier const &iElementModifier)
 Use this flavor to avoid copy. More...
 
- Public Member Functions inherited from SingleElementStorage< T >
bool __isLockFree () const
 Used (from test) to make sure that it is a lock free implementation. More...
 
bool isEmpty () const
 
 SingleElementStorage (std::unique_ptr< T > iElement, bool iIsEmpty) noexcept
 
 ~SingleElementStorage ()
 

Private Types

using Element = typename SingleElementStorage< T >::Element
 

Private Attributes

std::unique_ptr< ElementfGetValue
 
std::unique_ptr< ElementfSetValue
 

Additional Inherited Members

- Protected Member Functions inherited from SingleElementStorage< T >
std::unique_ptr< Element__newElement () const
 
std::unique_ptr< T > __newT () const
 
std::unique_ptr< Elementload (std::unique_ptr< Element > iElement)
 Loads an element from storage. More...
 
std::unique_ptr< Elementstore (std::unique_ptr< Element > iElement)
 Stores an element in the storage. More...
 

Detailed Description

template<typename T>
class pongasoft::Utils::Concurrent::LockFree::AtomicValue< T >

This is the lock free version of the AtomicValue.

Internally it uses a different pointer for get and set. As described in the comment for SingleElementStorage, all methods related to 'get' can be called in one thread while all methods related to 'set' can be called by another.

Member Typedef Documentation

◆ Element

using Element = typename SingleElementStorage<T>::Element
private

Constructor & Destructor Documentation

◆ AtomicValue()

AtomicValue ( std::unique_ptr< T >  iValue)
inlineexplicit

Member Function Documentation

◆ get() [1/3]

T const* get ( )
inline
Returns
the value

◆ get() [2/3]

void get ( T &  oElement)
inline

Copy the value to oElement.

◆ get() [3/3]

void get ( T *  oElement)
inline

Copy the value to *oElement.

◆ getCopy()

T getCopy ( )
inline
Returns
a copy of the value

◆ set() [1/2]

void set ( T const &  iValue)
inline

Copy the value to make it accessible to get.

◆ set() [2/2]

void set ( T const *  iValue)
inline

Copy the value to make it accessible to get.

◆ update()

void update ( ElementModifier const &  iElementModifier)
inline

Use this flavor to avoid copy.

ElementModifier will be called back with the internal pointer to update it.

◆ updateIf()

bool updateIf ( ElementModifier const &  iElementModifier)
inline

Use this flavor to avoid copy.

ElementModifier will be called back with the internal pointer to update it.This flavor uses a callback that returns true when the update should happen and false otherwise.

Member Data Documentation

◆ fGetValue

std::unique_ptr<Element> fGetValue
private

◆ fSetValue

std::unique_ptr<Element> fSetValue
private

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