diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2021-07-16 09:57:56 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2021-07-28 17:50:09 +0200 |
commit | 3a72496b5c43484a94882440993b0ca0cb842d8a (patch) | |
tree | 7704812d37e34a0e3e6ab32e17bb8a7624b3828d /tests | |
parent | 74a91773afa395ee0cefcdcd25bb3947b60a0b63 (diff) |
tests: fix some -Wvolatile
C++20 deprecated compound volatile statements such as pre- and
post-increments, to stress that they're not atomic. So instead of
volatile i;
~~~~;
++i;
you're now supposed to write
volatile i;
~~~~;
int j = i; // volatile load
++j;
i = j; // volatile store
which matches more closely what hardware does.
Instead of fixing every use of volatile pre- or post-increment in this
fashion individually, and realising that probably a few more Qt
modules will have the same kind of code patterns in them, write
QtPrivate functions to do the job centrally.
Change-Id: I838097bd484ef2118c071726963f103c080d2ba5
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
8 files changed, 19 insertions, 20 deletions
diff --git a/tests/auto/corelib/thread/qmutex/CMakeLists.txt b/tests/auto/corelib/thread/qmutex/CMakeLists.txt index 41b7b1da68..1412036fc9 100644 --- a/tests/auto/corelib/thread/qmutex/CMakeLists.txt +++ b/tests/auto/corelib/thread/qmutex/CMakeLists.txt @@ -7,12 +7,6 @@ qt_internal_add_test(tst_qmutex SOURCES tst_qmutex.cpp -) - -## Scopes: -##################################################################### - -qt_internal_extend_target(tst_qmutex CONDITION WIN32 PUBLIC_LIBRARIES Qt::CorePrivate ) diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index fb080a1a12..c00ddea908 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -36,6 +36,7 @@ #include <qmutex.h> #include <qthread.h> #include <qwaitcondition.h> +#include <private/qvolatile_p.h> class tst_QMutex : public QObject { @@ -1191,9 +1192,9 @@ void tst_QMutex::tryLockDeadlock() { for (int i = 0; i < 100000; ++i) { if (mut.tryLock(0)) { - if ((++tryLockDeadlockCounter) != 1) + if (QtPrivate::volatilePreIncrement(tryLockDeadlockCounter) != 1) ++tryLockDeadlockFailureCount; - if ((--tryLockDeadlockCounter) != 0) + if (QtPrivate::volatilePreDecrement(tryLockDeadlockCounter) != 0) ++tryLockDeadlockFailureCount; mut.unlock(); } @@ -1210,9 +1211,9 @@ void tst_QMutex::tryLockDeadlock() for (int i = 0; i < 100000; ++i) { mut.lock(); - if ((++tryLockDeadlockCounter) != 1) + if (QtPrivate::volatilePreIncrement(tryLockDeadlockCounter) != 1) ++tryLockDeadlockFailureCount; - if ((--tryLockDeadlockCounter) != 0) + if (QtPrivate::volatilePreDecrement(tryLockDeadlockCounter) != 0) ++tryLockDeadlockFailureCount; mut.unlock(); } diff --git a/tests/auto/corelib/thread/qreadwritelock/CMakeLists.txt b/tests/auto/corelib/thread/qreadwritelock/CMakeLists.txt index 4b81229024..a99001425e 100644 --- a/tests/auto/corelib/thread/qreadwritelock/CMakeLists.txt +++ b/tests/auto/corelib/thread/qreadwritelock/CMakeLists.txt @@ -7,4 +7,6 @@ qt_internal_add_test(tst_qreadwritelock SOURCES tst_qreadwritelock.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate ) diff --git a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp index ca282e2723..a6c0ebae22 100644 --- a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp +++ b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp @@ -34,6 +34,7 @@ #include <qmutex.h> #include <qthread.h> #include <qwaitcondition.h> +#include <private/qvolatile_p.h> #ifdef Q_OS_UNIX #include <unistd.h> @@ -587,12 +588,8 @@ public: if(count) qFatal("Non-zero count at start of write! (%d)",count ); // printf("."); - int i; - for(i=0; i<maxval; ++i) { - volatile int lc=count; - ++lc; - count=lc; - } + for (int i = 0; i < maxval; ++i) + QtPrivate::volatilePreIncrement(count); count=0; testRwlock.unlock(); msleep(ulong(waitTime)); diff --git a/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt b/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt index f43b83b819..d29f203bf9 100644 --- a/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt +++ b/tests/auto/corelib/tools/qsharedpointer/CMakeLists.txt @@ -8,4 +8,6 @@ qt_internal_add_test(tst_qsharedpointer nontracked.cpp wrapper.cpp tst_qsharedpointer.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate ) diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index e6e3329ed3..48464aff58 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -37,6 +37,7 @@ #include <QtCore/QList> #include <QtCore/QMap> #include <QtCore/QThread> +#include <QtCore/private/qvolatile_p.h> #include "forwarddeclared.h" #include "nontracked.h" @@ -1944,7 +1945,7 @@ class ThreadData QAtomicInt * volatile ptr; public: ThreadData(QAtomicInt *p) : ptr(p) { } - ~ThreadData() { ++ptr; } + ~ThreadData() { QtPrivate::volatilePreIncrement(ptr); } void ref() { // if we're called after the destructor, we'll crash diff --git a/tests/benchmarks/corelib/thread/qmutex/CMakeLists.txt b/tests/benchmarks/corelib/thread/qmutex/CMakeLists.txt index 8872a50227..923bfba117 100644 --- a/tests/benchmarks/corelib/thread/qmutex/CMakeLists.txt +++ b/tests/benchmarks/corelib/thread/qmutex/CMakeLists.txt @@ -8,6 +8,7 @@ qt_internal_add_benchmark(tst_bench_qmutex SOURCES tst_qmutex.cpp PUBLIC_LIBRARIES + Qt::CorePrivate Qt::Test ) diff --git a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp index 9cea995433..9b14cbca5d 100644 --- a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp @@ -28,6 +28,7 @@ #include <QtCore/QtCore> #include <QTest> +#include <QtCore/private/qvolatile_p.h> #include <math.h> @@ -158,7 +159,7 @@ void tst_QMutex::noThread() QBENCHMARK { count = 0; for (int i = 0; i < N; i++) { - count++; + QtPrivate::volatilePreIncrement(count); } } break; @@ -167,7 +168,7 @@ void tst_QMutex::noThread() count = 0; for (int i = 0; i < N; i++) { mtx.lock(); - count++; + QtPrivate::volatilePreIncrement(count); mtx.unlock(); } } @@ -177,7 +178,7 @@ void tst_QMutex::noThread() count = 0; for (int i = 0; i < N; i++) { QMutexLocker locker(&mtx); - count++; + QtPrivate::volatilePreIncrement(count); } } break; |