From f34b7fa3ca5ad0e808b15b8ce9965ebabcb53c00 Mon Sep 17 00:00:00 2001 From: Debian Qt/KDE Maintainers Date: Fri, 13 Jan 2023 07:41:54 +0000 Subject: [PATCH] revert "Remove the dead code for blocking methods from QtConcurrent" Origin: KDE, https://invent.kde.org/qt/qt/qtbase/-/commit/eeadc036d77b75be Also submitted to upstream 5.15 branch according to https://lists.qt-project.org/pipermail/development/2022-September/042951.html. Last-Update: 2022-09-10 It's a binary incompatible change. Gbp-Pq: Name revert_startBlocking_removal.diff --- src/concurrent/qtconcurrentthreadengine.cpp | 33 +++++++++++++++++++++ src/concurrent/qtconcurrentthreadengine.h | 23 ++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/concurrent/qtconcurrentthreadengine.cpp b/src/concurrent/qtconcurrentthreadengine.cpp index ea6ce3ac4..7f91a2ba6 100644 --- a/src/concurrent/qtconcurrentthreadengine.cpp +++ b/src/concurrent/qtconcurrentthreadengine.cpp @@ -176,6 +176,39 @@ 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 7c30cebdb..a4c8548cc 100644 --- a/src/concurrent/qtconcurrentthreadengine.h +++ b/src/concurrent/qtconcurrentthreadengine.h @@ -91,6 +91,7 @@ public: ThreadEngineBase(); virtual ~ThreadEngineBase(); void startSingleThreaded(); + void startBlocking(); void startThread(); bool isCanceled(); void waitForResume(); @@ -143,6 +144,15 @@ 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 startAsynchronously() @@ -223,6 +233,13 @@ class ThreadEngineStarter : public ThreadEngineStarterBase 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. @@ -232,6 +249,12 @@ class ThreadEngineStarter : public ThreadEngineStarterBase public: ThreadEngineStarter(ThreadEngine *_threadEngine) : ThreadEngineStarterBase(_threadEngine) {} + + void startBlocking() + { + this->threadEngine->startBlocking(); + delete this->threadEngine; + } }; //! [qtconcurrentthreadengine-1] -- 2.30.2