JUCE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
juce::Atomic< Type > Class Template Reference

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.
 
Atomicoperator= (const Atomic &other) noexcept
 Copies another value onto this one (atomically).
 
Atomicoperator= (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.
 
 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.
 
Atomicoperator= (const Atomic &other) noexcept
 Copies another value onto this one (atomically).
 
Atomicoperator= (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.
 
 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.
 
Atomicoperator= (const Atomic &other) noexcept
 Copies another value onto this one (atomically).
 
Atomicoperator= (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.
 
static void memoryBarrier () noexcept
 Implements a memory read/write barrier.
 
static void memoryBarrier () noexcept
 Implements a memory read/write barrier.
 

Public Attributes

volatile Type value
 The raw value that this class operates on.
 

Detailed Description

template<typename Type>
class juce::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

template<typename Type>
juce::Atomic< Type >::Atomic ( )
noexcept

Creates a new value, initialised to zero.

template<typename Type>
juce::Atomic< Type >::Atomic ( const Type  initialValue)
noexcept

Creates a new value, with a given initial value.

template<typename Type>
juce::Atomic< Type >::Atomic ( const Atomic< Type > &  other)
noexcept

Copies another value (atomically).

template<typename Type>
juce::Atomic< Type >::~Atomic ( )
noexcept

Destructor.

template<typename Type>
juce::Atomic< Type >::Atomic ( )
noexcept

Creates a new value, initialised to zero.

template<typename Type>
juce::Atomic< Type >::Atomic ( const Type  initialValue)
noexcept

Creates a new value, with a given initial value.

template<typename Type>
juce::Atomic< Type >::Atomic ( const Atomic< Type > &  other)
noexcept

Copies another value (atomically).

template<typename Type>
juce::Atomic< Type >::~Atomic ( )
noexcept

Destructor.

template<typename Type>
juce::Atomic< Type >::Atomic ( )
noexcept

Creates a new value, initialised to zero.

template<typename Type>
juce::Atomic< Type >::Atomic ( const Type  initialValue)
noexcept

Creates a new value, with a given initial value.

template<typename Type>
juce::Atomic< Type >::Atomic ( const Atomic< Type > &  other)
noexcept

Copies another value (atomically).

template<typename Type>
juce::Atomic< Type >::~Atomic ( )
noexcept

Destructor.

Member Function Documentation

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

Atomically reads and returns the current value.

template<typename Type>
Atomic& juce::Atomic< Type >::operator= ( const Atomic< Type > &  other)
noexcept

Copies another value onto this one (atomically).

template<typename Type>
Atomic& juce::Atomic< Type >::operator= ( const Type  newValue)
noexcept

Copies another value onto this one (atomically).

template<typename Type>
void juce::Atomic< Type >::set ( Type  newValue)
noexcept

Atomically sets the current value.

template<typename Type>
Type Atomic< Type >::exchange ( Type  value)
noexcept

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

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

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

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

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

template<typename Type >
Type Atomic< Type >::operator++ ( )
noexcept

Atomically increments this value, returning the new value.

template<typename Type >
Type Atomic< Type >::operator-- ( )
noexcept

Atomically decrements this value, returning the new value.

template<typename Type>
bool Atomic< Type >::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.

This operation is the atomic equivalent of doing this:

bool compareAndSetBool (Type newValue, Type valueToCompare)
{
if (get() == valueToCompare)
{
set (newValue);
return true;
}
return false;
}
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
template<typename Type>
Type Atomic< 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.

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;
}
Returns
the old value before it was changed.
See Also
compareAndSetBool
template<typename Type >
void Atomic< Type >::memoryBarrier ( )
staticnoexcept

Implements a memory read/write barrier.

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

Atomically reads and returns the current value.

template<typename Type>
Atomic& juce::Atomic< Type >::operator= ( const Atomic< Type > &  other)
noexcept

Copies another value onto this one (atomically).

template<typename Type>
Atomic& juce::Atomic< Type >::operator= ( const Type  newValue)
noexcept

Copies another value onto this one (atomically).

template<typename Type>
void juce::Atomic< Type >::set ( Type  newValue)
noexcept

Atomically sets the current value.

template<typename Type>
Type juce::Atomic< Type >::exchange ( Type  value)
noexcept

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

template<typename Type>
Type juce::Atomic< Type >::operator+= ( Type  amountToAdd)
noexcept

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

template<typename Type>
Type juce::Atomic< Type >::operator-= ( Type  amountToSubtract)
noexcept

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

template<typename Type>
Type juce::Atomic< Type >::operator++ ( )
noexcept

Atomically increments this value, returning the new value.

template<typename Type>
Type juce::Atomic< Type >::operator-- ( )
noexcept

Atomically decrements this value, returning the new value.

template<typename Type>
bool juce::Atomic< Type >::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.

This operation is the atomic equivalent of doing this:

bool compareAndSetBool (Type newValue, Type valueToCompare)
{
if (get() == valueToCompare)
{
set (newValue);
return true;
}
return false;
}
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
template<typename Type>
Type juce::Atomic< 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.

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;
}
Returns
the old value before it was changed.
See Also
compareAndSetBool
template<typename Type>
static void juce::Atomic< Type >::memoryBarrier ( )
staticnoexcept

Implements a memory read/write barrier.

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

Atomically reads and returns the current value.

template<typename Type>
Atomic& juce::Atomic< Type >::operator= ( const Atomic< Type > &  other)
noexcept

Copies another value onto this one (atomically).

template<typename Type>
Atomic& juce::Atomic< Type >::operator= ( const Type  newValue)
noexcept

Copies another value onto this one (atomically).

template<typename Type>
void juce::Atomic< Type >::set ( Type  newValue)
noexcept

Atomically sets the current value.

template<typename Type>
Type juce::Atomic< Type >::exchange ( Type  value)
noexcept

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

template<typename Type>
Type juce::Atomic< Type >::operator+= ( Type  amountToAdd)
noexcept

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

template<typename Type>
Type juce::Atomic< Type >::operator-= ( Type  amountToSubtract)
noexcept

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

template<typename Type>
Type juce::Atomic< Type >::operator++ ( )
noexcept

Atomically increments this value, returning the new value.

template<typename Type>
Type juce::Atomic< Type >::operator-- ( )
noexcept

Atomically decrements this value, returning the new value.

template<typename Type>
bool juce::Atomic< Type >::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.

This operation is the atomic equivalent of doing this:

bool compareAndSetBool (Type newValue, Type valueToCompare)
{
if (get() == valueToCompare)
{
set (newValue);
return true;
}
return false;
}
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
template<typename Type>
Type juce::Atomic< 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.

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;
}
Returns
the old value before it was changed.
See Also
compareAndSetBool
template<typename Type>
static void juce::Atomic< Type >::memoryBarrier ( )
staticnoexcept

Implements a memory read/write barrier.

Member Data Documentation

template<typename Type>
volatile Type Atomic< Type >::value

The raw value that this class operates on.

This is exposed publically in case you need to manipulate it directly for performance reasons.


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