Remove the dead code for blocking methods from QtConcurrent
After 79fd1cb2c6
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>
This commit is contained in:
parent
7dd4c93748
commit
1bf75f2a66
@ -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(std::current_exception()));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (throttled == false) {
|
||||
barrier.release();
|
||||
}
|
||||
|
||||
barrier.wait();
|
||||
finish();
|
||||
exceptionStore.throwPossibleException();
|
||||
}
|
||||
|
||||
void ThreadEngineBase::startThread()
|
||||
{
|
||||
startThreadInternal();
|
||||
|
@ -91,7 +91,6 @@ public:
|
||||
ThreadEngineBase(QThreadPool *pool);
|
||||
virtual ~ThreadEngineBase();
|
||||
void startSingleThreaded();
|
||||
void startBlocking();
|
||||
void startThread();
|
||||
bool isCanceled();
|
||||
void waitForResume();
|
||||
@ -153,15 +152,6 @@ public:
|
||||
return result();
|
||||
}
|
||||
|
||||
// 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()
|
||||
@ -242,13 +232,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.
|
||||
@ -258,12 +241,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]
|
||||
|
@ -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,12 @@ void tst_QtConcurrentIterateKernel::stresstest()
|
||||
void tst_QtConcurrentIterateKernel::noIterations()
|
||||
{
|
||||
const int times = 20000;
|
||||
for (int i = 0; i < times; ++i)
|
||||
startThreadEngine(new IterateKernel<TestIterator, void>(QThreadPool::globalInstance(), 0, 0)).startBlocking();
|
||||
for (int i = 0; i < times; ++i) {
|
||||
auto future = startThreadEngine(new IterateKernel<TestIterator, void>(
|
||||
QThreadPool::globalInstance(), 0, 0))
|
||||
.startAsynchronously();
|
||||
future.waitForFinished();
|
||||
}
|
||||
}
|
||||
|
||||
QMutex threadsMutex;
|
||||
@ -230,8 +237,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);
|
||||
|
||||
|
@ -66,16 +66,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>
|
||||
@ -108,8 +101,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>
|
||||
@ -137,17 +132,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>
|
||||
@ -233,12 +220,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;
|
||||
@ -278,17 +259,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);
|
||||
@ -296,15 +269,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);
|
||||
@ -450,7 +416,6 @@ public:
|
||||
|
||||
void tst_QtConcurrentThreadEngine::exceptions()
|
||||
{
|
||||
// Asynchronous mode:
|
||||
{
|
||||
bool caught = false;
|
||||
try {
|
||||
@ -463,32 +428,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(nullptr);
|
||||
e.startBlocking();
|
||||
} catch (const QException &) {
|
||||
caught = true;
|
||||
}
|
||||
QVERIFY2(caught, "did not get exception");
|
||||
}
|
||||
|
||||
// Asynchronous mode:
|
||||
{
|
||||
bool caught = false;
|
||||
try {
|
||||
@ -506,43 +445,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 {
|
||||
IntExceptionThrower e(QThread::currentThread());
|
||||
e.startBlocking();
|
||||
} catch (const QUnhandledException &ex) {
|
||||
// Make sure the exception info is not lost
|
||||
try {
|
||||
if (ex.exception())
|
||||
std::rethrow_exception(ex.exception());
|
||||
} catch (int) {
|
||||
caught = true;
|
||||
}
|
||||
}
|
||||
QVERIFY2(caught, "did not get exception");
|
||||
}
|
||||
|
||||
// test throwing the exception from the main thread (different code path)
|
||||
{
|
||||
bool caught = false;
|
||||
try {
|
||||
IntExceptionThrower e(nullptr);
|
||||
e.startBlocking();
|
||||
} catch (const QUnhandledException &ex) {
|
||||
// Make sure the exception info is not lost
|
||||
try {
|
||||
if (ex.exception())
|
||||
std::rethrow_exception(ex.exception());
|
||||
} catch (int) {
|
||||
caught = true;
|
||||
}
|
||||
}
|
||||
QVERIFY2(caught, "did not get exception");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user