From 620f12120618ae548575c741a9dc54e405aefed4 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 6 Jun 2019 12:27:26 +0200 Subject: 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 Reviewed-by: Thiago Macieira --- src/corelib/thread/qatomic.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/corelib/thread/qatomic.h') diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index 280ce96b76..7990db2fd9 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -81,8 +81,10 @@ public: #ifdef Q_CLANG_QDOC T load() const; + T loadRelaxed() const; T loadAcquire() const; void store(T newValue); + void storeRelaxed(T newValue); void storeRelease(T newValue); operator T() const; @@ -172,7 +174,7 @@ public: #else inline QAtomicPointer(T *value = nullptr) noexcept { - this->store(value); + this->storeRelaxed(value); } #endif inline QAtomicPointer(const QAtomicPointer &other) noexcept -- cgit v1.2.3 From 34fe9232dbf6a9fe58ebc4c7680bb67d2f642c40 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 10 Jun 2019 11:08:29 +0200 Subject: Port from QAtomic::load() to loadRelaxed() Semi-automated, just needed ~20 manual fixes: $ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)load\(\)/$1loadRelaxed\(\)/g' -i \{\} + $ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)store\(/$1storeRelaxed\(/g' -i \{\} + It can be easily improved (e.g. for store check that there are no commas after the opening parens). The most common offender is QLibrary::load, and some code using std::atomic directly. Change-Id: I07c38a3c8ed32c924ef4999e85c7e45cf48f0f6c Reviewed-by: Marc Mutz --- src/corelib/thread/qatomic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/thread/qatomic.h') diff --git a/src/corelib/thread/qatomic.h b/src/corelib/thread/qatomic.h index 7990db2fd9..a3b9be0729 100644 --- a/src/corelib/thread/qatomic.h +++ b/src/corelib/thread/qatomic.h @@ -257,7 +257,7 @@ inline void qAtomicAssign(T *&d, T *x) template inline void qAtomicDetach(T *&d) { - if (d->ref.load() == 1) + if (d->ref.loadRelaxed() == 1) return; T *x = d; d = new T(*d); -- cgit v1.2.3