From 79fd1cb2c631b6084bf10874205d27f5b53c907a Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 14 May 2020 18:46:15 +0200 Subject: [PATCH] Reuse the non blocking implementation for blocking one Replace the implementation of blockingMappedReduced(): after calling non-blocking version of mappedReduced() we are getting the future object, so we may call in sequence result(), which will block and return the result when the all tasks are done. The same is done with blockigMapped(), which calls blockingMappedReduced() with a custom reduce function. Looks like with this pattern we can reuse the non-blocking version for implementing blocking version of mapped / filtered methods. Task-number: QTBUG-83918 Change-Id: I7f240cfbd04834d551ff79d717b72194a26996d7 Reviewed-by: Sona Kurazyan --- src/concurrent/qtconcurrentfilter.h | 167 +++++++------- src/concurrent/qtconcurrentmap.h | 209 +++++++++--------- .../tst_qtconcurrentfilter.cpp | 68 +++--- .../qtconcurrentmap/tst_qtconcurrentmap.cpp | 56 +++-- 4 files changed, 248 insertions(+), 252 deletions(-) diff --git a/src/concurrent/qtconcurrentfilter.h b/src/concurrent/qtconcurrentfilter.h index 5feedec7512..e383118874a 100644 --- a/src/concurrent/qtconcurrentfilter.h +++ b/src/concurrent/qtconcurrentfilter.h @@ -127,29 +127,28 @@ QFuture filteredReduced(const Sequence &sequence, } #ifndef Q_CLANG_QDOC -template -QFuture::ResultType> filteredReduced( - QThreadPool *pool, +template ::ResultType> +QFuture filteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced::ResultType> - (pool, sequence, keep, reduce, options); + return startFilteredReduced(pool, sequence, keep, reduce, options); } -template -QFuture::ResultType> filteredReduced( - const Sequence &sequence, +template ::ResultType> +QFuture filteredReduced(const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced::ResultType> - (QThreadPool::globalInstance(), sequence, keep, reduce, options); + return startFilteredReduced(QThreadPool::globalInstance(), + sequence, keep, reduce, options); } template filteredReduced(Iterator begin, } #ifndef Q_CLANG_QDOC -template -QFuture::ResultType> filteredReduced( - QThreadPool *pool, +template ::ResultType> +QFuture filteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor keep, @@ -251,21 +250,20 @@ QFuture::ResultType> filtere ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced::ResultType> - (pool, begin, end, keep, reduce, options); + return startFilteredReduced(pool, begin, end, keep, reduce, options); } -template -QFuture::ResultType> filteredReduced( - Iterator begin, +template ::ResultType> +QFuture filteredReduced(Iterator begin, Iterator end, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced::ResultType> - (QThreadPool::globalInstance(), begin, end, keep, reduce, options); + return startFilteredReduced(QThreadPool::globalInstance(), + begin, end, keep, reduce, options); } template ::value_type> filtered(Iterator begin, template void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor keep) { - filterInternal(pool, sequence, keep, QtPrivate::PushBackWrapper()).startBlocking(); + QFuture future = filterInternal(pool, sequence, keep, QtPrivate::PushBackWrapper()); + future.waitForFinished(); } template void blockingFilter(Sequence &sequence, KeepFunctor keep) { - filterInternal(QThreadPool::globalInstance(), sequence, keep, QtPrivate::PushBackWrapper()) - .startBlocking(); + QFuture future = filterInternal(QThreadPool::globalInstance(), sequence, keep, + QtPrivate::PushBackWrapper()); + future.waitForFinished(); } // blocking filteredReduced() on sequences @@ -358,8 +358,9 @@ ResultType blockingFilteredReduced(QThreadPool *pool, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced(pool, sequence, keep, reduce, options) - .startBlocking(); + QFuture future = startFilteredReduced(pool, sequence, keep, + reduce, options); + return future.result(); } template @@ -369,8 +370,9 @@ ResultType blockingFilteredReduced(const Sequence &sequence, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced(QThreadPool::globalInstance(), - sequence, keep, reduce, options).startBlocking(); + QFuture future = startFilteredReduced(QThreadPool::globalInstance(), + sequence, keep, reduce, options); + return future.result(); } template (pool, sequence, keep, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + QFuture future = startFilteredReduced(pool, sequence, keep, reduce, + ResultType(std::forward(initialValue)), options); + return future.result(); } template (QThreadPool::globalInstance(), sequence, keep, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + QFuture future = startFilteredReduced(QThreadPool::globalInstance(), + sequence, keep, reduce, ResultType(std::forward(initialValue)), options); + return future.result(); } #ifndef Q_CLANG_QDOC -template -typename QtPrivate::ReduceResultType::ResultType blockingFilteredReduced( - QThreadPool *pool, +template ::ResultType> +ResultType blockingFilteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced::ResultType> - (pool, sequence, keep, reduce, options).startBlocking(); + QFuture future = startFilteredReduced(pool, sequence, keep, + reduce, options); + return future.result(); } -template -typename QtPrivate::ReduceResultType::ResultType blockingFilteredReduced( - const Sequence &sequence, +template ::ResultType> +ResultType blockingFilteredReduced(const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced::ResultType> - (QThreadPool::globalInstance(), sequence, keep, reduce, options).startBlocking(); + QFuture future = startFilteredReduced(QThreadPool::globalInstance(), + sequence, keep, reduce, options); + return future.result(); } template (pool, sequence, keep, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + QFuture future = startFilteredReduced(pool, sequence, keep, reduce, + ResultType(std::forward(initialValue)), options); + return future.result(); } template (QThreadPool::globalInstance(), sequence, keep, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + QFuture future = startFilteredReduced(QThreadPool::globalInstance(), + sequence, keep, reduce, ResultType(std::forward(initialValue)), options); + return future.result(); } #endif @@ -470,8 +478,9 @@ ResultType blockingFilteredReduced(QThreadPool *pool, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced(pool, begin, end, keep, reduce, options) - .startBlocking(); + QFuture future = startFilteredReduced(pool, begin, end, keep, + reduce, options); + return future.result(); } template @@ -482,11 +491,11 @@ ResultType blockingFilteredReduced(Iterator begin, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced(QThreadPool::globalInstance(), begin, end, keep, - reduce, options).startBlocking(); + QFuture future = startFilteredReduced(QThreadPool::globalInstance(), + begin, end, keep, reduce, options); + return future.result(); } - template , int> = 0> @@ -499,8 +508,9 @@ ResultType blockingFilteredReduced(QThreadPool *pool, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced(pool, begin, end, keep, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + QFuture future = startFilteredReduced(pool, begin, end, keep, reduce, + ResultType(std::forward(initialValue)), options); + return future.result(); } template (QThreadPool::globalInstance(), begin, end, keep, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + QFuture future = startFilteredReduced(QThreadPool::globalInstance(), + begin, end, keep, reduce, ResultType(std::forward(initialValue)), options); + return future.result(); } #ifndef Q_CLANG_QDOC -template -typename QtPrivate::ReduceResultType::ResultType blockingFilteredReduced( - QThreadPool *pool, +template ::ResultType> +ResultType blockingFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor keep, @@ -529,21 +540,23 @@ typename QtPrivate::ReduceResultType::ResultType blockingFiltered ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced::ResultType> - (pool, begin, end, keep, reduce, options).startBlocking(); + QFuture future = startFilteredReduced(pool, begin, end, keep, + reduce, options); + return future.result(); } -template -typename QtPrivate::ReduceResultType::ResultType blockingFilteredReduced( - Iterator begin, +template ::ResultType> +ResultType blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor keep, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced::ResultType> - (QThreadPool::globalInstance(), begin, end, keep, reduce, options).startBlocking(); + QFuture future = startFilteredReduced(QThreadPool::globalInstance(), + begin, end, keep, reduce, options); + return future.result(); } template (pool, begin, end, keep, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + QFuture future = startFilteredReduced(pool, begin, end, keep, reduce, + ResultType(std::forward(initialValue)), options); + return future.result(); } template (QThreadPool::globalInstance(), begin, end, keep, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + QFuture future = startFilteredReduced(QThreadPool::globalInstance(), + begin, end, keep, reduce, ResultType(std::forward(initialValue)), options); + return future.result(); } #endif @@ -583,30 +598,30 @@ ResultType blockingFilteredReduced(Iterator begin, template Sequence blockingFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor keep) { - return startFilteredReduced(pool, sequence, keep, QtPrivate::PushBackWrapper(), - OrderedReduce).startBlocking(); + return blockingFilteredReduced(pool, sequence, keep, QtPrivate::PushBackWrapper(), + OrderedReduce); } template Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep) { - return startFilteredReduced(QThreadPool::globalInstance(), sequence, keep, - QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); + return blockingFilteredReduced(QThreadPool::globalInstance(), sequence, keep, + QtPrivate::PushBackWrapper(), OrderedReduce); } // blocking filtered() on iterators template OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor keep) { - return startFilteredReduced(pool, begin, end, keep, - QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); + return blockingFilteredReduced(pool, begin, end, keep, + QtPrivate::PushBackWrapper(), OrderedReduce); } template OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep) { - return startFilteredReduced(QThreadPool::globalInstance(), begin, end, keep, - QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); + return blockingFilteredReduced(QThreadPool::globalInstance(), begin, end, keep, + QtPrivate::PushBackWrapper(), OrderedReduce); } } // namespace QtConcurrent diff --git a/src/concurrent/qtconcurrentmap.h b/src/concurrent/qtconcurrentmap.h index 7076d9ecdee..e217c9af3a5 100644 --- a/src/concurrent/qtconcurrentmap.h +++ b/src/concurrent/qtconcurrentmap.h @@ -136,30 +136,29 @@ QFuture mappedReduced(const Sequence &sequence, ResultType(std::forward(initialValue)), options); } -template -QFuture::ResultType> mappedReduced( - QThreadPool *pool, +template ::ResultType> +QFuture mappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced, - typename QtPrivate::ReduceResultType::ResultType> + return startMappedReduced, ResultType> (pool, sequence, map, reduce, options); } -template -QFuture::ResultType> mappedReduced( +template ::ResultType> +QFuture mappedReduced( const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced, - typename QtPrivate::ReduceResultType::ResultType> + return startMappedReduced, ResultType> (QThreadPool::globalInstance(), sequence, map, reduce, options); } @@ -175,8 +174,7 @@ QFuture mappedReduced(QThreadPool *pool, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced, - typename QtPrivate::ReduceResultType::ResultType> + return startMappedReduced, ResultType> (pool, sequence, map, reduce, ResultType(std::forward(initialValue)), options); } @@ -192,9 +190,7 @@ QFuture mappedReduced(const Sequence &sequence, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> + return startMappedReduced, ResultType> (QThreadPool::globalInstance(), sequence, map, reduce, ResultType(std::forward(initialValue)), options); } @@ -258,9 +254,9 @@ QFuture mappedReduced(Iterator begin, ResultType(std::forward(initialValue)), options); } -template -QFuture::ResultType> mappedReduced( - QThreadPool *pool, +template ::ResultType> +QFuture mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map, @@ -268,22 +264,20 @@ QFuture::ResultType> mappedR ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced, - typename QtPrivate::ReduceResultType::ResultType> + return startMappedReduced, ResultType> (pool, begin, end, map, reduce, options); } -template -QFuture::ResultType> mappedReduced( - Iterator begin, +template ::ResultType> +QFuture mappedReduced(Iterator begin, Iterator end, MapFunctor map, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced, - typename QtPrivate::ReduceResultType::ResultType> + return startMappedReduced, ResultType> (QThreadPool::globalInstance(), begin, end, map, reduce, options); } @@ -291,8 +285,7 @@ template ::ResultType, typename InitialValueType, std::enable_if_t, int> = 0> -QFuture::ResultType> mappedReduced( - QThreadPool *pool, +QFuture mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map, @@ -301,9 +294,7 @@ QFuture::ResultType> mappedR ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> + return startMappedReduced, ResultType> (pool, begin, end, map, reduce, ResultType(std::forward(initialValue)), options); } @@ -312,8 +303,7 @@ template ::ResultType, typename InitialValueType, std::enable_if_t, int> = 0> -QFuture::ResultType> mappedReduced( - Iterator begin, +QFuture mappedReduced(Iterator begin, Iterator end, MapFunctor map, ReduceFunctor reduce, @@ -321,9 +311,7 @@ QFuture::ResultType> mappedR ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> + return startMappedReduced, ResultType> (QThreadPool::globalInstance(), begin, end, map, reduce, ResultType(std::forward(initialValue)), options); } @@ -372,26 +360,30 @@ QFuture> mapped( template void blockingMap(QThreadPool *pool, Sequence &sequence, MapFunctor map) { - startMap(pool, sequence.begin(), sequence.end(), map).startBlocking(); + QFuture future = startMap(pool, sequence.begin(), sequence.end(), map); + future.waitForFinished(); } template void blockingMap(Sequence &sequence, MapFunctor map) { - startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), map).startBlocking(); + QFuture future = startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), map); + future.waitForFinished(); } // blockingMap() for iterator ranges template void blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map) { - startMap(pool, begin, end, map).startBlocking(); + QFuture future = startMap(pool, begin, end, map); + future.waitForFinished(); } template void blockingMap(Iterator begin, Iterator end, MapFunctor map) { - startMap(QThreadPool::globalInstance(), begin, end, map).startBlocking(); + QFuture future = startMap(QThreadPool::globalInstance(), begin, end, map); + future.waitForFinished(); } // blockingMappedReduced() for sequences @@ -403,9 +395,10 @@ ResultType blockingMappedReduced(QThreadPool *pool, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced + QFuture future = QtConcurrent::startMappedReduced , ResultType> - (pool, sequence, map, reduce, options).startBlocking(); + (pool, sequence, map, reduce, options); + return future.result(); } template @@ -415,9 +408,10 @@ ResultType blockingMappedReduced(const Sequence &sequence, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced + QFuture future = QtConcurrent::startMappedReduced , ResultType> - (QThreadPool::globalInstance(), sequence, map, reduce, options).startBlocking(); + (QThreadPool::globalInstance(), sequence, map, reduce, options); + return future.result(); } template future = QtConcurrent::startMappedReduced , ResultType> (pool, sequence, map, reduce, ResultType(std::forward(initialValue)), - options).startBlocking(); + options); + return future.result(); } template future = QtConcurrent::startMappedReduced , ResultType> (QThreadPool::globalInstance(), sequence, map, reduce, - ResultType(std::forward(initialValue)), options) - .startBlocking(); + ResultType(std::forward(initialValue)), options); + return future.result(); } -template -typename QtPrivate::ReduceResultType::ResultType blockingMappedReduced( - QThreadPool *pool, +template ::ResultType> +ResultType blockingMappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> - (pool, sequence, map, reduce, options).startBlocking(); + QFuture future = QtConcurrent::startMappedReduced + , ResultType> + (pool, sequence, map, reduce, options); + return future.result(); } -template -typename QtPrivate::ReduceResultType::ResultType blockingMappedReduced( - const Sequence &sequence, +template ::ResultType> +ResultType blockingMappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> - (QThreadPool::globalInstance(), sequence, map, reduce, options).startBlocking(); + QFuture future = QtConcurrent::startMappedReduced + , ResultType> + (QThreadPool::globalInstance(), sequence, map, reduce, options); + return future.result(); } template ::ResultType, typename InitialValueType, std::enable_if_t, int> = 0> -typename QtPrivate::ReduceResultType::ResultType blockingMappedReduced( - QThreadPool *pool, +ResultType blockingMappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, @@ -496,30 +490,29 @@ typename QtPrivate::ReduceResultType::ResultType blockingMappedRe ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> + QFuture future = QtConcurrent::startMappedReduced + , ResultType> (pool, sequence, map, reduce, ResultType(std::forward(initialValue)), - options).startBlocking(); + options); + return future.result(); } template ::ResultType, typename InitialValueType, std::enable_if_t, int> = 0> -typename QtPrivate::ReduceResultType::ResultType blockingMappedReduced( - const Sequence &sequence, +ResultType blockingMappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> + QFuture future = QtConcurrent::startMappedReduced + , ResultType> (QThreadPool::globalInstance(), sequence, map, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + ResultType(std::forward(initialValue)), options); + return future.result(); } // blockingMappedReduced() for iterator ranges @@ -532,9 +525,10 @@ ResultType blockingMappedReduced(QThreadPool *pool, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced + QFuture future = QtConcurrent::startMappedReduced , ResultType> - (pool, begin, end, map, reduce, options).startBlocking(); + (pool, begin, end, map, reduce, options); + return future.result(); } template @@ -545,9 +539,10 @@ ResultType blockingMappedReduced(Iterator begin, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced + QFuture future = QtConcurrent::startMappedReduced , ResultType> - (QThreadPool::globalInstance(), begin, end, map, reduce, options).startBlocking(); + (QThreadPool::globalInstance(), begin, end, map, reduce, options); + return future.result(); } template future = QtConcurrent::startMappedReduced , ResultType> (pool, begin, end, map, reduce, ResultType(std::forward(initialValue)), - options).startBlocking(); + options); + return future.result(); } template future = QtConcurrent::startMappedReduced , ResultType> (QThreadPool::globalInstance(), begin, end, map, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + ResultType(std::forward(initialValue)), options); + return future.result(); } -template -typename QtPrivate::ReduceResultType::ResultType blockingMappedReduced( - QThreadPool *pool, +template ::ResultType> +ResultType blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map, @@ -595,33 +592,32 @@ typename QtPrivate::ReduceResultType::ResultType blockingMappedRe ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> - (pool, begin, end, map, reduce, options).startBlocking(); + QFuture future = QtConcurrent::startMappedReduced + , ResultType> + (pool, begin, end, map, reduce, options); + return future.result(); } -template -typename QtPrivate::ReduceResultType::ResultType blockingMappedReduced( - Iterator begin, +template ::ResultType> +ResultType blockingMappedReduced(Iterator begin, Iterator end, MapFunctor map, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> - (QThreadPool::globalInstance(), begin, end, map, reduce, options).startBlocking(); + QFuture future = QtConcurrent::startMappedReduced + , ResultType> + (QThreadPool::globalInstance(), begin, end, map, reduce, options); + return future.result(); } template ::ResultType, typename InitialValueType, std::enable_if_t, int> = 0> -typename QtPrivate::ReduceResultType::ResultType blockingMappedReduced( - QThreadPool *pool, +ResultType blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map, @@ -630,19 +626,18 @@ typename QtPrivate::ReduceResultType::ResultType blockingMappedRe ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> + QFuture future = QtConcurrent::startMappedReduced + , ResultType> (pool, begin, end, map, reduce, ResultType(std::forward(initialValue)), - options).startBlocking(); + options); + return future.result(); } template ::ResultType, typename InitialValueType, std::enable_if_t, int> = 0> -typename QtPrivate::ReduceResultType::ResultType blockingMappedReduced( - Iterator begin, +ResultType blockingMappedReduced(Iterator begin, Iterator end, MapFunctor map, ReduceFunctor reduce, @@ -650,11 +645,11 @@ typename QtPrivate::ReduceResultType::ResultType blockingMappedRe ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced - , - typename QtPrivate::ReduceResultType::ResultType> + QFuture future = QtConcurrent::startMappedReduced + , ResultType> (QThreadPool::globalInstance(), begin, end, map, reduce, - ResultType(std::forward(initialValue)), options).startBlocking(); + ResultType(std::forward(initialValue)), options); + return future.result(); } // mapped() for sequences with a different putput sequence type. diff --git a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp index dbcb0a1e9ad..ac8aec4dcdc 100644 --- a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp +++ b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp @@ -127,17 +127,15 @@ void testFilterThreadPool(QThreadPool *pool, FilterObject filterObject) { QList copy1 = sourceObjectList; -// QList copy2 = sourceObjectList; + QList copy2 = sourceObjectList; QtConcurrent::filter(pool, copy1, filterObject).waitForFinished(); QCOMPARE(copy1, expectedResult); QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// TODO: enable when QTBUG-83918 is fixed - -// QtConcurrent::blockingFilter(pool, copy2, filterObject); -// QCOMPARE(copy2, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working + QtConcurrent::blockingFilter(pool, copy2, filterObject); + QCOMPARE(copy2, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working } class KeepOddIntegers @@ -244,17 +242,15 @@ void testFilteredThreadPool(QThreadPool *pool, QCOMPARE(result2, expectedResult); QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// TODO: enable when QTBUG-83918 is fixed + const QList result3 = QtConcurrent::blockingFiltered( + pool, sourceObjectList, filterObject); + QCOMPARE(result3, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// const QList result3 = QtConcurrent::blockingFiltered( -// pool, sourceObjectList, filterObject); -// QCOMPARE(result3, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working - -// const QList result4 = QtConcurrent::blockingFiltered>( -// pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), filterObject); -// QCOMPARE(result4, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working + const QList result4 = QtConcurrent::blockingFiltered>( + pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), filterObject); + QCOMPARE(result4, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working } void tst_QtConcurrentFilter::filteredThreadPool() @@ -436,18 +432,16 @@ void testFilteredReducedThreadPool(QThreadPool *pool, QCOMPARE(result2, expectedResult); QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// TODO: enable when QTBUG-83918 is fixed + const ResultObject result3 = QtConcurrent::blockingFilteredReduced( + pool, sourceObjectList, filterObject, reduceObject); + QCOMPARE(result3, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// const ResultObject result3 = QtConcurrent::blockingFilteredReduced( -// pool, sourceObjectList, filterObject, reduceObject); -// QCOMPARE(result3, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working - -// const ResultObject result4 = QtConcurrent::blockingFilteredReduced( -// pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), -// filterObject, reduceObject); -// QCOMPARE(result4, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working + const ResultObject result4 = QtConcurrent::blockingFilteredReduced( + pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), + filterObject, reduceObject); + QCOMPARE(result4, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working } void tst_QtConcurrentFilter::filteredReducedThreadPool() @@ -711,18 +705,16 @@ void testFilteredReducedInitialValueThreadPool(QThreadPool *pool, QCOMPARE(result2, expectedResult); QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// TODO: enable when QTBUG-83918 is fixed + const ResultObject result3 = QtConcurrent::blockingFilteredReduced( + pool, sourceObjectList, filterObject, reduceObject, initialObject); + QCOMPARE(result3, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// const ResultObject result3 = QtConcurrent::blockingFilteredReduced( -// pool, sourceObjectList, filterObject, reduceObject, initialObject); -// QCOMPARE(result3, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working - -// const ResultObject result4 = QtConcurrent::blockingFilteredReduced( -// pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), -// filterObject, reduceObject, initialObject); -// QCOMPARE(result4, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working + const ResultObject result4 = QtConcurrent::blockingFilteredReduced( + pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), + filterObject, reduceObject, initialObject); + QCOMPARE(result4, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working } void tst_QtConcurrentFilter::filteredReducedInitialValueThreadPool() diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp index 9d904b6984b..fefa7676abb 100644 --- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp +++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp @@ -483,17 +483,15 @@ void testMappedThreadPool(QThreadPool *pool, QCOMPARE(result2, expectedResult); QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// TODO: enable when QTBUG-83918 is fixed + const QList result3 = QtConcurrent::blockingMapped(pool, + sourceObjectList, mapObject); + QCOMPARE(result3, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// const QList result3 = QtConcurrent::blockingMapped(pool, -// sourceObjectList, mapObject); -// QCOMPARE(result3, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working - -// const QList result4 = QtConcurrent::blockingMapped>(pool, -// sourceObjectList.constBegin(), sourceObjectList.constEnd(), mapObject); -// QCOMPARE(result4, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working + const QList result4 = QtConcurrent::blockingMapped>(pool, + sourceObjectList.constBegin(), sourceObjectList.constEnd(), mapObject); + QCOMPARE(result4, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working } int multiplyBy3(int x) @@ -678,17 +676,15 @@ void testMappedReducedThreadPool(QThreadPool *pool, QCOMPARE(result2, expectedResult); QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// TODO: enable when QTBUG-83918 is fixed + const ResultObject result3 = QtConcurrent::blockingMappedReduced(pool, + sourceObjectList, mapObject, reduceObject); + QCOMPARE(result3, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// const ResultObject result3 = QtConcurrent::blockingMappedReduced(pool, -// sourceObjectList, mapObject, reduceObject); -// QCOMPARE(result3, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working - -// const ResultObject result4 = QtConcurrent::blockingMappedReduced(pool, -// sourceObjectList.constBegin(), sourceObjectList.constEnd(), mapObject, reduceObject); -// QCOMPARE(result4, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working + const ResultObject result4 = QtConcurrent::blockingMappedReduced(pool, + sourceObjectList.constBegin(), sourceObjectList.constEnd(), mapObject, reduceObject); + QCOMPARE(result4, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working } int intCube(int x) @@ -930,18 +926,16 @@ void testMappedReducedInitialValueThreadPool(QThreadPool *pool, QCOMPARE(result2, expectedResult); QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// TODO: enable when QTBUG-83918 is fixed + const ResultObject result3 = QtConcurrent::blockingMappedReduced( + pool, sourceObjectList, mapObject, reduceObject, initialObject); + QCOMPARE(result3, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working -// const ResultObject result3 = QtConcurrent::blockingMappedReduced( -// pool, sourceObjectList, mapObject, reduceObject, initialObject); -// QCOMPARE(result3, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working - -// const ResultObject result4 = QtConcurrent::blockingMappedReduced( -// pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), -// mapObject, reduceObject, initialObject); -// QCOMPARE(result4, expectedResult); -// QCOMPARE(threadCount(), 1); // ensure the only one thread was working + const ResultObject result4 = QtConcurrent::blockingMappedReduced( + pool, sourceObjectList.constBegin(), sourceObjectList.constEnd(), + mapObject, reduceObject, initialObject); + QCOMPARE(result4, expectedResult); + QCOMPARE(threadCount(), 1); // ensure the only one thread was working } void tst_QtConcurrentMap::mappedReducedInitialValueThreadPool()