diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2019-06-06 12:27:26 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2019-06-10 16:56:17 +0000 |
commit | 620f12120618ae548575c741a9dc54e405aefed4 (patch) | |
tree | 54ac78189cd5a35785e898e6aafb5bb90a3bd4cb /src/corelib/thread/qbasicatomic.h | |
parent | efe1073e440fd7a179da8d19abc43fb9a745ac2f (diff) |
QAtomic: introduce loadRelaxed() / storeRelaxed()
Plain load() / store() have already relaxed semantics. This
can be surprising -- std::atomic::load()/store() are actually
sequentially consistent -- and introduce a pain point
if someone wants to move from Qt atomics to std:: atomics.
So just add a suffix to the functions to clarify what's the
memory ordering involved with them.
The Ops::load / ::store are temporarily left in, because other
modules depends on them. We need to port those modules away,
then they can go (it's private API anyhow).
Similarly, not deprecating anything yet, except for marking
obsolete in the docs; there's a lot of code around using
load() / store() that needs to be ported first.
[ChangeLog][QtCore][QAtomicInteger] Added loadRelaxed() and
storeRelaxed(), to be used as replacements of load() / store().
[ChangeLog][QtCore][QAtomicPointer] Added loadRelaxed() and
storeRelaxed(), to be used as replacements of load() / store().
Change-Id: Iab0a78885050379e3740f0b039ba2bef28ce3bd2
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread/qbasicatomic.h')
-rw-r--r-- | src/corelib/thread/qbasicatomic.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h index 7d2e06a499..dc976819ef 100644 --- a/src/corelib/thread/qbasicatomic.h +++ b/src/corelib/thread/qbasicatomic.h @@ -99,9 +99,11 @@ public: typename Ops::Type _q_value; // Everything below is either implemented in ../arch/qatomic_XXX.h or (as fallback) in qgenericatomic.h + T load() const noexcept { return loadRelaxed(); } + void store(T newValue) noexcept { storeRelaxed(newValue); } - T load() const noexcept { return Ops::load(_q_value); } - void store(T newValue) noexcept { Ops::store(_q_value, newValue); } + T loadRelaxed() const noexcept { return Ops::loadRelaxed(_q_value); } + void storeRelaxed(T newValue) noexcept { Ops::storeRelaxed(_q_value, newValue); } T loadAcquire() const noexcept { return Ops::loadAcquire(_q_value); } void storeRelease(T newValue) noexcept { Ops::storeRelease(_q_value, newValue); } @@ -236,8 +238,12 @@ public: AtomicType _q_value; - Type load() const noexcept { return Ops::load(_q_value); } - void store(Type newValue) noexcept { Ops::store(_q_value, newValue); } + Type load() const noexcept { return loadRelaxed(); } + void store(Type newValue) noexcept { storeRelaxed(newValue); } + + Type loadRelaxed() const noexcept { return Ops::loadRelaxed(_q_value); } + void storeRelaxed(Type newValue) noexcept { Ops::storeRelaxed(_q_value, newValue); } + operator Type() const noexcept { return loadAcquire(); } Type operator=(Type newValue) noexcept { storeRelease(newValue); return newValue; } |