Simple class to hold a primitive value and perform atomic operations on it. More...
Public Member Functions | |
| Atomic () noexcept | |
| Creates a new value, initialised to zero. | |
| Atomic (const Type initialValue) noexcept | |
| Creates a new value, with a given initial value. | |
| Atomic (const Atomic &other) noexcept | |
| Copies another value (atomically). | |
| ~Atomic () noexcept | |
| Destructor. | |
| Type | get () const noexcept |
| Atomically reads and returns the current value. | |
| Atomic & | operator= (const Atomic &other) noexcept |
| Copies another value onto this one (atomically). | |
| Atomic & | operator= (const Type newValue) noexcept |
| Copies another value onto this one (atomically). | |
| void | set (Type newValue) noexcept |
| Atomically sets the current value. | |
| Type | exchange (Type value) noexcept |
| Atomically sets the current value, returning the value that was replaced. | |
| Type | operator+= (Type amountToAdd) noexcept |
| Atomically adds a number to this value, returning the new value. | |
| Type | operator-= (Type amountToSubtract) noexcept |
| Atomically subtracts a number from this value, returning the new value. | |
| Type | operator++ () noexcept |
| Atomically increments this value, returning the new value. | |
| Type | operator-- () noexcept |
| Atomically decrements this value, returning the new value. | |
| bool | compareAndSetBool (Type newValue, Type valueToCompare) noexcept |
| Atomically compares this value with a target value, and if it is equal, sets this to be equal to a new value. | |
| Type | compareAndSetValue (Type newValue, Type valueToCompare) noexcept |
| Atomically compares this value with a target value, and if it is equal, sets this to be equal to a new value. | |
Static Public Member Functions | |
| static void | memoryBarrier () noexcept |
| Implements a memory read/write barrier. | |
Public Attributes | |
| volatile Type | value |
| The raw value that this class operates on. | |
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.
Creates a new value, with a given initial value.
Copies another value (atomically).
| Type Atomic< Type >::get | ( | ) | const |
Atomically reads and returns the current value.
References JUCE_MAC_ATOMICS_VOLATILE.
Copies another value onto this one (atomically).
Copies another value onto this one (atomically).
| void Atomic< Type >::set | ( | Type | newValue ) |
Atomically sets the current value.
| Type Atomic< Type >::exchange | ( | Type | value ) |
Atomically sets the current value, returning the value that was replaced.
Referenced by Atomic< int >::operator=(), and Atomic< int >::set().
| Type Atomic< Type >::operator+= | ( | Type | amountToAdd ) |
Atomically adds a number to this value, returning the new value.
References JUCE_MAC_ATOMICS_VOLATILE.
| Type Atomic< Type >::operator-= | ( | Type | amountToSubtract ) |
Atomically subtracts a number from this value, returning the new value.
References juce_negate().
| Type Atomic< Type >::operator++ | ( | ) |
Atomically increments this value, returning the new value.
References JUCE_MAC_ATOMICS_VOLATILE.
| Type Atomic< Type >::operator-- | ( | ) |
Atomically decrements this value, returning the new value.
References JUCE_MAC_ATOMICS_VOLATILE.
| bool Atomic< Type >::compareAndSetBool | ( | Type | newValue, |
| Type | valueToCompare | ||
| ) |
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; }
References JUCE_MAC_ATOMICS_VOLATILE.
| Type Atomic< Type >::compareAndSetValue | ( | Type | newValue, |
| Type | valueToCompare | ||
| ) |
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; }
| void Atomic< Type >::memoryBarrier | ( | ) | [static] |
Implements a memory read/write barrier.
The raw value that this class operates on.
This is exposed publically in case you need to manipulate it directly for performance reasons.