CopperSpice API  1.9.1
QAtomicInt Class Reference

The QAtomicInt class provides platform independent atomic operations on integers. More...

Public Methods

 QAtomicInt (const QAtomicInt &other)
 
 QAtomicInt (int value)
 
bool compareExchange (int &expectedValue, int newValue, std::memory_order order1=std::memory_order_seq_cst, std::memory_order order2=std::memory_order_seq_cst)
 
bool compareExchangeWeak (int &expectedValue, int newValue, std::memory_order order1=std::memory_order_seq_cst, std::memory_order order2=std::memory_order_seq_cst)
 
bool deref ()
 
int fetchAndAddAcquire (int valueToAdd)
 
int fetchAndAddOrdered (int valueToAdd)
 
int fetchAndAddRelaxed (int valueToAdd)
 
int fetchAndAddRelease (int valueToAdd)
 
int fetchAndStoreAcquire (int newValue)
 
int fetchAndStoreOrdered (int newValue)
 
int fetchAndStoreRelaxed (int newValue)
 
int fetchAndStoreRelease (int newValue)
 
int load () const
 
int load (std::memory_order order) const
 
int loadAcquire () const
 
int operator++ ()
 
int operator++ (int)
 
int operator+= (int value)
 
int operator-- ()
 
int operator-- (int)
 
int operator-= (int value)
 
QAtomicInt & operator= (const QAtomicInt &other)
 
QAtomicInt & operator= (int value)
 
bool ref ()
 
void store (int newValue)
 
void store (int newValue, std::memory_order order)
 
void storeRelease (int newValue)
 
bool testAndSetAcquire (int expectedValue, int newValue)
 
bool testAndSetOrdered (int expectedValue, int newValue)
 
bool testAndSetRelaxed (int expectedValue, int newValue)
 
bool testAndSetRelease (int expectedValue, int newValue)
 

Static Public Methods

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

Detailed Description

The QAtomicInt class provides platform independent atomic operations on integers. For atomic operations on pointers refer to the QAtomicPointer 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.

QAtomicInt data = 100;
int expected = 10;
bool result data.compareExchange(expected, 50); // returns false

Fetch and Store

The atomic "fetch and store" methods assign the new value and returns the original value.

Fetch and Add

The atomic "fetch and add" methods add the given value to the current atomic value and return the original value.

See also
QAtomicPointer

Constructor & Destructor Documentation

QAtomicInt::QAtomicInt ( int  value = 0)
inline

Constructs a new QAtomicInt with the given value.

QAtomicInt::QAtomicInt ( const QAtomicInt &  other)
inline

Copy constructs a new QAtomicInt from other.

Method Documentation

bool QAtomicInt::compareExchange ( int &  expectedValue,
int  newValue,
std::memory_order  order1 = std::memory_order_seq_cst,
std::memory_order  order2 = std::memory_order_seq_cst 
)
inline

If the current atomic value is equal to the expectedValue, this method will store the new value and return true.

If the current atomic value is not equal to the expected value, will be updated with the current atomic value and this method will return false.

This method uses the strong compare exchange operation.

bool QAtomicInt::compareExchangeWeak ( int &  expectedValue,
int  newValue,
std::memory_order  order1 = std::memory_order_seq_cst,
std::memory_order  order2 = std::memory_order_seq_cst 
)
inline

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

This method uses the weak compare exchange operation. If the operation returns false it is possible the expected value did match however there was some other conflict. If this happens the operation should be retried.

bool QAtomicInt::deref ( )
inline

Atomically decrements the value of this QAtomicInt. Returns true if the new value is non-zero, false otherwise.

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.

See also
ref()
int QAtomicInt::fetchAndAddAcquire ( int  valueToAdd)
inline

Reads the current value of this QAtomicInt and then adds valueToAdd to the current value, returns 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.

int QAtomicInt::fetchAndAddOrdered ( int  valueToAdd)
inline

Reads the current value of this QAtomicInt and then adds valueToAdd to the current value, returns 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.

int QAtomicInt::fetchAndAddRelaxed ( int  valueToAdd)
inline

Reads the current value of this QAtomicInt and then adds valueToAdd to the current value, returns the original value.

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

int QAtomicInt::fetchAndAddRelease ( int  valueToAdd)
inline

Reads the current value of this QAtomicInt and then adds valueToAdd to the current value, returns 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.

int QAtomicInt::fetchAndStoreAcquire ( int  newValue)
inline

Reads the current value of this QAtomicInt and then assigns newValue to this object, returns 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.

int QAtomicInt::fetchAndStoreOrdered ( int  newValue)
inline

Reads the current value of this QAtomicInt and then assigns newValue to this object, returns 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.

int QAtomicInt::fetchAndStoreRelaxed ( int  newValue)
inline

Reads the current value of this QAtomicInt and then assigns newValue to this object, returns the original value.

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

int QAtomicInt::fetchAndStoreRelease ( int  newValue)
inline

Reads the current value of this QAtomicInt and then assigns newValue to this object, returns 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.

bool QAtomicInt::isFetchAndAddNative ( )
inlinestatic

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

bool QAtomicInt::isFetchAndAddWaitFree ( )
inlinestatic

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

bool QAtomicInt::isFetchAndStoreNative ( )
inlinestatic

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

bool QAtomicInt::isFetchAndStoreWaitFree ( )
inlinestatic

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

bool QAtomicInt::isReferenceCountingNative ( )
inlinestatic

Returns true if reference counting is implemented using atomic processor instructions, otherwise returns false.

bool QAtomicInt::isReferenceCountingWaitFree ( )
inlinestatic

Returns true if atomic reference counting is wait free, otherwise returns false.

bool QAtomicInt::isTestAndSetNative ( )
inlinestatic

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

bool QAtomicInt::isTestAndSetWaitFree ( )
inlinestatic

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

int QAtomicInt::load ( ) const
inline

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

See also
store(), loadAcquire()
int QAtomicInt::load ( std::memory_order  order) const
inline

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

int QAtomicInt::loadAcquire ( ) const
inline

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

See also
store(), load()
int QAtomicInt::operator++ ( )
inline

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

See also
operator--()
int QAtomicInt::operator++ ( int  )
inline

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

int QAtomicInt::operator+= ( int  value)
inline

Add value to current atomic and returns the new value.

int QAtomicInt::operator-- ( )
inline

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

See also
operator++()
int QAtomicInt::operator-- ( int  )
inline

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

int QAtomicInt::operator-= ( int  value)
inline

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

QAtomicInt & QAtomicInt::operator= ( const QAtomicInt &  other)
inline

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

QAtomicInt & QAtomicInt::operator= ( int  value)
inline

Assigns value to this QAtomicInt and returns a reference to this object.

bool QAtomicInt::ref ( )
inline

Atomically increments the value of this QAtomicInt. Returns true if the new value is non-zero, otherwise 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.

See also
deref()
void QAtomicInt::store ( int  newValue)
inline

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

See also
storeRelease(), load()
void QAtomicInt::store ( int  newValue,
std::memory_order  order 
)
inline

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

void QAtomicInt::storeRelease ( int  newValue)
inline

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

See also
store(), load()
bool QAtomicInt::testAndSetAcquire ( int  expectedValue,
int  newValue 
)
inlinedeprecated
Deprecated:

If the current value of this QAtomicInt is the expectedValue, the test-and-set methods assign the newValue to this QAtomicInt and returns 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.

bool QAtomicInt::testAndSetOrdered ( int  expectedValue,
int  newValue 
)
inlinedeprecated
Deprecated:

If the current value of this QAtomicInt is the expectedValue, the test-and-set methods assign the newValue to this QAtomicInt and returns 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.

bool QAtomicInt::testAndSetRelaxed ( int  expectedValue,
int  newValue 
)
inlinedeprecated
Deprecated:

If the current value of this QAtomicInt is the expectedValue, the test-and-set methods assign the newValue to this QAtomicInt and returns 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.

bool QAtomicInt::testAndSetRelease ( int  expectedValue,
int  newValue 
)
inlinedeprecated
Deprecated:

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

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.