diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-03-21 10:54:55 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-03-22 10:47:13 +0100 |
commit | e07aec7eaa40361b685f35dd75b9f668f28364b7 (patch) | |
tree | ebf239bb67b874ce16be3a23bef1cc52424b0eb3 | |
parent | df121fd7f74ecfb3de20867edea1c1f3ebf035c2 (diff) |
QFuture: cleanup headers
Do not include vector; we currently do not use std::vector, and the plan
is to use QList when that one supports move-only types.
Use QMutexLocker instead of std::mutex_locker, considering that the
former is already included with <QMutex>.
Use forward declarations where applicable.
Add header which were currently only indirectly included (to make
QtCreator's code model happy).
Change-Id: I37d5cd3982047a6d8a3132fd66571878298039b3
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r-- | src/corelib/thread/qfuture.h | 1 | ||||
-rw-r--r-- | src/corelib/thread/qfutureinterface.cpp | 5 | ||||
-rw-r--r-- | src/corelib/thread/qfutureinterface.h | 31 | ||||
-rw-r--r-- | src/corelib/thread/qfutureinterface_p.h | 2 |
4 files changed, 25 insertions, 14 deletions
diff --git a/src/corelib/thread/qfuture.h b/src/corelib/thread/qfuture.h index a56e9ee3ff..9aa77ccf2f 100644 --- a/src/corelib/thread/qfuture.h +++ b/src/corelib/thread/qfuture.h @@ -48,7 +48,6 @@ #include <QtCore/qfuture_impl.h> #include <type_traits> -#include <vector> QT_REQUIRE_CONFIG(future); diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp index 7a8ba08103..4e9d557209 100644 --- a/src/corelib/thread/qfutureinterface.cpp +++ b/src/corelib/thread/qfutureinterface.cpp @@ -600,6 +600,11 @@ void QFutureInterfaceBase::reset() d->isValid = false; } +void QFutureInterfaceBase::rethrowPossibleException() +{ + exceptionStore().throwPossibleException(); +} + QFutureInterfaceBasePrivate::QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState) : refCount(1), m_progressValue(0), m_progressMinimum(0), m_progressMaximum(0), state(initialState), diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h index 2432503cf7..62875c5ef9 100644 --- a/src/corelib/thread/qfutureinterface.h +++ b/src/corelib/thread/qfutureinterface.h @@ -40,17 +40,19 @@ #ifndef QFUTUREINTERFACE_H #define QFUTUREINTERFACE_H -#include <QtCore/qrunnable.h> #include <QtCore/qmutex.h> -#include <QtCore/qexception.h> +#include <QtCore/QMutexLocker> #include <QtCore/qresultstore.h> +#ifndef QT_NO_EXCEPTIONS +#include <exception> +#endif #include <utility> -#include <vector> -#include <mutex> QT_REQUIRE_CONFIG(future); +QT_FORWARD_DECLARE_CLASS(QRunnable) +QT_FORWARD_DECLARE_CLASS(QException) QT_BEGIN_NAMESPACE @@ -64,6 +66,8 @@ namespace QtPrivate { template<typename Function, typename ResultType, typename ParentResultType> class Continuation; +class ExceptionStore; + template<class Function, class ResultType> class CanceledHandler; @@ -169,6 +173,7 @@ protected: bool refT() const; bool derefT() const; void reset(); + void rethrowPossibleException(); public: #ifndef QFUTURE_TEST @@ -262,7 +267,7 @@ public: template <typename T> inline bool QFutureInterface<T>::reportResult(const T *result, int index) { - std::lock_guard<QMutex> locker{mutex()}; + QMutexLocker<QMutex> locker{&mutex()}; if (this->queryState(Canceled) || this->queryState(Finished)) return false; @@ -283,7 +288,7 @@ inline bool QFutureInterface<T>::reportResult(const T *result, int index) template<typename T> bool QFutureInterface<T>::reportAndMoveResult(T &&result, int index) { - std::lock_guard<QMutex> locker{mutex()}; + QMutexLocker<QMutex> locker{&mutex()}; if (queryState(Canceled) || queryState(Finished)) return false; @@ -312,7 +317,7 @@ inline bool QFutureInterface<T>::reportResult(const T &result, int index) template<typename T> inline bool QFutureInterface<T>::reportResults(const QList<T> &_results, int beginIndex, int count) { - std::lock_guard<QMutex> locker{mutex()}; + QMutexLocker<QMutex> locker{&mutex()}; if (this->queryState(Canceled) || this->queryState(Finished)) return false; @@ -343,14 +348,14 @@ inline bool QFutureInterface<T>::reportFinished(const T *result) template <typename T> inline const T &QFutureInterface<T>::resultReference(int index) const { - std::lock_guard<QMutex> locker{mutex()}; + QMutexLocker<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()}; + QMutexLocker<QMutex> locker{&mutex()}; return resultStoreBase().resultAt(index).template pointer<T>(); } @@ -358,14 +363,14 @@ template <typename T> inline QList<T> QFutureInterface<T>::results() { if (this->isCanceled()) { - exceptionStore().throwPossibleException(); + rethrowPossibleException(); return QList<T>(); } QFutureInterfaceBase::waitForResult(-1); QList<T> res; - std::lock_guard<QMutex> locker{mutex()}; + QMutexLocker<QMutex> locker{&mutex()}; QtPrivate::ResultIteratorBase it = resultStoreBase().begin(); while (it != resultStoreBase().end()) { @@ -385,7 +390,7 @@ T QFutureInterface<T>::takeResult() // not to mess with other unready results. waitForResult(-1); - const std::lock_guard<QMutex> locker{mutex()}; + const QMutexLocker<QMutex> locker{&mutex()}; QtPrivate::ResultIteratorBase position = resultStoreBase().resultAt(0); T ret(std::move_if_noexcept(position.value<T>())); reset(); @@ -404,7 +409,7 @@ std::vector<T> QFutureInterface<T>::takeResults() std::vector<T> res; res.reserve(resultCount()); - const std::lock_guard<QMutex> locker{mutex()}; + const QMutexLocker<QMutex> locker{&mutex()}; QtPrivate::ResultIteratorBase it = resultStoreBase().begin(); for (auto endIt = resultStoreBase().end(); it != endIt; ++it) diff --git a/src/corelib/thread/qfutureinterface_p.h b/src/corelib/thread/qfutureinterface_p.h index df71d3d4b6..28dc4be263 100644 --- a/src/corelib/thread/qfutureinterface_p.h +++ b/src/corelib/thread/qfutureinterface_p.h @@ -58,6 +58,8 @@ #include <QtCore/qwaitcondition.h> #include <QtCore/qrunnable.h> #include <QtCore/qthreadpool.h> +#include <QtCore/qfutureinterface.h> +#include <QtCore/qexception.h> QT_REQUIRE_CONFIG(future); |