From e07aec7eaa40361b685f35dd75b9f668f28364b7 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Sun, 21 Mar 2021 10:54:55 +0100 Subject: [PATCH] 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 . 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 Reviewed-by: Karsten Heimrich --- src/corelib/thread/qfuture.h | 1 - src/corelib/thread/qfutureinterface.cpp | 5 ++++ src/corelib/thread/qfutureinterface.h | 31 ++++++++++++++----------- 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 a56e9ee3ff7..9aa77ccf2f0 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 7a8ba081030..4e9d557209a 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 2432503cf79..62875c5ef9c 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 df71d3d4b66..28dc4be2633 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);