diff options
Diffstat (limited to 'tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp')
-rw-r--r-- | tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index 3c0e132a0a..fb34afb880 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -214,22 +214,22 @@ void tst_QThreadPool::waitcomplete() QCOMPARE(testFunctionCount, runs); } -volatile bool ran; +QAtomicInt ran; // bool class TestTask : public QRunnable { public: void run() { - ran = true; + ran.store(true); } }; void tst_QThreadPool::runTask() { QThreadPool manager; - ran = false; + ran.store(false); manager.start(new TestTask()); - QTRY_VERIFY(ran); + QTRY_VERIFY(ran.load()); } /* @@ -237,19 +237,19 @@ void tst_QThreadPool::runTask() */ void tst_QThreadPool::singleton() { - ran = false; + ran.store(false); QThreadPool::globalInstance()->start(new TestTask()); - QTRY_VERIFY(ran); + QTRY_VERIFY(ran.load()); } -int *value = 0; +QAtomicInt *value = 0; class IntAccessor : public QRunnable { public: void run() { for (int i = 0; i < 100; ++i) { - ++(*value); + value->ref(); QTest::qSleep(1); } } @@ -261,7 +261,7 @@ public: */ void tst_QThreadPool::destruction() { - value = new int; + value = new QAtomicInt; QThreadPool *threadManager = new QThreadPool(); threadManager->start(new IntAccessor()); threadManager->start(new IntAccessor()); @@ -681,8 +681,8 @@ void tst_QThreadPool::tryStart() } QMutex mutex; -int activeThreads = 0; -int peakActiveThreads = 0; +QAtomicInt activeThreads; +QAtomicInt peakActiveThreads; void tst_QThreadPool::tryStartPeakThreadCount() { class CounterTask : public QRunnable @@ -694,14 +694,14 @@ void tst_QThreadPool::tryStartPeakThreadCount() { { QMutexLocker lock(&mutex); - ++activeThreads; - peakActiveThreads = qMax(peakActiveThreads, activeThreads); + activeThreads.ref(); + peakActiveThreads.store(qMax(peakActiveThreads.load(), activeThreads.load())); } QTest::qWait(100); { QMutexLocker lock(&mutex); - --activeThreads; + activeThreads.deref(); } } }; @@ -713,13 +713,13 @@ void tst_QThreadPool::tryStartPeakThreadCount() if (threadPool.tryStart(&task) == false) QTest::qWait(10); } - QCOMPARE(peakActiveThreads, QThread::idealThreadCount()); + QCOMPARE(peakActiveThreads.load(), QThread::idealThreadCount()); for (int i = 0; i < 20; ++i) { if (threadPool.tryStart(&task) == false) QTest::qWait(10); } - QCOMPARE(peakActiveThreads, QThread::idealThreadCount()); + QCOMPARE(peakActiveThreads.load(), QThread::idealThreadCount()); } void tst_QThreadPool::tryStartCount() |