LMMS
Loading...
Searching...
No Matches
water::Atomic< Type > Class Template Reference

#include <Atomic.h>

Public Member Functions

 Atomic () noexcept
 Atomic (const Type initialValue) noexcept
 Atomic (const Atomic &other) noexcept
 ~Atomic () noexcept
Type get () const noexcept
Atomicoperator= (const Atomic &other) noexcept
Atomicoperator= (const Type newValue) noexcept
void set (Type newValue) noexcept
Type exchange (Type value) noexcept
Type operator+= (Type amountToAdd) noexcept
Type operator-= (Type amountToSubtract) noexcept
Type operator++ () noexcept
Type operator-- () noexcept
bool compareAndSetBool (Type newValue, Type valueToCompare) noexcept
Type compareAndSetValue (Type newValue, Type valueToCompare) noexcept
 __attribute__ ((aligned(WATER_ALIGN_SIZE))) mutable volatile Type value
int32 get () const noexcept
uint32 get () const noexcept
int64 get () const noexcept
uint64 get () const noexcept

Static Public Member Functions

static void memoryBarrier () noexcept

Private Member Functions

Type operator++ (int)
Type operator-- (int)
template<typename ValueType>
ValueType negateValue (ValueType n) noexcept
template<typename PointerType>
PointerType * negateValue (PointerType *n) noexcept

Static Private Member Functions

template<typename Dest, typename Source>
static Dest castTo (Source value) noexcept
static Type castFrom32Bit (int32 value) noexcept
static Type castFrom64Bit (int64 value) noexcept
static Type castFrom32Bit (uint32 value) noexcept
static Type castFrom64Bit (uint64 value) noexcept
static Type castFromLong (long value) noexcept
static int32 castTo32Bit (Type value) noexcept
static int64 castTo64Bit (Type value) noexcept
static long castToLong (Type value) noexcept

Detailed Description

template<typename Type>
class water::Atomic< Type >

Simple class to hold a primitive value and perform atomic operations on it.

The type used must be a 32 or 64 bit primitive, like an int, pointer, etc. There are methods to perform most of the basic atomic operations.

Constructor & Destructor Documentation

◆ Atomic() [1/3]

template<typename Type>
water::Atomic< Type >::Atomic ( )
inlinenoexcept

Creates a new value, initialised to zero.

◆ Atomic() [2/3]

template<typename Type>
water::Atomic< Type >::Atomic ( const Type initialValue)
inlineexplicitnoexcept

Creates a new value, with a given initial value.

◆ Atomic() [3/3]

template<typename Type>
water::Atomic< Type >::Atomic ( const Atomic< Type > & other)
inlinenoexcept

Copies another value (atomically).

◆ ~Atomic()

template<typename Type>
water::Atomic< Type >::~Atomic ( )
inlinenoexcept

Destructor.

Member Function Documentation

◆ __attribute__()

template<typename Type>
water::Atomic< Type >::__attribute__ ( (aligned(WATER_ALIGN_SIZE)) ) volatile

The raw value that this class operates on. This is exposed publicly in case you need to manipulate it directly for performance reasons.

◆ castFrom32Bit() [1/2]

template<typename Type>
Type water::Atomic< Type >::castFrom32Bit ( int32 value)
inlinestaticprivatenoexcept

◆ castFrom32Bit() [2/2]

template<typename Type>
Type water::Atomic< Type >::castFrom32Bit ( uint32 value)
inlinestaticprivatenoexcept

◆ castFrom64Bit() [1/2]

template<typename Type>
Type water::Atomic< Type >::castFrom64Bit ( int64 value)
inlinestaticprivatenoexcept

◆ castFrom64Bit() [2/2]

template<typename Type>
Type water::Atomic< Type >::castFrom64Bit ( uint64 value)
inlinestaticprivatenoexcept

◆ castFromLong()

template<typename Type>
Type water::Atomic< Type >::castFromLong ( long value)
inlinestaticprivatenoexcept

◆ castTo()

template<typename Type>
template<typename Dest, typename Source>
Dest water::Atomic< Type >::castTo ( Source value)
inlinestaticprivatenoexcept

◆ castTo32Bit()

template<typename Type>
int32 water::Atomic< Type >::castTo32Bit ( Type value)
inlinestaticprivatenoexcept

◆ castTo64Bit()

template<typename Type>
int64 water::Atomic< Type >::castTo64Bit ( Type value)
inlinestaticprivatenoexcept

◆ castToLong()

template<typename Type>
long water::Atomic< Type >::castToLong ( Type value)
inlinestaticprivatenoexcept

◆ compareAndSetBool()

template<typename Type>
bool water::Atomic< Type >::compareAndSetBool ( Type newValue,
Type valueToCompare )
inlinenoexcept

Atomically compares this value with a target value, and if it is equal, sets this to be equal to a new value.

This operation is the atomic equivalent of doing this:

bool compareAndSetBool (Type newValue, Type valueToCompare)
{
if (get() == valueToCompare)
{
set (newValue);
return true;
}
return false;
}
void set(Type newValue) noexcept
Definition Atomic.h:134
bool compareAndSetBool(Type newValue, Type valueToCompare) noexcept
Definition Atomic.h:445
Type get() const noexcept
Returns
true if the comparison was true and the value was replaced; false if the comparison failed and the value was left unchanged.
See also
compareAndSetValue

◆ compareAndSetValue()

template<typename Type>
Type water::Atomic< Type >::compareAndSetValue ( Type newValue,
Type valueToCompare )
inlinenoexcept

Atomically compares this value with a target value, and if it is equal, sets this to be equal to a new value.

This operation is the atomic equivalent of doing this:

Type compareAndSetValue (Type newValue, Type valueToCompare)
{
Type oldValue = get();
if (oldValue == valueToCompare)
set (newValue);
return oldValue;
}
Type compareAndSetValue(Type newValue, Type valueToCompare) noexcept
Definition Atomic.h:456
Returns
the old value before it was changed.
See also
compareAndSetBool

◆ exchange()

template<typename Type>
Type water::Atomic< Type >::exchange ( Type value)
inlinenoexcept

Atomically sets the current value, returning the value that was replaced.

◆ get() [1/5]

uint64 water::Atomic< uint64 >::get ( ) const
inlinenoexcept

◆ get() [2/5]

int64 water::Atomic< int64 >::get ( ) const
inlinenoexcept

◆ get() [3/5]

uint32 water::Atomic< uint32 >::get ( ) const
inlinenoexcept

◆ get() [4/5]

int32 water::Atomic< int32 >::get ( ) const
inlinenoexcept

◆ get() [5/5]

template<typename Type>
Type water::Atomic< Type >::get ( ) const
noexcept

Atomically reads and returns the current value.

◆ memoryBarrier()

template<typename Type>
void water::Atomic< Type >::memoryBarrier ( )
inlinestaticnoexcept

Implements a memory read/write barrier.

◆ negateValue() [1/2]

template<typename Type>
template<typename PointerType>
PointerType * water::Atomic< Type >::negateValue ( PointerType * n)
inlineprivatenoexcept

This templated negate function will negate pointers as well as integers

◆ negateValue() [2/2]

template<typename Type>
template<typename ValueType>
ValueType water::Atomic< Type >::negateValue ( ValueType n)
inlineprivatenoexcept

This templated negate function will negate pointers as well as integers

◆ operator++() [1/2]

template<typename Type>
Type water::Atomic< Type >::operator++ ( )
inlinenoexcept

Atomically increments this value, returning the new value.

◆ operator++() [2/2]

template<typename Type>
Type water::Atomic< Type >::operator++ ( int )
private

◆ operator+=()

template<typename Type>
Type water::Atomic< Type >::operator+= ( Type amountToAdd)
inlinenoexcept

Atomically adds a number to this value, returning the new value.

◆ operator--() [1/2]

template<typename Type>
Type water::Atomic< Type >::operator-- ( )
inlinenoexcept

Atomically decrements this value, returning the new value.

◆ operator--() [2/2]

template<typename Type>
Type water::Atomic< Type >::operator-- ( int )
private

◆ operator-=()

template<typename Type>
Type water::Atomic< Type >::operator-= ( Type amountToSubtract)
inlinenoexcept

Atomically subtracts a number from this value, returning the new value.

◆ operator=() [1/2]

template<typename Type>
Atomic & water::Atomic< Type >::operator= ( const Atomic< Type > & other)
inlinenoexcept

Copies another value onto this one (atomically).

◆ operator=() [2/2]

template<typename Type>
Atomic & water::Atomic< Type >::operator= ( const Type newValue)
inlinenoexcept

Copies another value onto this one (atomically).

◆ set()

template<typename Type>
void water::Atomic< Type >::set ( Type newValue)
inlinenoexcept

Atomically sets the current value.


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