From 97db8e04ac2efd924c6de4c0bcdcaf845b090bbc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 9 Aug 2019 16:15:57 +0200 Subject: 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 --- src/concurrent/qtconcurrentreducekernel.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/concurrent') diff --git a/src/concurrent/qtconcurrentreducekernel.h b/src/concurrent/qtconcurrentreducekernel.h index 0fbc40e02e..8f9a938952 100644 --- a/src/concurrent/qtconcurrentreducekernel.h +++ b/src/concurrent/qtconcurrentreducekernel.h @@ -52,6 +52,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE @@ -147,7 +149,7 @@ public: ReduceResultType &r, const IntermediateResults &result) { - QMutexLocker locker(&mutex); + std::unique_lock locker(mutex); if (!canReduce(result.begin)) { ++resultsMapSize; resultsMap.insert(result.begin, result); @@ -161,7 +163,7 @@ public: // reduce this result locker.unlock(); reduceResult(reduce, r, result); - locker.relock(); + locker.lock(); // reduce all stored results as well while (!resultsMap.isEmpty()) { @@ -170,7 +172,7 @@ public: locker.unlock(); reduceResults(reduce, r, resultsMapCopy); - locker.relock(); + locker.lock(); resultsMapSize -= resultsMapCopy.size(); } @@ -180,7 +182,7 @@ public: // reduce this result locker.unlock(); reduceResult(reduce, r, result); - locker.relock(); + locker.lock(); // OrderedReduce progress += result.end - result.begin; @@ -193,7 +195,7 @@ public: locker.unlock(); reduceResult(reduce, r, it.value()); - locker.relock(); + locker.lock(); --resultsMapSize; progress += it.value().end - it.value().begin; -- cgit v1.2.3