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 #include -#include 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 #include -#include +#include #include +#ifndef QT_NO_EXCEPTIONS +#include +#endif #include -#include -#include QT_REQUIRE_CONFIG(future); +QT_FORWARD_DECLARE_CLASS(QRunnable) +QT_FORWARD_DECLARE_CLASS(QException) QT_BEGIN_NAMESPACE @@ -64,6 +66,8 @@ namespace QtPrivate { template class Continuation; +class ExceptionStore; + template 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 inline bool QFutureInterface::reportResult(const T *result, int index) { - std::lock_guard locker{mutex()}; + QMutexLocker locker{&mutex()}; if (this->queryState(Canceled) || this->queryState(Finished)) return false; @@ -283,7 +288,7 @@ inline bool QFutureInterface::reportResult(const T *result, int index) template bool QFutureInterface::reportAndMoveResult(T &&result, int index) { - std::lock_guard locker{mutex()}; + QMutexLocker locker{&mutex()}; if (queryState(Canceled) || queryState(Finished)) return false; @@ -312,7 +317,7 @@ inline bool QFutureInterface::reportResult(const T &result, int index) template inline bool QFutureInterface::reportResults(const QList &_results, int beginIndex, int count) { - std::lock_guard locker{mutex()}; + QMutexLocker locker{&mutex()}; if (this->queryState(Canceled) || this->queryState(Finished)) return false; @@ -343,14 +348,14 @@ inline bool QFutureInterface::reportFinished(const T *result) template inline const T &QFutureInterface::resultReference(int index) const { - std::lock_guard locker{mutex()}; + QMutexLocker locker{&mutex()}; return resultStoreBase().resultAt(index).template value(); } template inline const T *QFutureInterface::resultPointer(int index) const { - std::lock_guard locker{mutex()}; + QMutexLocker locker{&mutex()}; return resultStoreBase().resultAt(index).template pointer(); } @@ -358,14 +363,14 @@ template inline QList QFutureInterface::results() { if (this->isCanceled()) { - exceptionStore().throwPossibleException(); + rethrowPossibleException(); return QList(); } QFutureInterfaceBase::waitForResult(-1); QList res; - std::lock_guard locker{mutex()}; + QMutexLocker locker{&mutex()}; QtPrivate::ResultIteratorBase it = resultStoreBase().begin(); while (it != resultStoreBase().end()) { @@ -385,7 +390,7 @@ T QFutureInterface::takeResult() // not to mess with other unready results. waitForResult(-1); - const std::lock_guard locker{mutex()}; + const QMutexLocker locker{&mutex()}; QtPrivate::ResultIteratorBase position = resultStoreBase().resultAt(0); T ret(std::move_if_noexcept(position.value())); reset(); @@ -404,7 +409,7 @@ std::vector QFutureInterface::takeResults() std::vector res; res.reserve(resultCount()); - const std::lock_guard locker{mutex()}; + const QMutexLocker 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 #include #include +#include +#include QT_REQUIRE_CONFIG(future);