diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-05-20 11:39:39 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-05-29 16:58:43 +0200 |
commit | 2f15927f01ceef0aca490746302a5ea57ea9441c (patch) | |
tree | c4978b801a1e7db5b63fd091182fff2394a36b7f /src/concurrent | |
parent | 9b0e23ef8a915a8c58808fa356f771ecdb6f020c (diff) |
Add a way of notifying QFutureWatcher when pause is in effect
Because setting QFutureInterface to paused state does not mean that
the computations that are already in progress will stop immediately,
it may be useful to get notified when pause actually takes effect.
Introduced the QFutureWatcher::suspended() signal, to be emitted when
there are no more computations in progress, and no more result ready
or progress reporting signals will be emitted, i.e. when pause took
effect. Added {QFuture, QFutureWatcher}::isSuspended() methods for
checking if pause took effect.
QtConcurrent will now to send QFutureCallOutEvent::Suspended event
when the state is paused and there are no more active threads.
[ChangeLog][QtCore][QFutureWatcher] Added a new QFutureWatcher::suspended()
signal, to be emitted when pause took effect, meaning that there are no
more computations in progress. Added {QFuture, QFutureWatcher}::isSuspended()
methods for checking if pause took effect.
Fixes: QTBUG-12152
Change-Id: I88f2ad24d800cd6293dec63977d45bd35f9a09f0
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/concurrent')
-rw-r--r-- | src/concurrent/qtconcurrentthreadengine.cpp | 15 | ||||
-rw-r--r-- | src/concurrent/qtconcurrentthreadengine.h | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/concurrent/qtconcurrentthreadengine.cpp b/src/concurrent/qtconcurrentthreadengine.cpp index 7dfc29c68f..7ea606f60b 100644 --- a/src/concurrent/qtconcurrentthreadengine.cpp +++ b/src/concurrent/qtconcurrentthreadengine.cpp @@ -219,6 +219,12 @@ void ThreadEngineBase::acquireBarrierSemaphore() barrier.acquire(); } +void ThreadEngineBase::reportIfPausedDone() const +{ + if (futureInterface && futureInterface->isPaused()) + futureInterface->reportSuspended(); +} + bool ThreadEngineBase::isCanceled() { if (futureInterface) @@ -304,8 +310,15 @@ void ThreadEngineBase::run() // implements QRunnable. // struct wants to be throttled by making a worker thread exit. // Respect that request unless this is the only worker thread left // running, in which case it has to keep going. - if (threadThrottleExit()) + if (threadThrottleExit()) { return; + } else { + // If the last worker thread is throttled and the state is paused, + // it means that pause has been requested, and it is already + // in effect (because all previous threads have already exited). + // Report the "Suspended" state. + reportIfPausedDone(); + } } #ifndef QT_NO_EXCEPTIONS diff --git a/src/concurrent/qtconcurrentthreadengine.h b/src/concurrent/qtconcurrentthreadengine.h index eb11c34c06..4e7e8d0b81 100644 --- a/src/concurrent/qtconcurrentthreadengine.h +++ b/src/concurrent/qtconcurrentthreadengine.h @@ -99,6 +99,7 @@ public: void setProgressValue(int progress); void setProgressRange(int minimum, int maximum); void acquireBarrierSemaphore(); + void reportIfPausedDone() const; protected: // The user overrides these: virtual void start() {} |