revert "Remove the dead code for blocking methods from QtConcurrent"
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Sat, 13 May 2023 11:12:14 +0000 (12:12 +0100)
committerDmitry Shachnev <mitya57@debian.org>
Sat, 13 May 2023 11:12:14 +0000 (12:12 +0100)
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
src/concurrent/qtconcurrentthreadengine.h

index ea6ce3ac42f64ec9674ddeca51d01323fca831ed..7f91a2ba68a30ce000421bd676f87593039dfe20 100644 (file)
@@ -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();
index 7c30cebdbcaa7e652e89dbda234e9fd33de53d61..a4c8548cc493aa1f10742ba1ded0419b4deb08f2 100644 (file)
@@ -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<T> startAsynchronously()
@@ -223,6 +233,13 @@ 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.
@@ -232,6 +249,12 @@ class ThreadEngineStarter<void> : public ThreadEngineStarterBase<void>
 public:
     ThreadEngineStarter(ThreadEngine<void> *_threadEngine)
         : ThreadEngineStarterBase<void>(_threadEngine) {}
+
+    void startBlocking()
+    {
+        this->threadEngine->startBlocking();
+        delete this->threadEngine;
+    }
 };
 
 //! [qtconcurrentthreadengine-1]