diff options
Diffstat (limited to 'tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp')
-rw-r--r-- | tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp b/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp index ff651eebae..6ea0c25c0b 100644 --- a/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp +++ b/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QtCore> #include <QTest> @@ -9,6 +9,8 @@ //#define USE_SEM_T +using namespace std::chrono_literals; + #if defined(Q_OS_UNIX) #if !defined(USE_SEM_T) # include <pthread.h> @@ -51,9 +53,6 @@ void NativeMutexUnlock(NativeMutexType *mutex) } #endif #elif defined(Q_OS_WIN) -# if !defined(_WIN32_WINNT) -# define _WIN32_WINNT 0x0A00 -# endif # include <qt_windows.h> typedef CRITICAL_SECTION NativeMutexType; void NativeMutexInitialize(NativeMutexType *mutex) @@ -231,7 +230,8 @@ void tst_QMutex::contendedNative_data() class NativeMutexThread : public QThread { NativeMutexType *mutex1, *mutex2; - int iterations, msleepDuration; + int iterations; + std::chrono::milliseconds msleepDuration; bool use2mutexes; public: bool done; @@ -249,8 +249,8 @@ public: NativeMutexLock(mutex1); if (use2mutexes) NativeMutexLock(mutex2); - if (msleepDuration >= 0) - msleep(msleepDuration); + if (msleepDuration >= 0ms) + sleep(msleepDuration); if (use2mutexes) NativeMutexUnlock(mutex2); NativeMutexUnlock(mutex1); @@ -274,7 +274,7 @@ void tst_QMutex::contendedNative() NativeMutexInitialize(&mutex2); QList<NativeMutexThread *> threads(threadCount); - for (int i = 0; i < threads.count(); ++i) { + for (int i = 0; i < threads.size(); ++i) { threads[i] = new NativeMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); threads[i]->start(); } @@ -286,11 +286,11 @@ void tst_QMutex::contendedNative() semaphore4.release(threadCount); } - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->done = true; semaphore1.acquire(threadCount); semaphore2.release(threadCount); - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->wait(); qDeleteAll(threads); @@ -301,7 +301,8 @@ void tst_QMutex::contendedNative() class QMutexThread : public QThread { QMutex *mutex1, *mutex2; - int iterations, msleepDuration; + int iterations; + std::chrono::milliseconds msleepDuration; bool use2mutexes; public: bool done; @@ -319,8 +320,8 @@ public: mutex1->lock(); if (use2mutexes) mutex2->lock(); - if (msleepDuration >= 0) - msleep(msleepDuration); + if (msleepDuration >= 0ms) + sleep(msleepDuration); if (use2mutexes) mutex2->unlock(); mutex1->unlock(); @@ -342,7 +343,7 @@ void tst_QMutex::contendedQMutex() QMutex mutex1, mutex2; QList<QMutexThread *> threads(threadCount); - for (int i = 0; i < threads.count(); ++i) { + for (int i = 0; i < threads.size(); ++i) { threads[i] = new QMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); threads[i]->start(); } @@ -354,11 +355,11 @@ void tst_QMutex::contendedQMutex() semaphore4.release(threadCount); } - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->done = true; semaphore1.acquire(threadCount); semaphore2.release(threadCount); - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->wait(); qDeleteAll(threads); } @@ -366,7 +367,8 @@ void tst_QMutex::contendedQMutex() class QMutexLockerThread : public QThread { QMutex *mutex1, *mutex2; - int iterations, msleepDuration; + int iterations; + std::chrono::milliseconds msleepDuration; bool use2mutexes; public: bool done; @@ -384,8 +386,8 @@ public: { QMutexLocker locker1(mutex1); QMutexLocker locker2(use2mutexes ? mutex2 : 0); - if (msleepDuration >= 0) - msleep(msleepDuration); + if (msleepDuration >= 0ms) + sleep(msleepDuration); } QThread::yieldCurrentThread(); @@ -405,7 +407,7 @@ void tst_QMutex::contendedQMutexLocker() QMutex mutex1, mutex2; QList<QMutexLockerThread *> threads(threadCount); - for (int i = 0; i < threads.count(); ++i) { + for (int i = 0; i < threads.size(); ++i) { threads[i] = new QMutexLockerThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); threads[i]->start(); } @@ -417,11 +419,11 @@ void tst_QMutex::contendedQMutexLocker() semaphore4.release(threadCount); } - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->done = true; semaphore1.acquire(threadCount); semaphore2.release(threadCount); - for (int i = 0; i < threads.count(); ++i) + for (int i = 0; i < threads.size(); ++i) threads[i]->wait(); qDeleteAll(threads); } |