JUCE  v5.2.0-514-g49784a029
JUCE API
juce::Atomic< Type > Class Template Referencefinal

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

#include <juce_Atomic.h>

Inheritance diagram for juce::Atomic< Type >:
Collaboration diagram for juce::Atomic< Type >:

Public Types

typedef AtomicBase< Type >::DiffType DiffType
 Resulting type when subtracting the underlying Type. More...
 

Public Member Functions

 Atomic () noexcept
 Creates a new value, initialised to zero. More...
 
 Atomic (const Type initialValue) noexcept
 Creates a new value, with a given initial value. More...
 
 Atomic (const Atomic &other) noexcept
 Copies another value (atomically). More...
 
 ~Atomic () noexcept
 Destructor. More...
 
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. More...
 
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. More...
 
Type exchange (Type v) noexcept
 Atomically sets the current value, returning the value that was replaced. More...
 
Type get () const noexcept
 Atomically reads and returns the current value. More...
 
Type operator++ () noexcept
 Atomically increments this value, returning the new value. More...
 
Type operator+= (DiffType amountToAdd) noexcept
 Atomically adds a number to this value, returning the new value. More...
 
Type operator-- () noexcept
 Atomically decrements this value, returning the new value. More...
 
Type operator-= (DiffType amountToSubtract) noexcept
 Atomically subtracts a number from this value, returning the new value. More...
 
Atomicoperator= (const Atomic &other) noexcept
 Copies another value into this one (atomically). More...
 
Atomicoperator= (const Type newValue) noexcept
 Copies another value into this one (atomically). More...
 
void set (Type newValue) noexcept
 Atomically sets the current value. More...
 

Static Public Member Functions

static void memoryBarrier () noexcept
 Implements a memory read/write barrier. More...
 

Public Attributes

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

Protected Member Functions

template<typename ValueType >
ValueType negateValue (ValueType n) noexcept
 This templated negate function will negate pointers as well as integers. More...
 
template<typename PointerType >
PointerType * negateValue (PointerType *n) noexcept
 This templated negate function will negate pointers as well as integers. More...
 
Type operator++ (int)
 
Type operator-- (int)
 

Static Protected Member Functions

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

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.

Member Typedef Documentation

◆ DiffType

template<typename Type>
typedef AtomicBase<Type>::DiffType juce::Atomic< Type >::DiffType

Resulting type when subtracting the underlying Type.

Constructor & Destructor Documentation

◆ Atomic() [1/3]

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

Creates a new value, initialised to zero.

◆ Atomic() [2/3]

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

Creates a new value, with a given initial value.

◆ Atomic() [3/3]

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

Copies another value (atomically).

◆ ~Atomic()

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

Destructor.

Member Function Documentation

◆ castFrom32Bit()

template<typename Type>
static Type juce::AtomicBase< Type >::castFrom32Bit ( int32  value)
inlinestaticprotectednoexceptinherited

◆ castFrom64Bit()

template<typename Type>
static Type juce::AtomicBase< Type >::castFrom64Bit ( int64  value)
inlinestaticprotectednoexceptinherited

◆ castTo()

template<typename Type>
template<typename Dest , typename Source >
static Dest juce::AtomicBase< Type >::castTo ( Source  value)
inlinestaticprotectednoexceptinherited

◆ castTo32Bit()

template<typename Type>
static int32 juce::AtomicBase< Type >::castTo32Bit ( Type  value)
inlinestaticprotectednoexceptinherited

◆ castTo64Bit()

template<typename Type>
static int64 juce::AtomicBase< Type >::castTo64Bit ( Type  value)
inlinestaticprotectednoexceptinherited

◆ compareAndSetBool()

template<typename Type>
bool juce::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;
}
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

Referenced by juce::ThreadLocalValue< Type >::get().

◆ compareAndSetValue()

template<typename Type>
Type juce::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;
}
Returns
the old value before it was changed.
See also
compareAndSetBool

◆ exchange()

template<typename Type>
Type juce::Atomic< Type >::exchange ( Type  v)
inlinenoexcept

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

◆ get()

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

◆ memoryBarrier()

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

Implements a memory read/write barrier.

◆ negateValue() [1/2]

template<typename Type>
template<typename ValueType >
ValueType juce::AtomicBase< Type >::negateValue ( ValueType  n)
inlineprotectednoexceptinherited

This templated negate function will negate pointers as well as integers.

◆ negateValue() [2/2]

template<typename Type>
template<typename PointerType >
PointerType* juce::AtomicBase< Type >::negateValue ( PointerType *  n)
inlineprotectednoexceptinherited

This templated negate function will negate pointers as well as integers.

◆ operator++() [1/2]

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

Atomically increments this value, returning the new value.

◆ operator++() [2/2]

template<typename Type>
Type juce::AtomicBase< Type >::operator++ ( int  )
protectedinherited

◆ operator+=()

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

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

◆ operator--() [1/2]

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

Atomically decrements this value, returning the new value.

◆ operator--() [2/2]

template<typename Type>
Type juce::AtomicBase< Type >::operator-- ( int  )
protectedinherited

◆ operator-=()

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

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

◆ operator=() [1/2]

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

Copies another value into this one (atomically).

◆ operator=() [2/2]

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

Copies another value into this one (atomically).

◆ set()

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

Atomically sets the current value.

Member Data Documentation

◆ value

template<typename Type>
volatile Type juce::AtomicBase< Type >::value
inherited

The raw value that this class operates on.

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

Referenced by juce::LeakedObjectDetector< OwnerClass >::LeakCounter::~LeakCounter().


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