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 | |
| Atomic & | operator= (const Atomic &)=delete |
| Atomic (Atomic &&)=delete | |
| Atomic & | operator= (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. | |
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.
| T | The value type. Must satisfy std::atomic requirements. |
Constructs an Atomic with the given initial value.
| val | Initial value (default: default-constructed T). |
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.
| expected | Reference to the expected value; updated on failure. |
| desired | The value to store on success. |
Atomically replaces the value and returns the previous one.
| desired | The new value. |
Atomically adds val and returns the previous value.
| val | The value to add. |
Atomically subtracts val and returns the previous value.
| val | The value to subtract. |
Stores a new value with release semantics.
| val | The value to store. |
Loads the current value with acquire semantics.