summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2012-03-09 14:11:26 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-12 13:14:05 +0100
commitc4342ddea083baf0ba7a22df6ce672f0fbcc04c2 (patch)
tree4a27be5d6dd2b342e52544e72f3214783169c4da /tests/auto
parent3d8e3421a5f4466b98f1747c7b72c8750a7688a7 (diff)
Fix indentation of QWaitCondition autotest.
No functional changes - cosmetic change only. Change-Id: I7332eaab31720776c70a7ef813d55db44bab83f7 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp703
1 files changed, 351 insertions, 352 deletions
diff --git a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp
index 0e1fa47a3e..a9fbde8037 100644
--- a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp
+++ b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp
@@ -73,10 +73,10 @@ public:
void run()
{
- mutex.lock();
- cond.wakeOne();
- cond.wait(&mutex);
- mutex.unlock();
+ mutex.lock();
+ cond.wakeOne();
+ cond.wait(&mutex);
+ mutex.unlock();
}
};
@@ -94,10 +94,10 @@ public:
void run()
{
- mutex->lock();
- started.wakeOne();
- cond->wait(mutex);
- mutex->unlock();
+ mutex->lock();
+ started.wakeOne();
+ cond->wait(mutex);
+ mutex->unlock();
}
};
@@ -112,10 +112,10 @@ public:
void run()
{
- readWriteLock.lockForWrite();
- cond.wakeOne();
- cond.wait(&readWriteLock);
- readWriteLock.unlock();
+ readWriteLock.lockForWrite();
+ cond.wakeOne();
+ cond.wait(&readWriteLock);
+ readWriteLock.unlock();
}
};
@@ -133,10 +133,10 @@ public:
void run()
{
- readWriteLock->lockForRead();
- started.wakeOne();
- cond->wait(readWriteLock);
- readWriteLock->unlock();
+ readWriteLock->lockForRead();
+ started.wakeOne();
+ cond->wait(readWriteLock);
+ readWriteLock->unlock();
}
};
@@ -144,80 +144,80 @@ void tst_QWaitCondition::wait_QMutex()
{
int x;
for (int i = 0; i < iterations; ++i) {
- {
- QMutex mutex;
- QWaitCondition cond;
-
- mutex.lock();
+ {
+ QMutex mutex;
+ QWaitCondition cond;
- cond.wakeOne();
- QVERIFY(!cond.wait(&mutex, 1));
-
- cond.wakeAll();
- QVERIFY(!cond.wait(&mutex, 1));
+ mutex.lock();
- mutex.unlock();
- }
+ cond.wakeOne();
+ QVERIFY(!cond.wait(&mutex, 1));
- {
- // test multiple threads waiting on separate wait conditions
- wait_QMutex_Thread_1 thread[ThreadCount];
+ cond.wakeAll();
+ QVERIFY(!cond.wait(&mutex, 1));
- for (x = 0; x < ThreadCount; ++x) {
- thread[x].mutex.lock();
- thread[x].start();
- // wait for thread to start
- QVERIFY(thread[x].cond.wait(&thread[x].mutex, 1000));
- thread[x].mutex.unlock();
+ mutex.unlock();
}
- for (x = 0; x < ThreadCount; ++x) {
- QVERIFY(thread[x].isRunning());
- QVERIFY(!thread[x].isFinished());
- }
+ {
+ // test multiple threads waiting on separate wait conditions
+ wait_QMutex_Thread_1 thread[ThreadCount];
- for (x = 0; x < ThreadCount; ++x) {
- thread[x].mutex.lock();
- thread[x].cond.wakeOne();
- thread[x].mutex.unlock();
- }
+ for (x = 0; x < ThreadCount; ++x) {
+ thread[x].mutex.lock();
+ thread[x].start();
+ // wait for thread to start
+ QVERIFY(thread[x].cond.wait(&thread[x].mutex, 1000));
+ thread[x].mutex.unlock();
+ }
- for (x = 0; x < ThreadCount; ++x) {
- QVERIFY(thread[x].wait(1000));
- }
- }
+ for (x = 0; x < ThreadCount; ++x) {
+ QVERIFY(thread[x].isRunning());
+ QVERIFY(!thread[x].isFinished());
+ }
- {
- // test multiple threads waiting on a wait condition
- QMutex mutex;
- QWaitCondition cond1, cond2;
- wait_QMutex_Thread_2 thread[ThreadCount];
+ for (x = 0; x < ThreadCount; ++x) {
+ thread[x].mutex.lock();
+ thread[x].cond.wakeOne();
+ thread[x].mutex.unlock();
+ }
- mutex.lock();
- for (x = 0; x < ThreadCount; ++x) {
- thread[x].mutex = &mutex;
- thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2;
- thread[x].start();
- // wait for thread to start
- QVERIFY(thread[x].started.wait(&mutex, 1000));
+ for (x = 0; x < ThreadCount; ++x) {
+ QVERIFY(thread[x].wait(1000));
+ }
}
- mutex.unlock();
- for (x = 0; x < ThreadCount; ++x) {
- QVERIFY(thread[x].isRunning());
- QVERIFY(!thread[x].isFinished());
- }
+ {
+ // test multiple threads waiting on a wait condition
+ QMutex mutex;
+ QWaitCondition cond1, cond2;
+ wait_QMutex_Thread_2 thread[ThreadCount];
+
+ mutex.lock();
+ for (x = 0; x < ThreadCount; ++x) {
+ thread[x].mutex = &mutex;
+ thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2;
+ thread[x].start();
+ // wait for thread to start
+ QVERIFY(thread[x].started.wait(&mutex, 1000));
+ }
+ mutex.unlock();
- mutex.lock();
- cond1.wakeAll();
- cond2.wakeAll();
- mutex.unlock();
+ for (x = 0; x < ThreadCount; ++x) {
+ QVERIFY(thread[x].isRunning());
+ QVERIFY(!thread[x].isFinished());
+ }
- for (x = 0; x < ThreadCount; ++x) {
- QVERIFY(thread[x].wait(1000));
+ mutex.lock();
+ cond1.wakeAll();
+ cond2.wakeAll();
+ mutex.unlock();
+
+ for (x = 0; x < ThreadCount; ++x) {
+ QVERIFY(thread[x].wait(1000));
+ }
}
}
- }
}
void tst_QWaitCondition::wait_QReadWriteLock()
@@ -263,96 +263,95 @@ void tst_QWaitCondition::wait_QReadWriteLock()
int x;
for (int i = 0; i < iterations; ++i) {
- {
- QReadWriteLock readWriteLock;
- QWaitCondition waitCondition;
+ {
+ QReadWriteLock readWriteLock;
+ QWaitCondition waitCondition;
- readWriteLock.lockForRead();
+ readWriteLock.lockForRead();
- waitCondition.wakeOne();
- QVERIFY(!waitCondition.wait(&readWriteLock, 1));
-
- waitCondition.wakeAll();
- QVERIFY(!waitCondition.wait(&readWriteLock, 1));
+ waitCondition.wakeOne();
+ QVERIFY(!waitCondition.wait(&readWriteLock, 1));
- readWriteLock.unlock();
- }
-
- {
- QReadWriteLock readWriteLock;
- QWaitCondition waitCondition;
+ waitCondition.wakeAll();
+ QVERIFY(!waitCondition.wait(&readWriteLock, 1));
- readWriteLock.lockForWrite();
+ readWriteLock.unlock();
+ }
- waitCondition.wakeOne();
- QVERIFY(!waitCondition.wait(&readWriteLock, 1));
+ {
+ QReadWriteLock readWriteLock;
+ QWaitCondition waitCondition;
- waitCondition.wakeAll();
- QVERIFY(!waitCondition.wait(&readWriteLock, 1));
+ readWriteLock.lockForWrite();
- readWriteLock.unlock();
- }
+ waitCondition.wakeOne();
+ QVERIFY(!waitCondition.wait(&readWriteLock, 1));
- {
- // test multiple threads waiting on separate wait conditions
- wait_QReadWriteLock_Thread_1 thread[ThreadCount];
+ waitCondition.wakeAll();
+ QVERIFY(!waitCondition.wait(&readWriteLock, 1));
- for (x = 0; x < ThreadCount; ++x) {
- thread[x].readWriteLock.lockForRead();
- thread[x].start();
- // wait for thread to start
- QVERIFY(thread[x].cond.wait(&thread[x].readWriteLock, 1000));
- thread[x].readWriteLock.unlock();
+ readWriteLock.unlock();
}
- for (x = 0; x < ThreadCount; ++x) {
- QVERIFY(thread[x].isRunning());
- QVERIFY(!thread[x].isFinished());
- }
+ {
+ // test multiple threads waiting on separate wait conditions
+ wait_QReadWriteLock_Thread_1 thread[ThreadCount];
- for (x = 0; x < ThreadCount; ++x) {
- thread[x].readWriteLock.lockForRead();
- thread[x].cond.wakeOne();
- thread[x].readWriteLock.unlock();
- }
+ for (x = 0; x < ThreadCount; ++x) {
+ thread[x].readWriteLock.lockForRead();
+ thread[x].start();
+ // wait for thread to start
+ QVERIFY(thread[x].cond.wait(&thread[x].readWriteLock, 1000));
+ thread[x].readWriteLock.unlock();
+ }
- for (x = 0; x < ThreadCount; ++x) {
- QVERIFY(thread[x].wait(1000));
- }
- }
+ for (x = 0; x < ThreadCount; ++x) {
+ QVERIFY(thread[x].isRunning());
+ QVERIFY(!thread[x].isFinished());
+ }
- {
- // test multiple threads waiting on a wait condition
- QReadWriteLock readWriteLock;
- QWaitCondition cond1, cond2;
- wait_QReadWriteLock_Thread_2 thread[ThreadCount];
+ for (x = 0; x < ThreadCount; ++x) {
+ thread[x].readWriteLock.lockForRead();
+ thread[x].cond.wakeOne();
+ thread[x].readWriteLock.unlock();
+ }
- readWriteLock.lockForWrite();
- for (x = 0; x < ThreadCount; ++x) {
- thread[x].readWriteLock = &readWriteLock;
- thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2;
- thread[x].start();
- // wait for thread to start
- QVERIFY(thread[x].started.wait(&readWriteLock, 1000));
+ for (x = 0; x < ThreadCount; ++x) {
+ QVERIFY(thread[x].wait(1000));
+ }
}
- readWriteLock.unlock();
- for (x = 0; x < ThreadCount; ++x) {
- QVERIFY(thread[x].isRunning());
- QVERIFY(!thread[x].isFinished());
- }
+ {
+ // test multiple threads waiting on a wait condition
+ QReadWriteLock readWriteLock;
+ QWaitCondition cond1, cond2;
+ wait_QReadWriteLock_Thread_2 thread[ThreadCount];
+
+ readWriteLock.lockForWrite();
+ for (x = 0; x < ThreadCount; ++x) {
+ thread[x].readWriteLock = &readWriteLock;
+ thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2;
+ thread[x].start();
+ // wait for thread to start
+ QVERIFY(thread[x].started.wait(&readWriteLock, 1000));
+ }
+ readWriteLock.unlock();
- readWriteLock.lockForWrite();
- cond1.wakeAll();
- cond2.wakeAll();
- readWriteLock.unlock();
+ for (x = 0; x < ThreadCount; ++x) {
+ QVERIFY(thread[x].isRunning());
+ QVERIFY(!thread[x].isFinished());
+ }
- for (x = 0; x < ThreadCount; ++x) {
- QVERIFY(thread[x].wait(1000));
+ readWriteLock.lockForWrite();
+ cond1.wakeAll();
+ cond2.wakeAll();
+ readWriteLock.unlock();
+
+ for (x = 0; x < ThreadCount; ++x) {
+ QVERIFY(thread[x].wait(1000));
+ }
}
}
- }
-
}
class wake_Thread : public QThread
@@ -375,14 +374,14 @@ public:
void run()
{
- mutex->lock();
- ++count;
+ mutex->lock();
+ ++count;
dummy.wakeOne(); // this wakeup should be lost
- started.wakeOne();
+ started.wakeOne();
dummy.wakeAll(); // this one too
- cond->wait(mutex);
+ cond->wait(mutex);
--count;
- mutex->unlock();
+ mutex->unlock();
}
};
@@ -408,14 +407,14 @@ public:
void run()
{
- readWriteLock->lockForWrite();
- ++count;
+ readWriteLock->lockForWrite();
+ ++count;
dummy.wakeOne(); // this wakeup should be lost
started.wakeOne();
dummy.wakeAll(); // this one too
- cond->wait(readWriteLock);
+ cond->wait(readWriteLock);
--count;
- readWriteLock->unlock();
+ readWriteLock->unlock();
}
};
@@ -426,264 +425,264 @@ void tst_QWaitCondition::wakeOne()
int x;
// wake up threads, one at a time
for (int i = 0; i < iterations; ++i) {
- QMutex mutex;
- QWaitCondition cond;
-
- // QMutex
- wake_Thread thread[ThreadCount];
- bool thread_exited[ThreadCount];
-
- mutex.lock();
- for (x = 0; x < ThreadCount; ++x) {
- thread[x].mutex = &mutex;
- thread[x].cond = &cond;
- thread_exited[x] = false;
- thread[x].start();
- // wait for thread to start
- QVERIFY(thread[x].started.wait(&mutex, 1000));
- // make sure wakeups are not queued... if nothing is
- // waiting at the time of the wakeup, nothing happens
- QVERIFY(!thread[x].dummy.wait(&mutex, 1));
- }
- mutex.unlock();
+ QMutex mutex;
+ QWaitCondition cond;
- QCOMPARE(wake_Thread::count, ThreadCount);
+ // QMutex
+ wake_Thread thread[ThreadCount];
+ bool thread_exited[ThreadCount];
- // wake up threads one at a time
- for (x = 0; x < ThreadCount; ++x) {
mutex.lock();
- cond.wakeOne();
- QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME));
- QVERIFY(!thread[x].dummy.wait(&mutex, 1));
+ for (x = 0; x < ThreadCount; ++x) {
+ thread[x].mutex = &mutex;
+ thread[x].cond = &cond;
+ thread_exited[x] = false;
+ thread[x].start();
+ // wait for thread to start
+ QVERIFY(thread[x].started.wait(&mutex, 1000));
+ // make sure wakeups are not queued... if nothing is
+ // waiting at the time of the wakeup, nothing happens
+ QVERIFY(!thread[x].dummy.wait(&mutex, 1));
+ }
mutex.unlock();
- int exited = 0;
- for (int y = 0; y < ThreadCount; ++y) {
- if (thread_exited[y])
- continue;
- if (thread[y].wait(exited > 0 ? 10 : 1000)) {
- thread_exited[y] = true;
- ++exited;
- }
- }
+ QCOMPARE(wake_Thread::count, ThreadCount);
- QCOMPARE(exited, 1);
- QCOMPARE(wake_Thread::count, ThreadCount - (x + 1));
- }
+ // wake up threads one at a time
+ for (x = 0; x < ThreadCount; ++x) {
+ mutex.lock();
+ cond.wakeOne();
+ QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME));
+ QVERIFY(!thread[x].dummy.wait(&mutex, 1));
+ mutex.unlock();
+
+ int exited = 0;
+ for (int y = 0; y < ThreadCount; ++y) {
+ if (thread_exited[y])
+ continue;
+ if (thread[y].wait(exited > 0 ? 10 : 1000)) {
+ thread_exited[y] = true;
+ ++exited;
+ }
+ }
- QCOMPARE(wake_Thread::count, 0);
+ QCOMPARE(exited, 1);
+ QCOMPARE(wake_Thread::count, ThreadCount - (x + 1));
+ }
- // QReadWriteLock
- QReadWriteLock readWriteLock;
- wake_Thread_2 rwthread[ThreadCount];
-
- readWriteLock.lockForWrite();
- for (x = 0; x < ThreadCount; ++x) {
- rwthread[x].readWriteLock = &readWriteLock;
- rwthread[x].cond = &cond;
- thread_exited[x] = false;
- rwthread[x].start();
- // wait for thread to start
- QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000));
- // make sure wakeups are not queued... if nothing is
- // waiting at the time of the wakeup, nothing happens
- QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
- }
- readWriteLock.unlock();
+ QCOMPARE(wake_Thread::count, 0);
- QCOMPARE(wake_Thread_2::count, ThreadCount);
+ // QReadWriteLock
+ QReadWriteLock readWriteLock;
+ wake_Thread_2 rwthread[ThreadCount];
- // wake up threads one at a time
- for (x = 0; x < ThreadCount; ++x) {
readWriteLock.lockForWrite();
- cond.wakeOne();
- QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME));
- QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
+ for (x = 0; x < ThreadCount; ++x) {
+ rwthread[x].readWriteLock = &readWriteLock;
+ rwthread[x].cond = &cond;
+ thread_exited[x] = false;
+ rwthread[x].start();
+ // wait for thread to start
+ QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000));
+ // make sure wakeups are not queued... if nothing is
+ // waiting at the time of the wakeup, nothing happens
+ QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
+ }
readWriteLock.unlock();
- int exited = 0;
- for (int y = 0; y < ThreadCount; ++y) {
- if (thread_exited[y])
- continue;
- if (rwthread[y].wait(exited > 0 ? 10 : 1000)) {
- thread_exited[y] = true;
- ++exited;
+ QCOMPARE(wake_Thread_2::count, ThreadCount);
+
+ // wake up threads one at a time
+ for (x = 0; x < ThreadCount; ++x) {
+ readWriteLock.lockForWrite();
+ cond.wakeOne();
+ QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME));
+ QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
+ readWriteLock.unlock();
+
+ int exited = 0;
+ for (int y = 0; y < ThreadCount; ++y) {
+ if (thread_exited[y])
+ continue;
+ if (rwthread[y].wait(exited > 0 ? 10 : 1000)) {
+ thread_exited[y] = true;
+ ++exited;
+ }
}
- }
- QCOMPARE(exited, 1);
- QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 1));
- }
+ QCOMPARE(exited, 1);
+ QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 1));
+ }
- QCOMPARE(wake_Thread_2::count, 0);
+ QCOMPARE(wake_Thread_2::count, 0);
}
// wake up threads, two at a time
for (int i = 0; i < iterations; ++i) {
- QMutex mutex;
- QWaitCondition cond;
+ QMutex mutex;
+ QWaitCondition cond;
// QMutex
- wake_Thread thread[ThreadCount];
- bool thread_exited[ThreadCount];
-
- mutex.lock();
- for (x = 0; x < ThreadCount; ++x) {
- thread[x].mutex = &mutex;
- thread[x].cond = &cond;
- thread_exited[x] = false;
- thread[x].start();
- // wait for thread to start
- QVERIFY(thread[x].started.wait(&mutex, 1000));
- // make sure wakeups are not queued... if nothing is
- // waiting at the time of the wakeup, nothing happens
- QVERIFY(!thread[x].dummy.wait(&mutex, 1));
- }
- mutex.unlock();
-
- QCOMPARE(wake_Thread::count, ThreadCount);
+ wake_Thread thread[ThreadCount];
+ bool thread_exited[ThreadCount];
- // wake up threads one at a time
- for (x = 0; x < ThreadCount; x += 2) {
mutex.lock();
- cond.wakeOne();
- cond.wakeOne();
- QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME));
- QVERIFY(!thread[x].dummy.wait(&mutex, 1));
- QVERIFY(!thread[x + 1].dummy.wait(&mutex, 1));
+ for (x = 0; x < ThreadCount; ++x) {
+ thread[x].mutex = &mutex;
+ thread[x].cond = &cond;
+ thread_exited[x] = false;
+ thread[x].start();
+ // wait for thread to start
+ QVERIFY(thread[x].started.wait(&mutex, 1000));
+ // make sure wakeups are not queued... if nothing is
+ // waiting at the time of the wakeup, nothing happens
+ QVERIFY(!thread[x].dummy.wait(&mutex, 1));
+ }
mutex.unlock();
- int exited = 0;
- for (int y = 0; y < ThreadCount; ++y) {
- if (thread_exited[y])
- continue;
- if (thread[y].wait(exited > 0 ? 10 : 1000)) {
- thread_exited[y] = true;
- ++exited;
+ QCOMPARE(wake_Thread::count, ThreadCount);
+
+ // wake up threads one at a time
+ for (x = 0; x < ThreadCount; x += 2) {
+ mutex.lock();
+ cond.wakeOne();
+ cond.wakeOne();
+ QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME));
+ QVERIFY(!thread[x].dummy.wait(&mutex, 1));
+ QVERIFY(!thread[x + 1].dummy.wait(&mutex, 1));
+ mutex.unlock();
+
+ int exited = 0;
+ for (int y = 0; y < ThreadCount; ++y) {
+ if (thread_exited[y])
+ continue;
+ if (thread[y].wait(exited > 0 ? 10 : 1000)) {
+ thread_exited[y] = true;
+ ++exited;
+ }
}
- }
- QCOMPARE(exited, 2);
- QCOMPARE(wake_Thread::count, ThreadCount - (x + 2));
- }
+ QCOMPARE(exited, 2);
+ QCOMPARE(wake_Thread::count, ThreadCount - (x + 2));
+ }
- QCOMPARE(wake_Thread::count, 0);
+ QCOMPARE(wake_Thread::count, 0);
// QReadWriteLock
QReadWriteLock readWriteLock;
wake_Thread_2 rwthread[ThreadCount];
- readWriteLock.lockForWrite();
- for (x = 0; x < ThreadCount; ++x) {
- rwthread[x].readWriteLock = &readWriteLock;
- rwthread[x].cond = &cond;
- thread_exited[x] = false;
- rwthread[x].start();
- // wait for thread to start
- QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000));
- // make sure wakeups are not queued... if nothing is
- // waiting at the time of the wakeup, nothing happens
- QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
- }
- readWriteLock.unlock();
-
- QCOMPARE(wake_Thread_2::count, ThreadCount);
-
- // wake up threads one at a time
- for (x = 0; x < ThreadCount; x += 2) {
readWriteLock.lockForWrite();
- cond.wakeOne();
- cond.wakeOne();
- QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME));
- QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
- QVERIFY(!rwthread[x + 1].dummy.wait(&readWriteLock, 1));
+ for (x = 0; x < ThreadCount; ++x) {
+ rwthread[x].readWriteLock = &readWriteLock;
+ rwthread[x].cond = &cond;
+ thread_exited[x] = false;
+ rwthread[x].start();
+ // wait for thread to start
+ QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000));
+ // make sure wakeups are not queued... if nothing is
+ // waiting at the time of the wakeup, nothing happens
+ QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
+ }
readWriteLock.unlock();
- int exited = 0;
- for (int y = 0; y < ThreadCount; ++y) {
- if (thread_exited[y])
- continue;
- if (rwthread[y].wait(exited > 0 ? 10 : 1000)) {
- thread_exited[y] = true;
- ++exited;
+ QCOMPARE(wake_Thread_2::count, ThreadCount);
+
+ // wake up threads one at a time
+ for (x = 0; x < ThreadCount; x += 2) {
+ readWriteLock.lockForWrite();
+ cond.wakeOne();
+ cond.wakeOne();
+ QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME));
+ QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
+ QVERIFY(!rwthread[x + 1].dummy.wait(&readWriteLock, 1));
+ readWriteLock.unlock();
+
+ int exited = 0;
+ for (int y = 0; y < ThreadCount; ++y) {
+ if (thread_exited[y])
+ continue;
+ if (rwthread[y].wait(exited > 0 ? 10 : 1000)) {
+ thread_exited[y] = true;
+ ++exited;
+ }
}
+
+ QCOMPARE(exited, 2);
+ QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 2));
}
- QCOMPARE(exited, 2);
- QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 2));
+ QCOMPARE(wake_Thread_2::count, 0);
}
-
- QCOMPARE(wake_Thread_2::count, 0);
-}
}
void tst_QWaitCondition::wakeAll()
{
int x;
for (int i = 0; i < iterations; ++i) {
- QMutex mutex;
- QWaitCondition cond;
+ QMutex mutex;
+ QWaitCondition cond;
- // QMutex
- wake_Thread thread[ThreadCount];
+ // QMutex
+ wake_Thread thread[ThreadCount];
- mutex.lock();
- for (x = 0; x < ThreadCount; ++x) {
- thread[x].mutex = &mutex;
- thread[x].cond = &cond;
- thread[x].start();
- // wait for thread to start
- QVERIFY(thread[x].started.wait(&mutex, 1000));
- }
- mutex.unlock();
+ mutex.lock();
+ for (x = 0; x < ThreadCount; ++x) {
+ thread[x].mutex = &mutex;
+ thread[x].cond = &cond;
+ thread[x].start();
+ // wait for thread to start
+ QVERIFY(thread[x].started.wait(&mutex, 1000));
+ }
+ mutex.unlock();
- QCOMPARE(wake_Thread::count, ThreadCount);
+ QCOMPARE(wake_Thread::count, ThreadCount);
- // wake up all threads at once
- mutex.lock();
- cond.wakeAll();
- QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME));
- mutex.unlock();
+ // wake up all threads at once
+ mutex.lock();
+ cond.wakeAll();
+ QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME));
+ mutex.unlock();
- int exited = 0;
- for (x = 0; x < ThreadCount; ++x) {
- if (thread[x].wait(1000))
- ++exited;
- }
+ int exited = 0;
+ for (x = 0; x < ThreadCount; ++x) {
+ if (thread[x].wait(1000))
+ ++exited;
+ }
- QCOMPARE(exited, ThreadCount);
- QCOMPARE(wake_Thread::count, 0);
+ QCOMPARE(exited, ThreadCount);
+ QCOMPARE(wake_Thread::count, 0);
- // QReadWriteLock
- QReadWriteLock readWriteLock;
- wake_Thread_2 rwthread[ThreadCount];
-
- readWriteLock.lockForWrite();
- for (x = 0; x < ThreadCount; ++x) {
- rwthread[x].readWriteLock = &readWriteLock;
- rwthread[x].cond = &cond;
- rwthread[x].start();
- // wait for thread to start
- QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000));
- }
- readWriteLock.unlock();
+ // QReadWriteLock
+ QReadWriteLock readWriteLock;
+ wake_Thread_2 rwthread[ThreadCount];
- QCOMPARE(wake_Thread_2::count, ThreadCount);
+ readWriteLock.lockForWrite();
+ for (x = 0; x < ThreadCount; ++x) {
+ rwthread[x].readWriteLock = &readWriteLock;
+ rwthread[x].cond = &cond;
+ rwthread[x].start();
+ // wait for thread to start
+ QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000));
+ }
+ readWriteLock.unlock();
- // wake up all threads at once
- readWriteLock.lockForWrite();
- cond.wakeAll();
- QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME));
- readWriteLock.unlock();
+ QCOMPARE(wake_Thread_2::count, ThreadCount);
- exited = 0;
- for (x = 0; x < ThreadCount; ++x) {
- if (rwthread[x].wait(1000))
- ++exited;
- }
+ // wake up all threads at once
+ readWriteLock.lockForWrite();
+ cond.wakeAll();
+ QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME));
+ readWriteLock.unlock();
+
+ exited = 0;
+ for (x = 0; x < ThreadCount; ++x) {
+ if (rwthread[x].wait(1000))
+ ++exited;
+ }
- QCOMPARE(exited, ThreadCount);
- QCOMPARE(wake_Thread_2::count, 0);
+ QCOMPARE(exited, ThreadCount);
+ QCOMPARE(wake_Thread_2::count, 0);
}
}