AtomicFloatType< T > Class Template Reference

#include <atomictypes.h>

Detailed Description

template<typename T>
class maxon::AtomicFloatType< T >

Atomic float template. Since floating point loads and stores are not atomic the template uses integers loads and stores and then safely reinterprets them as floats.

Public Types

using ValueType = T
 
using IntT = typename IntType< SIZEOF(T)>::type
 
using AtomicType = typename std::conditional< SIZEOF(T)==4, Atomic32< Int32 >, Atomic64< Int64 > >::type
 

Public Member Functions

MAXON_IMPLICIT AtomicFloatType (T value=T())
 
Get () const
 
void Set (T newValue)
 
Load () const
 
void Store (T newValue)
 
LoadRelaxed () const
 
void StoreRelaxed (T newValue)
 
LoadAcquire () const
 
void StoreRelease (T &newValue)
 
Bool TryCompareAndSwap (const T &newValue, const T &compare)
 
Swap (T &newValue)
 
SwapAdd (T add)
 

Private Member Functions

 MAXON_DISALLOW_COPY_AND_ASSIGN (AtomicFloatType)
 

Private Attributes

AtomicType _value
 

Member Typedef Documentation

◆ ValueType

using ValueType = T

◆ IntT

using IntT = typename IntType<SIZEOF(T)>::type

◆ AtomicType

using AtomicType = typename std::conditional<SIZEOF(T) == 4, Atomic32<Int32>, Atomic64<Int64> >::type

Constructor & Destructor Documentation

◆ AtomicFloatType()

MAXON_IMPLICIT AtomicFloatType ( value = T())

Member Function Documentation

◆ MAXON_DISALLOW_COPY_AND_ASSIGN()

MAXON_DISALLOW_COPY_AND_ASSIGN ( AtomicFloatType< T >  )
private

◆ Get()

T Get ( ) const

Default routine to get an atomic value. It is identical to Load() with sequentially consistent memory order. Other routines might deliver improved performance.

Returns
Read memory location content.

◆ Set()

void Set ( newValue)

Default routine to set an atomic value. It is identical to Store() with sequentially consistent memory order. Other routines might deliver improved performance.

Parameters
[in]newValueValue to be stored.

◆ Load()

T Load ( ) const

Atomic load with sequentially consistent memory order.

Returns
Read memory location content.

◆ Store()

void Store ( newValue)

Atomic store with sequentially consistent memory order.

Parameters
[in]newValueValue to be stored.

◆ LoadRelaxed()

T LoadRelaxed ( ) const

Atomic load with relaxed memory order. This load is completely unordered (might be prefetched). You should only use it within the same thread when guarded with preceding acquire load or a fence. Fences are implicitly created by TryCompareAndSwap, Swap, SwapAdd, SwapIncrement, SwapDecrement and by locks.

Returns
Read memory location content.

◆ StoreRelaxed()

void StoreRelaxed ( newValue)

Atomic store with relaxed memory order. This store is completely unordered. You should only use it within the same thread when guarded by a following release store or a fence.

Parameters
[in]newValueValue to be stored.

◆ LoadAcquire()

T LoadAcquire ( ) const

Atomic load with acquire memory order. If another thread has released a store on this location it is guaranteed that after a load with acquire memory order all following loads will see the (relaxed) stores that preceded the release. Furthermore subsequent loads or stores will not be speculatively executed before this load. This is equivalent to a relaxed load followed by a MemoryFenceAcquire().

Returns
Read memory location content.

◆ StoreRelease()

void StoreRelease ( T &  newValue)

Atomic store with release memory order. As soon as another thread reads on this location using LoadAcquire() and obtains the stored value it is guaranteed that all prior (relaxed) stores are visible to it. This is equivalent to a MemoryFenceRelease() followed by a relaxed store.

Parameters
[in]newValueValue to be stored.

◆ TryCompareAndSwap()

Bool TryCompareAndSwap ( const T &  newValue,
const T &  compare 
)

Atomic compare and swap with sequentially consistent memory order. If the previous memory location value equals compare newValue is written to the memory location and true is returned. If the memory location contained a different value it is not changed and false will be returned. If the value is exchanged this call enforces a sequentially consistent memory order which means that it might require potentially expensive synchronization between the CPUs.

Parameters
[in]newValueValue to be stored if memory location contains compare.
[in]compareValue to compare with memory location.
Returns
True if the memory value was exchanged.

◆ Swap()

T Swap ( T &  newValue)

Atomic swap with sequentially consistent memory order. Exchanges the value of the memory location with newValue and returns the previous value. This call enforces a sequentially consistent memory order which means that it might require potentially expensive synchronization between the CPUs.

Parameters
[in]newValueValue to be stored.
Returns
Previous value of the memory location.

◆ SwapAdd()

T SwapAdd ( add)

Atomic add with sequentially consistent memory order. Adds the specified value to the memory location and returns the previous value. This call enforces a sequentially consistent memory order which means that it might require potentially expensive synchronization between the CPUs.

Parameters
[in]addValue to be added.
Returns
Previous value of the memory location.

Member Data Documentation

◆ _value

AtomicType _value
private