XII Release 0.1.0
Loading...
Searching...
No Matches
xiiAtomicUtils Struct Reference

This class provides functions to do atomic operations. More...

#include <AtomicUtils.h>

Public Member Functions

template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T Read (const T &ref_value)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T Exchange (T &ref_value, T newValue)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T Increment (T &ref_value)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T Decrement (T &ref_value)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T PostIncrement (T &ref_value)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T PostDecrement (T &ref_value)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T Add (T &ref_value, T addend)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T Subtract (T &ref_value, T subtrahend)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T And (T &ref_value, T operand)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T Or (T &ref_value, T operand)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T Xor (T &ref_value, T operand)
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
XII_ALWAYS_INLINE T CompareExchange (T &ref_value, T expected, T desired)
 

Static Public Member Functions

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T Read (const T &ref_value)
 Reads the atomic value.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T Exchange (T &ref_value, T newValue)
 Atomically exchanges the value and returns the old one.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T Increment (T &ref_value)
 Atomically increments the value and returns the new value.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T Decrement (T &ref_value)
 Atomically decrements the value and returns the new value.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T PostIncrement (T &ref_value)
 Atomically increments the value and returns the original value.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T PostDecrement (T &ref_value)
 Atomically decrements the value and returns the original value.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T Add (T &ref_value, T addend)
 Atomically adds a value to the reference and returns the new value.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T Subtract (T &ref_value, T subtrahend)
 Atomically subtracts a value from the reference and returns the new value.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T And (T &ref_value, T operand)
 Performs an atomic bitwise AND operation.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T Or (T &ref_value, T operand)
 Performs an atomic bitwise OR operation.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T Xor (T &ref_value, T operand)
 Performs an atomic bitwise XOR operation.
 
template<typename T>
requires xii_is_atomic_compatible_v<T>
static T CompareExchange (T &ref_value, T expected, T desired)
 Performs an atomic compare-and-exchange operation.
 
static bool CompareExchangePointer (void **pDestination, void *pExpected, void *pValue)
 

Detailed Description

This class provides functions to do atomic operations.

Atomic operations are generally faster than mutexes, and should therefore be preferred whenever possible. However only the operations in themselves are atomic, once you execute several of them in sequence, the sequence will not be atomic. Also atomic operations are a lot slower than non-atomic operations, thus you should not use them in code that does not need to be thread-safe. xiiAtomicInteger is built on top of xiiAtomicUtils and provides a more convenient interface to use atomic integer instructions.

Member Function Documentation

◆ Add()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::Add ( T & ref_value,
T addend )
static

Atomically adds a value to the reference and returns the new value.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
addend- Value to add.
Returns
The new value after addition.

◆ And()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::And ( T & ref_value,
T operand )
static

Performs an atomic bitwise AND operation.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
operand- Value to AND with.
Returns
The result of the AND operation.

◆ CompareExchange()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::CompareExchange ( T & ref_value,
T expected,
T desired )
static

Performs an atomic compare-and-exchange operation.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
ref_expected- Reference to the expected value.
desired- Value to set if comparison succeeds.
Returns
True if the exchange was performed; false otherwise.

◆ CompareExchangePointer()

XII_ALWAYS_INLINE bool xiiAtomicUtils::CompareExchangePointer ( void ** pDestination,
void * pExpected,
void * pValue )
static
Parameters
pDestination- Pointer to the atomic value.
pExpected- Pointer to the expected value.
pValue- Pointer to the value to set if comparison succeeds.
Returns
True if the exchange was performed; false otherwise.

◆ Decrement()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::Decrement ( T & ref_value)
static

Atomically decrements the value and returns the new value.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
Returns
The new value after decrementing.

◆ Exchange()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::Exchange ( T & ref_value,
T newValue )
static

Atomically exchanges the value and returns the old one.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
newValue- The new value to store.
Returns
The old value before the exchange.

◆ Increment()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::Increment ( T & ref_value)
static

Atomically increments the value and returns the new value.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
Returns
The new value after incrementing.

◆ Or()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::Or ( T & ref_value,
T operand )
static

Performs an atomic bitwise OR operation.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
operand- Value to OR with.
Returns
The result of the OR operation.

◆ PostDecrement()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::PostDecrement ( T & ref_value)
static

Atomically decrements the value and returns the original value.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
Returns
The original value before decrementing.

◆ PostIncrement()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::PostIncrement ( T & ref_value)
static

Atomically increments the value and returns the original value.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
Returns
The original value before incrementing.

◆ Read()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::Read ( const T & ref_value)
static

Reads the atomic value.

Helper variable templates for easier usage

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
Returns
The current value.

◆ Subtract()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::Subtract ( T & ref_value,
T subtrahend )
static

Atomically subtracts a value from the reference and returns the new value.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
subtrahend- Value to subtract.
Returns
The new value after subtraction.

◆ Xor()

template<typename T>
requires xii_is_atomic_compatible_v<T>
static T xiiAtomicUtils::Xor ( T & ref_value,
T operand )
static

Performs an atomic bitwise XOR operation.

Template Parameters
T- Type of the atomic value.
Parameters
ref_value- Reference to the atomic value.
operand- Value to XOR with.
Returns
The result of the XOR operation.

The documentation for this struct was generated from the following files: