diff options
| author | Andrei Golubev <andrei.golubev@qt.io> | 2020-05-14 14:02:31 +0300 |
|---|---|---|
| committer | Andrei Golubev <andrei.golubev@qt.io> | 2020-06-09 17:21:38 +0300 |
| commit | 385f0732d927f0eba8ecf990ee9bc19936475edd (patch) | |
| tree | ce8ba1adfb7252ad475885e6acc7ed256ec6b86f /src/corelib/thread/qfutureinterface.h | |
| parent | 20ba86262f39886629880fa1e07383f1e3e1d52e (diff) | |
Add QPromise implementation
QPromise and QFuture created from it share the same internal state
(namely, QFutureInterface object). QPromise provides high-level
management of the shared resource, ensuring thread-safe behavior
on construction and destruction (also taking into account
QFuture::waitForFinished() semantics).
QFuture acts as a primary controller of QPromise via action
initiating methods such as suspend() or cancel(). QPromise is
equipped with methods to check the status, but the actual
handling of QFuture action "requests" is user-defined.
[ChangeLog][QtCore][QPromise] Added QPromise class to accompany
QFuture. It allows one to communicate computation results and
progress to the QFuture via a shared state.
Task-number: QTBUG-81586
Change-Id: Ibab9681d35fe63754bf394ad0e7923e2683e2457
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/thread/qfutureinterface.h')
| -rw-r--r-- | src/corelib/thread/qfutureinterface.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h index c802be762b2..75c4cae0ca0 100644 --- a/src/corelib/thread/qfutureinterface.h +++ b/src/corelib/thread/qfutureinterface.h @@ -140,6 +140,7 @@ public: bool isThrottled() const; bool isResultReadyAt(int index) const; bool isValid() const; + int loadState() const; void cancel(); void setSuspended(bool suspend); @@ -151,6 +152,7 @@ public: bool waitForNextResult(); void waitForResult(int resultIndex); void waitForResume(); + void suspendIfRequested(); QMutex &mutex() const; QtPrivate::ExceptionStore &exceptionStore(); @@ -233,6 +235,7 @@ public: inline void reportResult(const T *result, int index = -1); inline void reportAndMoveResult(T &&result, int index = -1); + inline void reportResult(T &&result, int index = -1); inline void reportResult(const T &result, int index = -1); inline void reportResults(const QVector<T> &results, int beginIndex = -1, int count = -1); inline void reportFinished(const T *result); @@ -285,6 +288,12 @@ void QFutureInterface<T>::reportAndMoveResult(T &&result, int index) reportResultsReady(insertIndex, store.count()); } +template<typename T> +void QFutureInterface<T>::reportResult(T &&result, int index) +{ + reportAndMoveResult(std::move(result), index); +} + template <typename T> inline void QFutureInterface<T>::reportResult(const T &result, int index) { |
