diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-08-09 16:15:57 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-08-25 04:48:11 +0000 |
commit | 97db8e04ac2efd924c6de4c0bcdcaf845b090bbc (patch) | |
tree | 73481764b260c8e92d6f491aaccc009e31285ab0 /src/corelib/thread | |
parent | e913b690b9c87a24e69085f707886ee066d1b616 (diff) |
Port away from QMutexLocker in public headers
We can't use qt_scoped_lock/qt_unique_lock here, so port to
std::unique_lock and std::lock_guard for now.
This is in preparation of deprecating QMutexLocker in favor
of std::unique_lock and std::scoped_lock.
In QFutureInterface, change the return type of mutex() from
QMutex* to QMutex&, so we don't need to deref when passing
to std::lock_guard. We need to keep the old method around
for BC reasons, so the new one needs an artificial function
argument for disambiguation. This will vanish come Qt 6.
Change-Id: I1a0f0205952a249512ec2dbd3f0f48dd209b1636
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qfutureinterface.cpp | 5 | ||||
-rw-r--r-- | src/corelib/thread/qfutureinterface.h | 13 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp index 8f4cae8816..6430f38a3b 100644 --- a/src/corelib/thread/qfutureinterface.cpp +++ b/src/corelib/thread/qfutureinterface.cpp @@ -429,6 +429,11 @@ QMutex *QFutureInterfaceBase::mutex() const return &d->m_mutex; } +QMutex &QFutureInterfaceBase::mutex(int) const +{ + return d->m_mutex; +} + QtPrivate::ExceptionStore &QFutureInterfaceBase::exceptionStore() { return d->m_exceptionStore; diff --git a/src/corelib/thread/qfutureinterface.h b/src/corelib/thread/qfutureinterface.h index d5e2401eee..bcdae24833 100644 --- a/src/corelib/thread/qfutureinterface.h +++ b/src/corelib/thread/qfutureinterface.h @@ -45,6 +45,8 @@ #include <QtCore/qexception.h> #include <QtCore/qresultstore.h> +#include <mutex> + QT_REQUIRE_CONFIG(future); QT_BEGIN_NAMESPACE @@ -118,6 +120,7 @@ public: void waitForResume(); QMutex *mutex() const; + QMutex &mutex(int) const; QtPrivate::ExceptionStore &exceptionStore(); QtPrivate::ResultStoreBase &resultStoreBase(); const QtPrivate::ResultStoreBase &resultStoreBase() const; @@ -188,7 +191,7 @@ public: template <typename T> inline void QFutureInterface<T>::reportResult(const T *result, int index) { - QMutexLocker locker(mutex()); + std::lock_guard<QMutex> locker(mutex(0)); if (this->queryState(Canceled) || this->queryState(Finished)) { return; } @@ -214,7 +217,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) { - QMutexLocker locker(mutex()); + std::lock_guard<QMutex> locker(mutex(0)); if (this->queryState(Canceled) || this->queryState(Finished)) { return; } @@ -242,14 +245,14 @@ inline void QFutureInterface<T>::reportFinished(const T *result) template <typename T> inline const T &QFutureInterface<T>::resultReference(int index) const { - QMutexLocker lock(mutex()); + std::lock_guard<QMutex> locker(mutex(0)); return resultStoreBase().resultAt(index).template value<T>(); } template <typename T> inline const T *QFutureInterface<T>::resultPointer(int index) const { - QMutexLocker lock(mutex()); + std::lock_guard<QMutex> locker(mutex(0)); return resultStoreBase().resultAt(index).template pointer<T>(); } @@ -263,7 +266,7 @@ inline QList<T> QFutureInterface<T>::results() QFutureInterfaceBase::waitForResult(-1); QList<T> res; - QMutexLocker lock(mutex()); + std::lock_guard<QMutex> locker(mutex(0)); QtPrivate::ResultIteratorBase it = resultStoreBase().begin(); while (it != resultStoreBase().end()) { |