diff options
Diffstat (limited to 'src/concurrent')
-rw-r--r-- | src/concurrent/qtconcurrentfilter.h | 32 | ||||
-rw-r--r-- | src/concurrent/qtconcurrentmap.h | 34 | ||||
-rw-r--r-- | src/concurrent/qtconcurrentreducekernel.h | 2 | ||||
-rw-r--r-- | src/concurrent/qtconcurrentrunbase.h | 8 |
4 files changed, 48 insertions, 28 deletions
diff --git a/src/concurrent/qtconcurrentfilter.h b/src/concurrent/qtconcurrentfilter.h index d01b351ad0..532057c33c 100644 --- a/src/concurrent/qtconcurrentfilter.h +++ b/src/concurrent/qtconcurrentfilter.h @@ -136,7 +136,9 @@ QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, Iter template <typename Sequence, typename KeepFunctor> void blockingFilter(Sequence &sequence, KeepFunctor keep) { - filterInternal(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper()).startBlocking(); + QFuture<void> future = + filterInternal(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper()); + future.waitForFinished(); } // blocking filteredReduced() on sequences @@ -146,8 +148,9 @@ ResultType blockingFilteredReduced(const Sequence &sequence, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options) - .startBlocking(); + QFuture<ResultType> future = + startFilteredReduced<ResultType>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), options); + return future.result(); } #ifndef Q_CLANG_QDOC @@ -173,12 +176,11 @@ ResultType blockingFilteredReduced(Iterator begin, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<ResultType> - (begin, end, + QFuture<ResultType> future = startFilteredReduced<ResultType>(begin, end, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); + options); + return future.result(); } #ifndef Q_CLANG_QDOC @@ -189,12 +191,13 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFiltered ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> future = + startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> (begin, end, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); + options); + return future.result(); } #endif @@ -202,17 +205,20 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFiltered template <typename Sequence, typename KeepFunctor> Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep) { - return startFilteredReduced<Sequence>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); + QFuture<Sequence> future = + startFilteredReduced<Sequence>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper(), OrderedReduce); + return future.result(); } // blocking filtered() on iterators template <typename OutputSequence, typename Iterator, typename KeepFunctor> OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep) { - return startFilteredReduced<OutputSequence>(begin, end, + QFuture<OutputSequence> future = startFilteredReduced<OutputSequence>(begin, end, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper(), - OrderedReduce).startBlocking(); + OrderedReduce); + return future.result(); } } // namespace QtConcurrent diff --git a/src/concurrent/qtconcurrentmap.h b/src/concurrent/qtconcurrentmap.h index 151f03cf56..70eea29bca 100644 --- a/src/concurrent/qtconcurrentmap.h +++ b/src/concurrent/qtconcurrentmap.h @@ -143,14 +143,16 @@ QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped( template <typename Sequence, typename MapFunctor> void blockingMap(Sequence &sequence, MapFunctor map) { - startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map)).startBlocking(); + QFuture<void> future = startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map)); + future.waitForFinished(); } // blockingMap() for iterator ranges template <typename Iterator, typename MapFunctor> void blockingMap(Iterator begin, Iterator end, MapFunctor map) { - startMap(begin, end, QtPrivate::createFunctionWrapper(map)).startBlocking(); + QFuture<void> future = startMap(begin, end, QtPrivate::createFunctionWrapper(map)); + future.waitForFinished(); } // blockingMappedReduced() for sequences @@ -160,12 +162,13 @@ ResultType blockingMappedReduced(const Sequence &sequence, ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> + QFuture<ResultType> future = + QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> (sequence, QtPrivate::createFunctionWrapper(map), QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); + options); + return future.result(); } template <typename MapFunctor, typename ReduceFunctor, typename Sequence> @@ -174,12 +177,13 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedRe ReduceFunctor reduce, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) { - return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> future = + QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> (sequence, QtPrivate::createFunctionWrapper(map), QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); + options); + return future.result(); } // blockingMappedReduced() for iterator ranges @@ -190,12 +194,13 @@ ResultType blockingMappedReduced(Iterator begin, ReduceFunctor reduce, QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) { - return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> + QFuture<ResultType> future = + QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> (begin, end, QtPrivate::createFunctionWrapper(map), QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); + options); + return future.result(); } template <typename Iterator, typename MapFunctor, typename ReduceFunctor> @@ -205,12 +210,13 @@ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedRe ReduceFunctor reduce, QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) { - return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> + QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> future = + QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> (begin, end, QtPrivate::createFunctionWrapper(map), QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); + options); + return future.result(); } // mapped() for sequences with a different putput sequence type. diff --git a/src/concurrent/qtconcurrentreducekernel.h b/src/concurrent/qtconcurrentreducekernel.h index 8f9a938952..a98dedef2e 100644 --- a/src/concurrent/qtconcurrentreducekernel.h +++ b/src/concurrent/qtconcurrentreducekernel.h @@ -212,11 +212,13 @@ public: inline bool shouldThrottle() { + std::lock_guard<QMutex> locker(mutex); return (resultsMapSize > (ReduceQueueThrottleLimit * threadCount)); } inline bool shouldStartThread() { + std::lock_guard<QMutex> locker(mutex); return (resultsMapSize <= (ReduceQueueStartLimit * threadCount)); } }; diff --git a/src/concurrent/qtconcurrentrunbase.h b/src/concurrent/qtconcurrentrunbase.h index aaa1245856..632689e9e0 100644 --- a/src/concurrent/qtconcurrentrunbase.h +++ b/src/concurrent/qtconcurrentrunbase.h @@ -84,7 +84,13 @@ public: this->setRunnable(this); this->reportStarted(); QFuture<T> theFuture = this->future(); - pool->start(this, /*m_priority*/ 0); + if (pool) { + pool->start(this, /*m_priority*/ 0); + } else { + this->reportCanceled(); + this->reportFinished(); + delete this; + } return theFuture; } |