CopperSpice API  1.7.2
QAtomicPointer< T > Class Template Reference

Class template providing platform independent atomic operations on pointers. More...

Public Methods

 QAtomicPointer (const QAtomicPointer< T > &other)
 
 QAtomicPointer (T *value=nullptr)
 
T * fetchAndAddAcquire (std::ptrdiff_t valueToAdd)
 
T * fetchAndAddOrdered (std::ptrdiff_t valueToAdd)
 
T * fetchAndAddRelaxed (std::ptrdiff_t valueToAdd)
 
T * fetchAndAddRelease (std::ptrdiff_t valueToAdd)
 
T * fetchAndStoreAcquire (T *newValue)
 
T * fetchAndStoreOrdered (T *newValue)
 
T * fetchAndStoreRelaxed (T *newValue)
 
T * fetchAndStoreRelease (T *newValue)
 
T * load () const
 
T * load (std::memory_order order) const
 
T * loadAcquire () const
 
T * operator++ ()
 
T * operator++ (int)
 
T * operator+= (std::ptrdiff_t value)
 
T * operator-- ()
 
T * operator-- (int)
 
T * operator-= (std::ptrdiff_t value)
 
QAtomicPointer< T > & operator= (const QAtomicPointer< T > &other)
 
QAtomicPointer< T > & operator= (T *value)
 
void store (T *newValue)
 
void store (T *newValue, std::memory_order order)
 
void storeRelease (T *newValue)
 
bool testAndSetAcquire (T *expectedValue, T *newValue)
 
bool testAndSetOrdered (T *expectedValue, T *newValue)
 
bool testAndSetRelaxed (T *expectedValue, T *newValue)
 
bool testAndSetRelease (T *expectedValue, T *newValue)
 

Static Public Methods

static bool isFetchAndAddNative ()
 
static bool isFetchAndAddWaitFree ()
 
static bool isFetchAndStoreNative ()
 
static bool isFetchAndStoreWaitFree ()
 
static bool isTestAndSetNative ()
 
static bool isTestAndSetWaitFree ()
 

Detailed Description

template<typename T>
class QAtomicPointer< T >

The QAtomicPointer class is a template class which provides platform independent atomic operations on pointers. For atomic operations on integers refer to the QAtomicInt class. An atomic operation is one which is guaranteed to free of data races.

Memory Ordering

This class has several methods which have a parameter which specifies the memory ordering. These are the valid enum values.

ValueDescription
std::memory_order_relaxed memory ordering is unrestricted, allows the compiler and processor to freely reorder non atomic memory access
std::memory_order_acquire prevents all read and writes of non atomic data from being moved before the current atomic operation
std::memory_order_release prevents all read and writes of non atomic data from being moved after the current atomic operation
std::memory_order_acq_rel combination of acquire and release
std::memory_order_seq_cst default ordering, all reads and writes will done in the same order as the appear in the source code

Compare and Exchange

If the current atomic value is equal to the expected value then compareExchange() will store the new value and return true. If the current atomic value is not equal to the expected value compareExchange() will be updated with the current atomic value and this method will return false.

QAtomicPointer<int> data = nullptr;
int *expected = &myInt;
bool result data.compareExchange(expected, somePointerValue); // returns false

Fetch and Store

The atomic "fetch and store" methods read the current value of the QAtomicPointer and then assign a new value, returning the original value.

Fetch And Add

The atomic "fetch and add" methods read the current value of the QAtomicPointer and then add the given value to the current value, returning the original value.

See also
QAtomicInt

Constructor & Destructor Documentation

template<typename T >
QAtomicPointer< T >::QAtomicPointer ( T *  value = nullptr)
inline

Constructs a QAtomicPointer with the given value.

template<typename T >
QAtomicPointer< T >::QAtomicPointer ( const QAtomicPointer< T > &  other)
inline

Constructs a copy of other.

Method Documentation

template<typename T >
T * QAtomicPointer< T >::fetchAndAddAcquire ( std::ptrdiff_t  valueToAdd)
inlinedeprecated
Deprecated:

Reads the current value of this QAtomicPointer and then adds valueToAdd to the current value, returning the original value.

This method uses acquire memory ordering semantics which ensures that memory access following the atomic operation (in program order) may not be reordered before the atomic operation.

template<typename T >
T * QAtomicPointer< T >::fetchAndAddOrdered ( std::ptrdiff_t  valueToAdd)
inlinedeprecated
Deprecated:

Reads the current value of this QAtomicPointer and then adds valueToAdd to the current value, returning the original value.

This method uses ordered memory ordering semantics which ensures that memory access before and after the atomic operation (in program order) may not be reordered.

template<typename T >
T * QAtomicPointer< T >::fetchAndAddRelaxed ( std::ptrdiff_t  valueToAdd)
inlinedeprecated
Deprecated:

Reads the current value of this QAtomicPointer and then adds valueToAdd to the current value, returning the original value.

This method uses relaxed memory ordering semantics leaving the compiler and processor to freely reorder memory accesses.

template<typename T >
T * QAtomicPointer< T >::fetchAndAddRelease ( std::ptrdiff_t  valueToAdd)
inlinedeprecated
Deprecated:

Reads the current value of this QAtomicPointer and then adds valueToAdd to the current value, returning the original value.

This method uses release memory ordering semantics, which ensures that memory access before the atomic operation (in program order) may not be reordered after the atomic operation.

template<typename T >
T * QAtomicPointer< T >::fetchAndStoreAcquire ( T *  newValue)
inlinedeprecated
Deprecated:

Reads the current value of this QAtomicPointer and then assigns it the newValue, returning the original value.

This method uses acquire memory ordering semantics which ensures that memory access following the atomic operation (in program order) may not be reordered before the atomic operation.

template<typename T >
T * QAtomicPointer< T >::fetchAndStoreOrdered ( T *  newValue)
inlinedeprecated
Deprecated:

Reads the current value of this QAtomicPointer and then assigns it the newValue, returning the original value.

This method uses ordered memory ordering semantics which ensures that memory access before and after the atomic operation (in program order) may not be reordered.

template<typename T >
T * QAtomicPointer< T >::fetchAndStoreRelaxed ( T *  newValue)
inlinedeprecated
Deprecated:

Reads the current value of this QAtomicPointer and then assigns it the newValue, returning the original value.

This method uses relaxed memory ordering semantics leaving the compiler and processor to freely reorder memory accesses.

template<typename T >
T * QAtomicPointer< T >::fetchAndStoreRelease ( T *  newValue)
inlinedeprecated
Deprecated:

Reads the current value of this QAtomicPointer and then assigns it the newValue, returning the original value.

This method uses release memory ordering semantics which ensures that memory access before the atomic operation (in program order) may not be reordered after the atomic operation.

template<typename T >
bool QAtomicPointer< T >::isFetchAndAddNative ( )
inlinestatic

Returns true if "fetch and add" is implemented using atomic processor instructions, otherwise returns false.

template<typename T >
bool QAtomicPointer< T >::isFetchAndAddWaitFree ( )
inlinestatic

Returns true if atomic "fetch and add" is wait free, false otherwise.

template<typename T >
bool QAtomicPointer< T >::isFetchAndStoreNative ( )
inlinestatic

Returns true if "fetch and store" is implemented using atomic processor instructions, otherwise returns false.

template<typename T >
bool QAtomicPointer< T >::isFetchAndStoreWaitFree ( )
inlinestatic

Returns true if atomic "fetch and store" is wait free, otherwise returns false.

template<typename T >
bool QAtomicPointer< T >::isTestAndSetNative ( )
inlinestatic

Returns true if "test and set" is implemented using atomic processor instructions, otherwise returns false.

template<typename T >
bool QAtomicPointer< T >::isTestAndSetWaitFree ( )
inlinestatic

Returns true if atomic "test and set" is wait free, otherwise returns false.

template<typename T >
T * QAtomicPointer< T >::load ( ) const
inline

Atomically loads the value of this QAtomicPointer using relaxed memory ordering.

See also
store(), loadAcquire()
template<typename T >
T * QAtomicPointer< T >::load ( std::memory_order  order) const
inline

Atomically loads the value of this QAtomicPointer using the memory ordering order.

template<typename T >
T * QAtomicPointer< T >::loadAcquire ( ) const
inline

Atomically loads the value of this QAtomicPointer using the "Acquire" memory ordering.

See also
store(), load()
template<typename T >
T * QAtomicPointer< T >::operator++ ( )
inline

The prefix ++ operator advances the pointer to the next item in memory and returns the new value.

See also
operator--()
template<typename T >
T * QAtomicPointer< T >::operator++ ( int  )
inline

The postfix ++ operator advances the pointer to the next item in memory and returns the old value.

template<typename T >
T * QAtomicPointer< T >::operator+= ( std::ptrdiff_t  value)
inline

Add value to current pointer and returns the new value.

template<typename T >
T * QAtomicPointer< T >::operator-- ( )
inline

The prefix – operator decrements the pointer to the previous item in memory and returns the new value.

See also
operator++()
template<typename T >
T * QAtomicPointer< T >::operator-- ( int  )
inline

The postfix – operator decrements the pointer to the previous item in memory and returns the old value.

template<typename T >
T * QAtomicPointer< T >::operator-= ( std::ptrdiff_t  value)
inline

Subtracts value from the current pointer and returns the new value.

template<typename T >
QAtomicPointer< T > & QAtomicPointer< T >::operator= ( const QAtomicPointer< T > &  other)
inline

Copy assigns from other and returns a reference to this object.

template<typename T >
QAtomicPointer< T > & QAtomicPointer< T >::operator= ( T *  value)
inline

Assigns the value to this QAtomicPointer and returns a reference to this QAtomicPointer.

template<typename T >
void QAtomicPointer< T >::store ( T *  newValue)
inline

Atomically stores the newValue value into this atomic type using relaxed memory ordering.

See also
storeRelease(), load()
template<typename T >
void QAtomicPointer< T >::store ( T *  newValue,
std::memory_order  order 
)
inline

Atomically stores the newValue value into this atomic type using the memory ordering order.

template<typename T >
void QAtomicPointer< T >::storeRelease ( T *  newValue)
inline

Atomically stores the newValue value into this atomic type using the "Release" memory ordering.

See also
store(), load()
template<typename T >
bool QAtomicPointer< T >::testAndSetAcquire ( T *  expectedValue,
T *  newValue 
)
inlinedeprecated
Deprecated:

If the current value of this QAtomicPointer is the expectedValue, the test-and-set methods assign the newValue to this QAtomicPointer and return true. If the values are not the same, this method does nothing and returns false.

This method uses acquire memory ordering semantics which ensures that memory access following the atomic operation (in program order) may not be reordered before the atomic operation.

template<typename T >
bool QAtomicPointer< T >::testAndSetOrdered ( T *  expectedValue,
T *  newValue 
)
inlinedeprecated
Deprecated:

If the current value of this QAtomicPointer is the expectedValue, the test-and-set methods assign the newValue to this QAtomicPointer and return true. If the values are not the same, this method does nothing and returns false.

This method uses ordered memory ordering semantics which ensures that memory access before and after the atomic operation (in program order) may not be reordered.

template<typename T >
bool QAtomicPointer< T >::testAndSetRelaxed ( T *  expectedValue,
T *  newValue 
)
inlinedeprecated
Deprecated:

If the current value of this QAtomicPointer is the expectedValue, the test-and-set methods assign the newValue to this QAtomicPointer and return true. If the values are not the same, this method does nothing and returns false.

This method uses relaxed memory ordering semantics leaving the compiler and processor to freely reorder memory accesses.

template<typename T >
bool QAtomicPointer< T >::testAndSetRelease ( T *  expectedValue,
T *  newValue 
)
inlinedeprecated
Deprecated:

If the current value of this QAtomicPointer is the expectedValue, the test-and-set methods assign the newValue to this QAtomicPointer and return true. If the values are not the same, this method does nothing and returns false.

This method method uses release memory ordering semantics which ensures memory access before the atomic operation (in program order) may not be reordered after the atomic operation.