libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Atomic< T > Class Template Reference

Atomic variable wrapping std::atomic<T>. More...

#include <atomic.h>

Public Member Functions

 Atomic (T val=T{})
 Constructs an Atomic with the given initial value.
 
 ~Atomic ()=default
 Destructor.
 
 Atomic (const Atomic &)=delete
 
Atomicoperator= (const Atomic &)=delete
 
 Atomic (Atomic &&)=delete
 
Atomicoperator= (Atomic &&)=delete
 
T value () const
 Loads the current value with acquire semantics.
 
void setValue (T val)
 Stores a new value with release semantics.
 
T fetchAndAdd (T val)
 Atomically adds val and returns the previous value.
 
T fetchAndSub (T val)
 Atomically subtracts val and returns the previous value.
 
bool compareAndSwap (T &expected, T desired)
 Atomically compares and swaps.
 
T exchange (T desired)
 Atomically replaces the value and returns the previous one.
 

Detailed Description

template<typename T>
class Atomic< T >

Atomic variable wrapping std::atomic<T>.

Provides load/store with acquire/release semantics, atomic arithmetic for integral types, and compare-and-swap. Non-copyable and non-movable.

Template Parameters
TThe value type. Must satisfy std::atomic requirements.

Constructor & Destructor Documentation

◆ Atomic()

template<typename T >
Atomic< T >::Atomic ( T  val = T{})
inline

Constructs an Atomic with the given initial value.

Parameters
valInitial value (default: default-constructed T).

Member Function Documentation

◆ compareAndSwap()

template<typename T >
bool Atomic< T >::compareAndSwap ( T expected,
T  desired 
)
inline

Atomically compares and swaps.

If the current value equals expected, replaces it with desired and returns true. Otherwise, loads the current value into expected and returns false.

Parameters
expectedReference to the expected value; updated on failure.
desiredThe value to store on success.
Returns
True if the swap occurred.

◆ exchange()

template<typename T >
T Atomic< T >::exchange ( T  desired)
inline

Atomically replaces the value and returns the previous one.

Parameters
desiredThe new value.
Returns
The value before the exchange.

◆ fetchAndAdd()

template<typename T >
T Atomic< T >::fetchAndAdd ( T  val)
inline

Atomically adds val and returns the previous value.

Parameters
valThe value to add.
Returns
The value before the addition.
Note
Only available for integral types.

◆ fetchAndSub()

template<typename T >
T Atomic< T >::fetchAndSub ( T  val)
inline

Atomically subtracts val and returns the previous value.

Parameters
valThe value to subtract.
Returns
The value before the subtraction.
Note
Only available for integral types.

◆ setValue()

template<typename T >
void Atomic< T >::setValue ( T  val)
inline

Stores a new value with release semantics.

Parameters
valThe value to store.

◆ value()

template<typename T >
T Atomic< T >::value ( ) const
inline

Loads the current value with acquire semantics.

Returns
The current value.

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