summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2021-06-10 17:38:27 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2021-07-08 10:12:35 +0200
commit4d6752e8d2ed9d303befe7adf7f6e4b6ba16bbb9 (patch)
tree329526a872dd9e801a95a2c256ed4d1cb5f7a25b
parent2a3425cb49eff0753feae3b41bc36655e30b0372 (diff)
Remove the dead code for blocking methods from QtConcurrent
After 79fd1cb2c631b6084bf10874205d27f5b53c907a the methods for running QtConcurrent algorithms in the blocking mode aren't used anymore. Since ThreadEngineBase and ThreadEngineStarter classes aren't meant to be used externally, it should be fine to remove startBlocking() methods now. Removed the unused code and adjusted the tests accordingly. Change-Id: Ifb13820ce207869d6f720bcb5be8d35bb355fe33 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> (cherry picked from commit 1bf75f2a661c05c7f1126187310d7df3f9704af5)
-rw-r--r--src/concurrent/qtconcurrentthreadengine.cpp33
-rw-r--r--src/concurrent/qtconcurrentthreadengine.h23
-rw-r--r--tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp22
-rw-r--r--tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp112
4 files changed, 28 insertions, 162 deletions
diff --git a/src/concurrent/qtconcurrentthreadengine.cpp b/src/concurrent/qtconcurrentthreadengine.cpp
index 4679bd7e5c..e533ae9f9e 100644
--- a/src/concurrent/qtconcurrentthreadengine.cpp
+++ b/src/concurrent/qtconcurrentthreadengine.cpp
@@ -176,39 +176,6 @@ void ThreadEngineBase::startSingleThreaded()
finish();
}
-void ThreadEngineBase::startBlocking()
-{
- start();
- barrier.acquire();
- startThreads();
-
- bool throttled = false;
-#ifndef QT_NO_EXCEPTIONS
- try {
-#endif
- while (threadFunction() == ThrottleThread) {
- if (threadThrottleExit()) {
- throttled = true;
- break;
- }
- }
-#ifndef QT_NO_EXCEPTIONS
- } catch (QException &e) {
- handleException(e);
- } catch (...) {
- handleException(QUnhandledException());
- }
-#endif
-
- if (throttled == false) {
- barrier.release();
- }
-
- barrier.wait();
- finish();
- exceptionStore.throwPossibleException();
-}
-
void ThreadEngineBase::startThread()
{
startThreadInternal();
diff --git a/src/concurrent/qtconcurrentthreadengine.h b/src/concurrent/qtconcurrentthreadengine.h
index 6176221961..1baf8e5b19 100644
--- a/src/concurrent/qtconcurrentthreadengine.h
+++ b/src/concurrent/qtconcurrentthreadengine.h
@@ -91,7 +91,6 @@ public:
ThreadEngineBase();
virtual ~ThreadEngineBase();
void startSingleThreaded();
- void startBlocking();
void startThread();
bool isCanceled();
void waitForResume();
@@ -145,15 +144,6 @@ public:
}
// Runs the user algorithm using multiple threads.
- // This function blocks until the algorithm is finished,
- // and then returns the result.
- T *startBlocking()
- {
- ThreadEngineBase::startBlocking();
- return result();
- }
-
- // Runs the user algorithm using multiple threads.
// Does not block, returns a future.
QFuture<T> startAsynchronously()
{
@@ -233,13 +223,6 @@ class ThreadEngineStarter : public ThreadEngineStarterBase<T>
public:
ThreadEngineStarter(TypedThreadEngine *eng)
: Base(eng) { }
-
- T startBlocking()
- {
- T t = *this->threadEngine->startBlocking();
- delete this->threadEngine;
- return t;
- }
};
// Full template specialization where T is void.
@@ -249,12 +232,6 @@ class ThreadEngineStarter<void> : public ThreadEngineStarterBase<void>
public:
ThreadEngineStarter(ThreadEngine<void> *_threadEngine)
: ThreadEngineStarterBase<void>(_threadEngine) {}
-
- void startBlocking()
- {
- this->threadEngine->startBlocking();
- delete this->threadEngine;
- }
};
//! [qtconcurrentthreadengine-1]
diff --git a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp
index 3c77b1ba0b..212c0a2e13 100644
--- a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp
+++ b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp
@@ -126,7 +126,8 @@ public:
void tst_QtConcurrentIterateKernel::instantiate()
{
- startThreadEngine(new PrintFor(0, 40)).startBlocking();
+ auto future = startThreadEngine(new PrintFor(0, 40)).startAsynchronously();
+ future.waitForFinished();
QCOMPARE(iterations.loadRelaxed(), 40);
}
@@ -165,8 +166,10 @@ void tst_QtConcurrentIterateKernel::stresstest()
const int times = 50;
for (int i = 0; i < times; ++i) {
counter.storeRelaxed(0);
- CountFor f(0, iterations);
- f.startBlocking();
+ // ThreadEngine will delete f when it finishes
+ auto f = new CountFor(0, iterations);
+ auto future = f->startAsynchronously();
+ future.waitForFinished();
QCOMPARE(counter.loadRelaxed(), iterations);
}
}
@@ -174,8 +177,11 @@ void tst_QtConcurrentIterateKernel::stresstest()
void tst_QtConcurrentIterateKernel::noIterations()
{
const int times = 20000;
- for (int i = 0; i < times; ++i)
- startThreadEngine(new IterateKernel<TestIterator, void>(0, 0)).startBlocking();
+ for (int i = 0; i < times; ++i) {
+ auto future = startThreadEngine(new IterateKernel<TestIterator, void>(0, 0))
+ .startAsynchronously();
+ future.waitForFinished();
+ }
}
QMutex threadsMutex;
@@ -230,8 +236,10 @@ void tst_QtConcurrentIterateKernel::throttling()
threads.clear();
- ThrottleFor f(0, totalIterations);
- f.startBlocking();
+ // ThreadEngine will delete f when it finishes
+ auto f = new ThrottleFor(0, totalIterations);
+ auto future = f->startAsynchronously();
+ future.waitForFinished();
QCOMPARE(iterations.loadRelaxed(), totalIterations);
diff --git a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp
index d4c669cddc..caaa5d9bc9 100644
--- a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp
+++ b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp
@@ -65,16 +65,9 @@ public:
void tst_QtConcurrentThreadEngine::runDirectly()
{
- {
- PrintUser engine;
- engine.startSingleThreaded();
- engine.startBlocking();
- }
- {
- PrintUser *engine = new PrintUser();
- QFuture<void> f = engine->startAsynchronously();
- f.waitForFinished();
- }
+ PrintUser *engine = new PrintUser();
+ QFuture<void> f = engine->startAsynchronously();
+ f.waitForFinished();
}
class StringResultUser : public ThreadEngine<QString>
@@ -106,8 +99,10 @@ public:
void tst_QtConcurrentThreadEngine::result()
{
- StringResultUser engine;
- QCOMPARE(*engine.startBlocking(), QString("Foo"));
+ // ThreadEngine will delete 'engine' when it finishes
+ auto engine = new StringResultUser();
+ auto future = engine->startAsynchronously();
+ QCOMPARE(future.result(), QString("Foo"));
}
class VoidResultUser : public ThreadEngine<void>
@@ -133,17 +128,9 @@ public:
void tst_QtConcurrentThreadEngine::runThroughStarter()
{
- {
- ThreadEngineStarter<QString> starter = startThreadEngine(new StringResultUser());
- QFuture<QString> f = starter.startAsynchronously();
- QCOMPARE(f.result(), QString("Foo"));
- }
-
- {
- ThreadEngineStarter<QString> starter = startThreadEngine(new StringResultUser());
- QString str = starter.startBlocking();
- QCOMPARE(str, QString("Foo"));
- }
+ ThreadEngineStarter<QString> starter = startThreadEngine(new StringResultUser());
+ QFuture<QString> f = starter.startAsynchronously();
+ QCOMPARE(f.result(), QString("Foo"));
}
class CancelUser : public ThreadEngine<void>
@@ -226,12 +213,6 @@ void tst_QtConcurrentThreadEngine::throttle()
f.waitForFinished();
QCOMPARE(count.loadRelaxed(), 0);
}
-
- for (int i = 0; i < repeats; ++i) {
- ThrottleAlwaysUser t;
- t.startBlocking();
- QCOMPARE(count.loadRelaxed(), 0);
- }
}
QSet<QThread *> threads;
@@ -270,17 +251,9 @@ void tst_QtConcurrentThreadEngine::threadCount()
const int repeats = 10;
for (int i = 0; i < repeats; ++i) {
- ThreadCountUser t;
- t.startBlocking();
- int count = threads.count();
- int count_expected = QThreadPool::globalInstance()->maxThreadCount() + 1; // +1 for the main thread.
- if (count != count_expected)
- QEXPECT_FAIL("", "QTBUG-23333", Abort);
- QCOMPARE(count, count_expected);
-
(new ThreadCountUser())->startAsynchronously().waitForFinished();
- count = threads.count();
- count_expected = QThreadPool::globalInstance()->maxThreadCount();
+ const auto count = threads.count();
+ const auto count_expected = QThreadPool::globalInstance()->maxThreadCount();
if (count != count_expected)
QEXPECT_FAIL("", "QTBUG-23333", Abort);
QCOMPARE(count, count_expected);
@@ -288,15 +261,8 @@ void tst_QtConcurrentThreadEngine::threadCount()
// Set the finish flag immediately, this should give us one thread only.
for (int i = 0; i < repeats; ++i) {
- ThreadCountUser t(true /*finishImmediately*/);
- t.startBlocking();
- int count = threads.count();
- if (count != 1)
- QEXPECT_FAIL("", "QTBUG-23333", Abort);
- QCOMPARE(count, 1);
-
(new ThreadCountUser(true /*finishImmediately*/))->startAsynchronously().waitForFinished();
- count = threads.count();
+ const auto count = threads.count();
if (count != 1)
QEXPECT_FAIL("", "QTBUG-23333", Abort);
QCOMPARE(count, 1);
@@ -438,7 +404,6 @@ public:
void tst_QtConcurrentThreadEngine::exceptions()
{
- // Asynchronous mode:
{
bool caught = false;
try {
@@ -451,32 +416,6 @@ void tst_QtConcurrentThreadEngine::exceptions()
QVERIFY2(caught, "did not get exception");
}
- // Blocking mode:
- // test throwing the exception from a worker thread.
- {
- bool caught = false;
- try {
- QtConcurrentExceptionThrower e(QThread::currentThread());
- e.startBlocking();
- } catch (const QException &) {
- caught = true;
- }
- QVERIFY2(caught, "did not get exception");
- }
-
- // test throwing the exception from the main thread (different code path)
- {
- bool caught = false;
- try {
- QtConcurrentExceptionThrower e(0);
- e.startBlocking();
- } catch (const QException &) {
- caught = true;
- }
- QVERIFY2(caught, "did not get exception");
- }
-
- // Asynchronous mode:
{
bool caught = false;
try {
@@ -488,31 +427,6 @@ void tst_QtConcurrentThreadEngine::exceptions()
}
QVERIFY2(caught, "did not get exception");
}
-
- // Blocking mode:
- // test throwing the exception from a worker thread.
- {
- bool caught = false;
- try {
- UnrelatedExceptionThrower e(QThread::currentThread());
- e.startBlocking();
- } catch (const QUnhandledException &) {
- caught = true;
- }
- QVERIFY2(caught, "did not get exception");
- }
-
- // test throwing the exception from the main thread (different code path)
- {
- bool caught = false;
- try {
- UnrelatedExceptionThrower e(0);
- e.startBlocking();
- } catch (const QUnhandledException &) {
- caught = true;
- }
- QVERIFY2(caught, "did not get exception");
- }
}
#endif