QAtomicPointer Class
template <typename T> class QAtomicPointer
The QAtomicPointer class is a template class that provides platform-independent atomic operations on pointers. More…
| Header | #include <QAtomicPointer> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QAtomicPointer(T *p = nullptr) | |
| QAtomicPointer(const QAtomicPointer &other) | |
| QAtomicPointer & | operator=(const QAtomicPointer &other) |
| T * | loadRelaxed() const |
| T * | loadAcquire() const |
| void | storeRelaxed(T *p) |
| void | storeRelease(T *p) |
| T * | load() const |
| void | store(T *p) |
| bool | testAndSetRelaxed(T *expected, T *desired) |
| bool | testAndSetRelaxed(T *expected, T *desired, T *¤tValue) |
| T * | fetchAndStoreRelaxed(T *v) |
| T * | fetchAndAddRelaxed(qptrdiff v) |
| T * | fetchAndSubRelaxed(qptrdiff v) |
| bool | testAndSetAcquire(T *expected, T *desired) |
| bool | testAndSetAcquire(T *expected, T *desired, T *¤tValue) |
| T * | fetchAndStoreAcquire(T *v) |
| T * | fetchAndAddAcquire(qptrdiff v) |
| T * | fetchAndSubAcquire(qptrdiff v) |
| bool | testAndSetRelease(T *expected, T *desired) |
| bool | testAndSetRelease(T *expected, T *desired, T *¤tValue) |
| T * | fetchAndStoreRelease(T *v) |
| T * | fetchAndAddRelease(qptrdiff v) |
| T * | fetchAndSubRelease(qptrdiff v) |
| bool | testAndSetOrdered(T *expected, T *desired) |
| bool | testAndSetOrdered(T *expected, T *desired, T *¤tValue) |
| T * | fetchAndStoreOrdered(T *v) |
| T * | fetchAndAddOrdered(qptrdiff v) |
| T * | fetchAndSubOrdered(qptrdiff v) |
| operator T*() const | |
| QAtomicPointer & | operator=(T *p) |
Detailed Description
QAtomicPointer<T> wraps a std::atomic<T *>. It is used for lock-free publication of pointers between threads:
QAtomicPointer<Config> current;
void publish(Config *c) { current.storeRelease(c); }
Config *get() { return current.loadAcquire(); }
See also QAtomicInteger.
Differences from Qt
There are no is...Native() or is...WaitFree() queries.
Member Function Documentation
QAtomicPointer::QAtomicPointer(T *p = nullptr)
Constructs an atomic pointer holding p.
QAtomicPointer::QAtomicPointer(const QAtomicPointer &other)
Constructs a copy of other, loading its pointer atomically.
T * QAtomicPointer::fetchAndAddAcquire(qptrdiff v)
Atomically adds v to the pointer, counted in elements of T,, using acquire memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndAddOrdered(qptrdiff v)
Atomically adds v to the pointer, counted in elements of T,, using sequentially consistent memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndAddRelaxed(qptrdiff v)
Atomically adds v to the pointer, counted in elements of T,, using relaxed memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndAddRelease(qptrdiff v)
Atomically adds v to the pointer, counted in elements of T,, using release memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndStoreAcquire(T *v)
Atomically replaces the value with v, using acquire memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndStoreOrdered(T *v)
Atomically replaces the value with v, using sequentially consistent memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndStoreRelaxed(T *v)
Atomically replaces the value with v, using relaxed memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndStoreRelease(T *v)
Atomically replaces the value with v, using release memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndSubAcquire(qptrdiff v)
Atomically subtracts v from the pointer, counted in elements of T,, using acquire memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndSubOrdered(qptrdiff v)
Atomically subtracts v from the pointer, counted in elements of T,, using sequentially consistent memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndSubRelaxed(qptrdiff v)
Atomically subtracts v from the pointer, counted in elements of T,, using relaxed memory ordering, and returns the previous value.
T * QAtomicPointer::fetchAndSubRelease(qptrdiff v)
Atomically subtracts v from the pointer, counted in elements of T,, using release memory ordering, and returns the previous value.
T * QAtomicPointer::load() const
Atomically loads and returns the pointer with sequentially consistent ordering.
See also loadRelaxed() and loadAcquire().
T * QAtomicPointer::loadAcquire() const
Atomically loads and returns the pointer with acquire memory ordering.
See also loadRelaxed() and load().
T * QAtomicPointer::loadRelaxed() const
Atomically loads and returns the pointer with relaxed memory ordering.
See also loadAcquire() and load().
QAtomicPointer::operator T*() const
Atomically loads and returns the pointer, as load() does.
QAtomicPointer & QAtomicPointer::operator=(const QAtomicPointer &other)
Atomically stores the pointer of other and returns a reference to this object.
QAtomicPointer & QAtomicPointer::operator=(T *p)
Atomically stores p and returns a reference to this object.
void QAtomicPointer::store(T *p)
Atomically stores p with sequentially consistent ordering.
See also storeRelaxed() and storeRelease().
void QAtomicPointer::storeRelaxed(T *p)
Atomically stores p with relaxed memory ordering.
See also storeRelease() and store().
void QAtomicPointer::storeRelease(T *p)
Atomically stores p with release memory ordering.
See also storeRelaxed() and store().
bool QAtomicPointer::testAndSetAcquire(T *expected, T *desired)
Atomically compares the value with expected and, if they are equal, replaces it with desired, using acquire memory ordering. Returns true if the value was replaced; otherwise returns false.
bool QAtomicPointer::testAndSetAcquire(T *expected, T *desired, T *¤tValue)
This is an overloaded function.
Like the other overload, and stores the value found in currentValue whether or not it was replaced, comparing with expected and storing desired with acquire memory ordering.
bool QAtomicPointer::testAndSetOrdered(T *expected, T *desired)
Atomically compares the value with expected and, if they are equal, replaces it with desired, using sequentially consistent memory ordering. Returns true if the value was replaced; otherwise returns false.
bool QAtomicPointer::testAndSetOrdered(T *expected, T *desired, T *¤tValue)
This is an overloaded function.
Like the other overload, and stores the value found in currentValue whether or not it was replaced, comparing with expected and storing desired with sequentially consistent memory ordering.
bool QAtomicPointer::testAndSetRelaxed(T *expected, T *desired)
Atomically compares the value with expected and, if they are equal, replaces it with desired, using relaxed memory ordering. Returns true if the value was replaced; otherwise returns false.
bool QAtomicPointer::testAndSetRelaxed(T *expected, T *desired, T *¤tValue)
This is an overloaded function.
Like the other overload, and stores the value found in currentValue whether or not it was replaced, comparing with expected and storing desired with relaxed memory ordering.
bool QAtomicPointer::testAndSetRelease(T *expected, T *desired)
Atomically compares the value with expected and, if they are equal, replaces it with desired, using release memory ordering. Returns true if the value was replaced; otherwise returns false.
bool QAtomicPointer::testAndSetRelease(T *expected, T *desired, T *¤tValue)
This is an overloaded function.
Like the other overload, and stores the value found in currentValue whether or not it was replaced, comparing with expected and storing desired with release memory ordering.