diff options
author | mread <qt-info@nokia.com> | 2011-02-17 15:05:57 (GMT) |
---|---|---|
committer | mread <qt-info@nokia.com> | 2011-03-09 12:47:42 (GMT) |
commit | 563c766ced47c1bfb25976e5a8b8668ed9ab0c53 (patch) | |
tree | a95c578485a620e590cb263c5e7fa2edb16395e1 /tests/benchmarks | |
parent | 3a9ed967f793abe5049c91217f47d63c9457c1db (diff) | |
download | Qt-563c766ced47c1bfb25976e5a8b8668ed9ab0c53.zip Qt-563c766ced47c1bfb25976e5a8b8668ed9ab0c53.tar.gz Qt-563c766ced47c1bfb25976e5a8b8668ed9ab0c53.tar.bz2 |
making the QWaitCondition benchmark more reliable
The benchmark sometimes hung because wait conditions were sometimes
signalled before being waited for. This change adds a real condition to
control the interactions.
Task-number: QTBUG-13990
Reviewed-by: Shane Kearns
Diffstat (limited to 'tests/benchmarks')
-rw-r--r-- | tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp b/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp index ae5b48e..1bfc637 100644 --- a/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp +++ b/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp @@ -63,10 +63,13 @@ private slots: public: static QWaitCondition local, remote; + enum Turn {LocalTurn, RemoteTurn}; + static Turn turn; }; QWaitCondition tst_QWaitCondition::local; QWaitCondition tst_QWaitCondition::remote; +tst_QWaitCondition::Turn tst_QWaitCondition::turn = tst_QWaitCondition::LocalTurn; class OscillateThread : public QThread { @@ -89,19 +92,22 @@ public: forever { if (m_done) break; - if (m_wakeOne) - tst_QWaitCondition::local.wakeOne(); - else - tst_QWaitCondition::local.wakeAll(); if (m_useMutex) { mtx.lock(); - tst_QWaitCondition::remote.wait(&mtx, m_timeout); + while (tst_QWaitCondition::turn == tst_QWaitCondition::LocalTurn) + tst_QWaitCondition::remote.wait(&mtx, m_timeout); mtx.unlock(); } else { rwl.lockForWrite(); - tst_QWaitCondition::remote.wait(&rwl, m_timeout); + while (tst_QWaitCondition::turn == tst_QWaitCondition::LocalTurn) + tst_QWaitCondition::remote.wait(&rwl, m_timeout); rwl.unlock(); } + tst_QWaitCondition::turn = tst_QWaitCondition::LocalTurn; + if (m_wakeOne) + tst_QWaitCondition::local.wakeOne(); + else + tst_QWaitCondition::local.wakeAll(); count++; } } @@ -132,6 +138,7 @@ void tst_QWaitCondition::oscillate() QFETCH(unsigned long, timeout); QFETCH(bool, wakeOne); + turn = LocalTurn; OscillateThread thrd(useMutex, timeout, wakeOne); thrd.start(); @@ -140,15 +147,18 @@ void tst_QWaitCondition::oscillate() mtx.lock(); else rwl.lockForWrite(); + turn = RemoteTurn; if (wakeOne) remote.wakeOne(); else remote.wakeAll(); if (useMutex) { - local.wait(&mtx, timeout); + while (turn == RemoteTurn) + local.wait(&mtx, timeout); mtx.unlock(); } else { - local.wait(&rwl, timeout); + while (turn == RemoteTurn) + local.wait(&rwl, timeout); rwl.unlock(); } } @@ -174,12 +184,14 @@ void tst_QWaitCondition::thrash() QFETCH(unsigned long, timeout); QFETCH(bool, wakeOne); + turn = LocalTurn; OscillateThread thrd(useMutex, timeout, wakeOne); thrd.start(); local.wait(&mtx, 1000ul); mtx.unlock(); QBENCHMARK { + turn = RemoteTurn; if (wakeOne) remote.wakeOne(); else @@ -187,6 +199,7 @@ void tst_QWaitCondition::thrash() } thrd.m_done = true; + turn = RemoteTurn; remote.wakeAll(); thrd.wait(); |