summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-05-23 21:27:07 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2013-05-23 21:27:07 +0200
commitd3a8bc803cd7c4ce106038bfc4b37cdd6bb8e177 (patch)
tree3b6db0d4869f334d0eb4559c5ae457995cbe913e /tests/auto/corelib/thread
parentd934ddc297f6db94dbc548fe01da64350f13577d (diff)
parent47a7628023610904c6ac52e23fa289f75f349b4e (diff)
Merge remote-tracking branch 'origin/stable' into dev
Conflicts: src/corelib/io/qdatastream.cpp src/corelib/io/qdatastream.h src/corelib/json/qjsonwriter.cpp src/plugins/platforms/cocoa/qcocoawindow.mm src/plugins/platforms/xcb/qxcbkeyboard.cpp Change-Id: I46fef1455f5a9f2ce1ec394a3c65881093c51b62
Diffstat (limited to 'tests/auto/corelib/thread')
-rw-r--r--tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
index 8a72ae5bce..fb34afb880 100644
--- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
+++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
@@ -94,6 +94,8 @@ private slots:
void tryStart();
void tryStartPeakThreadCount();
void tryStartCount();
+ void priorityStart_data();
+ void priorityStart();
void waitForDone();
void waitForDoneTimeout();
void destroyingWaitsForTasksToFinish();
@@ -747,6 +749,57 @@ void tst_QThreadPool::tryStartCount()
}
}
+void tst_QThreadPool::priorityStart_data()
+{
+ QTest::addColumn<int>("otherCount");
+ QTest::newRow("0") << 0;
+ QTest::newRow("1") << 1;
+ QTest::newRow("2") << 2;
+}
+
+void tst_QThreadPool::priorityStart()
+{
+ class Holder : public QRunnable
+ {
+ public:
+ QSemaphore &sem;
+ Holder(QSemaphore &sem) : sem(sem) {}
+ void run()
+ {
+ sem.acquire();
+ }
+ };
+ class Runner : public QRunnable
+ {
+ public:
+ QAtomicPointer<QRunnable> &ptr;
+ Runner(QAtomicPointer<QRunnable> &ptr) : ptr(ptr) {}
+ void run()
+ {
+ ptr.testAndSetRelaxed(0, this);
+ }
+ };
+
+ QFETCH(int, otherCount);
+ QSemaphore sem;
+ QAtomicPointer<QRunnable> firstStarted;
+ QRunnable *expected;
+ QThreadPool threadPool;
+ threadPool.setMaxThreadCount(1); // start only one thread at a time
+
+ // queue the holder first
+ // We need to be sure that all threads are active when we
+ // queue the two Runners
+ threadPool.start(new Holder(sem));
+ while (otherCount--)
+ threadPool.start(new Runner(firstStarted), 0); // priority 0
+ threadPool.start(expected = new Runner(firstStarted), 1); // priority 1
+
+ sem.release();
+ QVERIFY(threadPool.waitForDone());
+ QCOMPARE(firstStarted.load(), expected);
+}
+
void tst_QThreadPool::waitForDone()
{
QTime total, pass;