summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qfutureinterface.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread/qfutureinterface.h')
-rw-r--r--src/corelib/thread/qfutureinterface.h42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h
index bcdae24833..c2e884911f 100644
--- a/src/corelib/thread/qfutureinterface.h
+++ b/src/corelib/thread/qfutureinterface.h
@@ -58,6 +58,11 @@ class QFutureInterfaceBasePrivate;
class QFutureWatcherBase;
class QFutureWatcherBasePrivate;
+namespace QtPrivate {
+template<typename Function, typename ResultType, typename ParentResultType>
+class Continuation;
+}
+
class Q_CORE_EXPORT QFutureInterfaceBase
{
public:
@@ -68,7 +73,9 @@ public:
Finished = 0x04,
Canceled = 0x08,
Paused = 0x10,
- Throttled = 0x20
+ Throttled = 0x20,
+ // Pending means that the future depends on another one, which is not finished yet
+ Pending = 0x40
};
QFutureInterfaceBase(State initialState = NoState);
@@ -86,6 +93,7 @@ public:
void setRunnable(QRunnable *runnable);
void setThreadPool(QThreadPool *pool);
+ QThreadPool *threadPool() const;
void setFilterMode(bool enable);
void setProgressRange(int minimum, int maximum);
int progressMinimum() const;
@@ -119,8 +127,7 @@ public:
void waitForResult(int resultIndex);
void waitForResume();
- QMutex *mutex() const;
- QMutex &mutex(int) const;
+ QMutex &mutex() const;
QtPrivate::ExceptionStore &exceptionStore();
QtPrivate::ResultStoreBase &resultStoreBase();
const QtPrivate::ResultStoreBase &resultStoreBase() const;
@@ -142,6 +149,18 @@ private:
private:
friend class QFutureWatcherBase;
friend class QFutureWatcherBasePrivate;
+
+ template<typename Function, typename ResultType, typename ParentResultType>
+ friend class QtPrivate::Continuation;
+
+protected:
+ void setContinuation(std::function<void()> func);
+ void runContinuation() const;
+
+ void setLaunchAsync(bool value);
+ bool launchAsync() const;
+
+ bool isRunningOrPending() const;
};
template <typename T>
@@ -191,7 +210,7 @@ public:
template <typename T>
inline void QFutureInterface<T>::reportResult(const T *result, int index)
{
- std::lock_guard<QMutex> locker(mutex(0));
+ std::lock_guard<QMutex> locker{mutex()};
if (this->queryState(Canceled) || this->queryState(Finished)) {
return;
}
@@ -217,7 +236,7 @@ inline void QFutureInterface<T>::reportResult(const T &result, int index)
template <typename T>
inline void QFutureInterface<T>::reportResults(const QVector<T> &_results, int beginIndex, int count)
{
- std::lock_guard<QMutex> locker(mutex(0));
+ std::lock_guard<QMutex> locker{mutex()};
if (this->queryState(Canceled) || this->queryState(Finished)) {
return;
}
@@ -240,19 +259,20 @@ inline void QFutureInterface<T>::reportFinished(const T *result)
if (result)
reportResult(result);
QFutureInterfaceBase::reportFinished();
+ QFutureInterfaceBase::runContinuation();
}
template <typename T>
inline const T &QFutureInterface<T>::resultReference(int index) const
{
- std::lock_guard<QMutex> locker(mutex(0));
+ std::lock_guard<QMutex> locker{mutex()};
return resultStoreBase().resultAt(index).template value<T>();
}
template <typename T>
inline const T *QFutureInterface<T>::resultPointer(int index) const
{
- std::lock_guard<QMutex> locker(mutex(0));
+ std::lock_guard<QMutex> locker{mutex()};
return resultStoreBase().resultAt(index).template pointer<T>();
}
@@ -266,7 +286,7 @@ inline QList<T> QFutureInterface<T>::results()
QFutureInterfaceBase::waitForResult(-1);
QList<T> res;
- std::lock_guard<QMutex> locker(mutex(0));
+ std::lock_guard<QMutex> locker{mutex()};
QtPrivate::ResultIteratorBase it = resultStoreBase().begin();
while (it != resultStoreBase().end()) {
@@ -293,7 +313,11 @@ public:
void reportResult(const void *, int) { }
void reportResults(const QVector<void> &, int) { }
- void reportFinished(const void * = nullptr) { QFutureInterfaceBase::reportFinished(); }
+ void reportFinished(const void * = nullptr)
+ {
+ QFutureInterfaceBase::reportFinished();
+ QFutureInterfaceBase::runContinuation();
+ }
};
QT_END_NAMESPACE