summaryrefslogtreecommitdiffstats
path: root/src/concurrent
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2020-04-28 14:19:42 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2020-05-18 10:03:29 +0200
commit8a11641bb9709b2c6cb5051163eb5086838c8fac (patch)
treec1a684ba92207c5d05a253c08c499cf4d294573f /src/concurrent
parent4857fee0fc6a9b277a779266d521d4dc1ca3bd95 (diff)
Enable setting custom QThreadPool for QtConcurrent methods
Task-number: QTBUG-53465 Change-Id: Icff05d5f65dce453ff702502b85c35e20fca86a9 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/concurrent')
-rw-r--r--src/concurrent/qtconcurrentfilter.cpp263
-rw-r--r--src/concurrent/qtconcurrentfilter.h476
-rw-r--r--src/concurrent/qtconcurrentfilterkernel.h111
-rw-r--r--src/concurrent/qtconcurrentiteratekernel.h4
-rw-r--r--src/concurrent/qtconcurrentmap.cpp253
-rw-r--r--src/concurrent/qtconcurrentmap.h618
-rw-r--r--src/concurrent/qtconcurrentmapkernel.h90
-rw-r--r--src/concurrent/qtconcurrentreducekernel.h11
-rw-r--r--src/concurrent/qtconcurrentthreadengine.cpp4
-rw-r--r--src/concurrent/qtconcurrentthreadengine.h4
10 files changed, 1491 insertions, 343 deletions
diff --git a/src/concurrent/qtconcurrentfilter.cpp b/src/concurrent/qtconcurrentfilter.cpp
index 789188911e..6839de4641 100644
--- a/src/concurrent/qtconcurrentfilter.cpp
+++ b/src/concurrent/qtconcurrentfilter.cpp
@@ -236,6 +236,17 @@
*/
/*!
+ \fn template <typename Sequence, typename KeepFunctor> QFuture<void> QtConcurrent::filter(QThreadPool *pool, Sequence &sequence, KeepFunctor filterFunction)
+
+ Calls \a filterFunction once for each item in \a sequence.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true, the item is kept in \a sequence;
+ otherwise, the item is removed from \a sequence.
+
+ \sa {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename Sequence, typename KeepFunctor> QFuture<void> QtConcurrent::filter(Sequence &sequence, KeepFunctor filterFunction)
Calls \a filterFunction once for each item in \a sequence. If
@@ -246,6 +257,18 @@
*/
/*!
+ \fn template <typename Sequence, typename KeepFunctor> QFuture<Sequence::value_type> QtConcurrent::filtered(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction)
+
+ Calls \a filterFunction once for each item in \a sequence and returns a
+ new Sequence of kept items. All calls to \a filterFunction are invoked from the threads
+ taken from the QThreadPool \a pool. If \a filterFunction returns \c true, a copy of
+ the item is put in the new Sequence. Otherwise, the item will \e not
+ appear in the new Sequence.
+
+ \sa {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename Sequence, typename KeepFunctor> QFuture<Sequence::value_type> QtConcurrent::filtered(const Sequence &sequence, KeepFunctor filterFunction)
Calls \a filterFunction once for each item in \a sequence and returns a
@@ -257,6 +280,18 @@
*/
/*!
+ \fn template <typename Iterator, typename KeepFunctor> QFuture<typename QtConcurrent::qValueType<Iterator>::value_type> QtConcurrent::filtered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor filterFunction)
+
+ Calls \a filterFunction once for each item from \a begin to \a end and
+ returns a new Sequence of kept items. All calls to \a filterFunction are invoked from the threads
+ taken from the QThreadPool \a pool. If \a filterFunction returns \c true, a
+ copy of the item is put in the new Sequence. Otherwise, the item will
+ \e not appear in the new Sequence.
+
+ \sa {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename Iterator, typename KeepFunctor> QFuture<typename QtConcurrent::qValueType<Iterator>::value_type> QtConcurrent::filtered(Iterator begin, Iterator end, KeepFunctor filterFunction)
Calls \a filterFunction once for each item from \a begin to \a end and
@@ -268,6 +303,25 @@
*/
/*!
+ \fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a filterFunction once for each item in \a sequence.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true for an item, that item is then passed to
+ \a reduceFunction. In other words, the return value is the result of
+ \a reduceFunction for each item where \a filterFunction returns \c true.
+
+ Note that while \a filterFunction is called concurrently, only one thread
+ at a time will call \a reduceFunction. The order in which \a reduceFunction
+ is called is undefined if \a reduceOptions is
+ QtConcurrent::UnorderedReduce. If \a reduceOptions is
+ QtConcurrent::OrderedReduce, \a reduceFunction is called in the order of
+ the original sequence.
+
+ \sa {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
Calls \a filterFunction once for each item in \a sequence. If
@@ -286,6 +340,28 @@
*/
/*!
+ \fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a filterFunction once for each item in \a sequence.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true for an item, that item is then passed to
+ \a reduceFunction. In other words, the return value is the result of
+ \a reduceFunction for each item where \a filterFunction returns \c true.
+ The result value is initialized to \a initialValue when the function is
+ called, and the first call to \a reduceFunction will operate on
+ this value.
+
+ Note that while \a filterFunction is called concurrently, only one thread
+ at a time will call \a reduceFunction. The order in which \a reduceFunction
+ is called is undefined if \a reduceOptions is
+ QtConcurrent::UnorderedReduce. If \a reduceOptions is
+ QtConcurrent::OrderedReduce, \a reduceFunction is called in the order of
+ the original sequence.
+
+ \sa {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::filteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
Calls \a filterFunction once for each item in \a sequence. If
@@ -307,6 +383,25 @@
*/
/*!
+ \fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a filterFunction once for each item from \a begin to \a end.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true for an item, that item is then passed to
+ \a reduceFunction. In other words, the return value is the result of
+ \a reduceFunction for each item where \a filterFunction returns \c true.
+
+ Note that while \a filterFunction is called concurrently, only one thread
+ at a time will call \a reduceFunction. The order in which
+ \a reduceFunction is called is undefined if \a reduceOptions is
+ QtConcurrent::UnorderedReduce. If \a reduceOptions is
+ QtConcurrent::OrderedReduce, the \a reduceFunction is called in the order
+ of the original sequence.
+
+ \sa {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::filteredReduced(Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
Calls \a filterFunction once for each item from \a begin to \a end. If
@@ -325,6 +420,28 @@
*/
/*!
+ \fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a filterFunction once for each item from \a begin to \a end.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true for an item, that item is then passed to
+ \a reduceFunction. In other words, the return value is the result of
+ \a reduceFunction for each item where \a filterFunction returns \c true.
+ The result value is initialized to \a initialValue when the function is
+ called, and the first call to \a reduceFunction will operate on
+ this value.
+
+ Note that while \a filterFunction is called concurrently, only one thread
+ at a time will call \a reduceFunction. The order in which
+ \a reduceFunction is called is undefined if \a reduceOptions is
+ QtConcurrent::UnorderedReduce. If \a reduceOptions is
+ QtConcurrent::OrderedReduce, the \a reduceFunction is called in the order
+ of the original sequence.
+
+ \sa {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::filteredReduced(Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
Calls \a filterFunction once for each item from \a begin to \a end. If
@@ -346,6 +463,19 @@
*/
/*!
+ \fn template <typename Sequence, typename KeepFunctor> void QtConcurrent::blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor filterFunction)
+
+ Calls \a filterFunction once for each item in \a sequence.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true, the item is kept in \a sequence;
+ otherwise, the item is removed from \a sequence.
+
+ \note This function will block until all items in the sequence have been processed.
+
+ \sa {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename Sequence, typename KeepFunctor> void QtConcurrent::blockingFilter(Sequence &sequence, KeepFunctor filterFunction)
Calls \a filterFunction once for each item in \a sequence. If
@@ -358,6 +488,20 @@
*/
/*!
+ \fn template <typename Sequence, typename KeepFunctor> Sequence QtConcurrent::blockingFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction)
+
+ Calls \a filterFunction once for each item in \a sequence and returns a
+ new Sequence of kept items. All calls to \a filterFunction are invoked from the threads
+ taken from the QThreadPool \a pool. If \a filterFunction returns \c true, a copy of
+ the item is put in the new Sequence. Otherwise, the item will \e not
+ appear in the new Sequence.
+
+ \note This function will block until all items in the sequence have been processed.
+
+ \sa filtered(), {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename Sequence, typename KeepFunctor> Sequence QtConcurrent::blockingFiltered(const Sequence &sequence, KeepFunctor filterFunction)
Calls \a filterFunction once for each item in \a sequence and returns a
@@ -371,6 +515,21 @@
*/
/*!
+ \fn template <typename OutputSequence, typename Iterator, typename KeepFunctor> OutputSequence QtConcurrent::blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor filterFunction)
+
+ Calls \a filterFunction once for each item from \a begin to \a end and
+ returns a new Sequence of kept items. All calls to \a filterFunction are invoked from the threads
+ taken from the QThreadPool \a pool. If \a filterFunction returns \c true, a
+ copy of the item is put in the new Sequence. Otherwise, the item will
+ \e not appear in the new Sequence.
+
+ \note This function will block until the iterator reaches the end of the
+ sequence being processed.
+
+ \sa filtered(), {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename OutputSequence, typename Iterator, typename KeepFunctor> OutputSequence QtConcurrent::blockingFiltered(Iterator begin, Iterator end, KeepFunctor filterFunction)
Calls \a filterFunction once for each item from \a begin to \a end and
@@ -385,6 +544,27 @@
*/
/*!
+ \fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a filterFunction once for each item in \a sequence.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true for an item, that item is then passed to
+ \a reduceFunction. In other words, the return value is the result of
+ \a reduceFunction for each item where \a filterFunction returns \c true.
+
+ Note that while \a filterFunction is called concurrently, only one thread
+ at a time will call \a reduceFunction. The order in which \a reduceFunction
+ is called is undefined if \a reduceOptions is
+ QtConcurrent::UnorderedReduce. If \a reduceOptions is
+ QtConcurrent::OrderedReduce, \a reduceFunction is called in the order of
+ the original sequence.
+
+ \note This function will block until all items in the sequence have been processed.
+
+ \sa filteredReduced(), {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
Calls \a filterFunction once for each item in \a sequence. If
@@ -405,6 +585,30 @@
*/
/*!
+ \fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a filterFunction once for each item in \a sequence.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true for an item, that item is then passed to
+ \a reduceFunction. In other words, the return value is the result of
+ \a reduceFunction for each item where \a filterFunction returns \c true.
+ The result value is initialized to \a initialValue when the function is
+ called, and the first call to \a reduceFunction will operate on
+ this value.
+
+ Note that while \a filterFunction is called concurrently, only one thread
+ at a time will call \a reduceFunction. The order in which \a reduceFunction
+ is called is undefined if \a reduceOptions is
+ QtConcurrent::UnorderedReduce. If \a reduceOptions is
+ QtConcurrent::OrderedReduce, \a reduceFunction is called in the order of
+ the original sequence.
+
+ \note This function will block until all items in the sequence have been processed.
+
+ \sa filteredReduced(), {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingFilteredReduced(const Sequence &sequence, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
Calls \a filterFunction once for each item in \a sequence. If
@@ -428,6 +632,28 @@
*/
/*!
+ \fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a filterFunction once for each item from \a begin to \a end.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true for an item, that item is then passed to
+ \a reduceFunction. In other words, the return value is the result of
+ \a reduceFunction for each item where \a filterFunction returns \c true.
+
+ Note that while \a filterFunction is called concurrently, only one thread
+ at a time will call \a reduceFunction. The order in which
+ \a reduceFunction is called is undefined if \a reduceOptions is
+ QtConcurrent::UnorderedReduce. If \a reduceOptions is
+ QtConcurrent::OrderedReduce, the \a reduceFunction is called in the order
+ of the original sequence.
+
+ \note This function will block until the iterator reaches the end of the
+ sequence being processed.
+
+ \sa filteredReduced(), {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
Calls \a filterFunction once for each item from \a begin to \a end. If
@@ -449,6 +675,31 @@
*/
/*!
+ \fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a filterFunction once for each item from \a begin to \a end.
+ All calls to \a filterFunction are invoked from the threads taken from the QThreadPool \a pool.
+ If \a filterFunction returns \c true for an item, that item is then passed to
+ \a reduceFunction. In other words, the return value is the result of
+ \a reduceFunction for each item where \a filterFunction returns \c true.
+ The result value is initialized to \a initialValue when the function is
+ called, and the first call to \a reduceFunction will operate on
+ this value.
+
+ Note that while \a filterFunction is called concurrently, only one thread
+ at a time will call \a reduceFunction. The order in which
+ \a reduceFunction is called is undefined if \a reduceOptions is
+ QtConcurrent::UnorderedReduce. If \a reduceOptions is
+ QtConcurrent::OrderedReduce, the \a reduceFunction is called in the order
+ of the original sequence.
+
+ \note This function will block until the iterator reaches the end of the
+ sequence being processed.
+
+ \sa filteredReduced(), {Concurrent Filter and Filter-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor filterFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
Calls \a filterFunction once for each item from \a begin to \a end. If
@@ -473,31 +724,31 @@
*/
/*!
- \fn [QtConcurrent-2] ThreadEngineStarter<typename qValueType<Iterator>::value_type> QtConcurrent::startFiltered(Iterator begin, Iterator end, KeepFunctor functor)
+ \fn [QtConcurrent-2] ThreadEngineStarter<typename qValueType<Iterator>::value_type> QtConcurrent::startFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor functor)
\internal
*/
/*!
- \fn [QtConcurrent-3] ThreadEngineStarter<typename Sequence::value_type> QtConcurrent::startFiltered(const Sequence &sequence, KeepFunctor functor)
+ \fn [QtConcurrent-3] ThreadEngineStarter<typename Sequence::value_type> QtConcurrent::startFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor functor)
\internal
*/
/*!
- \fn [QtConcurrent-4] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(const Sequence & sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options)
+ \fn [QtConcurrent-4] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options)
\internal
*/
/*!
- \fn [QtConcurrent-5] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(Iterator begin, Iterator end, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options)
+ \fn [QtConcurrent-5] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ReduceOptions options)
\internal
*/
/*!
- \fn [QtConcurrent-6] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(Iterator begin, Iterator end, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ResultType initialValue, ReduceOptions options)
+ \fn [QtConcurrent-6] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ResultType initialValue, ReduceOptions options)
\internal
*/
/*!
- \fn [QtConcurrent-7] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(Iterator begin, Iterator end, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ResultType initialValue, ReduceOptions options)
+ \fn [QtConcurrent-7] ThreadEngineStarter<ResultType> QtConcurrent::startFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor mapFunctor, ReduceFunctor reduceFunctor, ResultType initialValue, ReduceOptions options)
\internal
*/
diff --git a/src/concurrent/qtconcurrentfilter.h b/src/concurrent/qtconcurrentfilter.h
index df4c9ed384..5feedec751 100644
--- a/src/concurrent/qtconcurrentfilter.h
+++ b/src/concurrent/qtconcurrentfilter.h
@@ -53,286 +53,560 @@ namespace QtConcurrent {
//! [QtConcurrent-1]
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
-ThreadEngineStarter<void> filterInternal(Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce)
+ThreadEngineStarter<void> filterInternal(QThreadPool *pool, Sequence &sequence,
+ KeepFunctor keep, ReduceFunctor reduce)
{
typedef FilterKernel<Sequence, KeepFunctor, ReduceFunctor> KernelType;
- return startThreadEngine(new KernelType(sequence, keep, reduce));
+ return startThreadEngine(new KernelType(pool, sequence, keep, reduce));
}
// filter() on sequences
template <typename Sequence, typename KeepFunctor>
+QFuture<void> filter(QThreadPool *pool, Sequence &sequence, KeepFunctor keep)
+{
+ return filterInternal(pool, sequence, keep, QtPrivate::PushBackWrapper());
+}
+
+template <typename Sequence, typename KeepFunctor>
QFuture<void> filter(Sequence &sequence, KeepFunctor keep)
{
- return filterInternal(sequence, keep, QtPrivate::PushBackWrapper());
+ return filterInternal(QThreadPool::globalInstance(),
+ sequence, keep, QtPrivate::PushBackWrapper());
}
// filteredReduced() on sequences
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
+QFuture<ResultType> filteredReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, options);
+}
+
+template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
QFuture<ResultType> filteredReduced(const Sequence &sequence,
KeepFunctor keep,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return startFilteredReduced<ResultType>(sequence, keep, reduce, options);
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
+ sequence, keep, reduce, options);
}
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-QFuture<ResultType> filteredReduced(const Sequence &sequence, KeepFunctor keep,
- ReduceFunctor reduce, InitialValueType &&initialValue,
+QFuture<ResultType> filteredReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
- return startFilteredReduced<ResultType>(
- sequence, keep,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options);
+ return startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
+}
+
+template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+QFuture<ResultType> filteredReduced(const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
}
#ifndef Q_CLANG_QDOC
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
-QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(const Sequence &sequence,
+QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(
+ QThreadPool *pool,
+ const Sequence &sequence,
KeepFunctor keep,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
- (sequence,
- keep,
- reduce,
- options);
+ (pool, sequence, keep, reduce, options);
+}
+
+template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
+QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(
+ const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), sequence, keep, reduce, options);
+}
+
+template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
+ typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+QFuture<ResultType> filteredReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
}
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-QFuture<ResultType> filteredReduced(const Sequence &sequence, KeepFunctor keep,
- ReduceFunctor reduce, InitialValueType &&initialValue,
+QFuture<ResultType> filteredReduced(const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
- return startFilteredReduced<ResultType>(
- sequence, keep,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options);
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
}
#endif
// filteredReduced() on iterators
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
+QFuture<ResultType> filteredReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, options);
+}
+
+template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
QFuture<ResultType> filteredReduced(Iterator begin,
Iterator end,
KeepFunctor keep,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return startFilteredReduced<ResultType>(begin, end, keep, reduce, options);
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce,
+ options);
}
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-QFuture<ResultType> filteredReduced(Iterator begin, Iterator end, KeepFunctor keep,
- ReduceFunctor reduce, InitialValueType &&initialValue,
+QFuture<ResultType> filteredReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
+}
+
+template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+QFuture<ResultType> filteredReduced(Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
- return startFilteredReduced<ResultType>(
- begin, end, keep,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options);
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
}
#ifndef Q_CLANG_QDOC
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor>
-QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(Iterator begin,
+QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(
+ QThreadPool *pool,
+ Iterator begin,
Iterator end,
KeepFunctor keep,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
- (begin, end,
- keep,
- reduce,
- options);
+ (pool, begin, end, keep, reduce, options);
+}
+
+template <typename Iterator, typename KeepFunctor, typename ReduceFunctor>
+QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> filteredReduced(
+ Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), begin, end, keep, reduce, options);
+}
+
+template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
+ typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+QFuture<ResultType> filteredReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
}
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-QFuture<ResultType> filteredReduced(Iterator begin, Iterator end, KeepFunctor keep,
- ReduceFunctor reduce, InitialValueType &&initialValue,
+QFuture<ResultType> filteredReduced(Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
- return startFilteredReduced<ResultType>(
- begin, end, keep,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options);
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
}
#endif
// filtered() on sequences
template <typename Sequence, typename KeepFunctor>
+QFuture<typename Sequence::value_type> filtered(QThreadPool *pool,
+ const Sequence &sequence,
+ KeepFunctor keep)
+{
+ return startFiltered(pool, sequence, keep);
+}
+
+template <typename Sequence, typename KeepFunctor>
QFuture<typename Sequence::value_type> filtered(const Sequence &sequence, KeepFunctor keep)
{
- return startFiltered(sequence, keep);
+ return startFiltered(QThreadPool::globalInstance(), sequence, keep);
}
// filtered() on iterators
template <typename Iterator, typename KeepFunctor>
-QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, Iterator end, KeepFunctor keep)
+QFuture<typename qValueType<Iterator>::value_type> filtered(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ KeepFunctor keep)
+{
+ return startFiltered(pool, begin, end, keep);
+}
+
+template <typename Iterator, typename KeepFunctor>
+QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin,
+ Iterator end,
+ KeepFunctor keep)
{
- return startFiltered(begin, end, keep);
+ return startFiltered(QThreadPool::globalInstance(), begin, end, keep);
}
// blocking filter() on sequences
template <typename Sequence, typename KeepFunctor>
+void blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor keep)
+{
+ filterInternal(pool, sequence, keep, QtPrivate::PushBackWrapper()).startBlocking();
+}
+
+template <typename Sequence, typename KeepFunctor>
void blockingFilter(Sequence &sequence, KeepFunctor keep)
{
- filterInternal(sequence, keep, QtPrivate::PushBackWrapper()).startBlocking();
+ filterInternal(QThreadPool::globalInstance(), sequence, keep, QtPrivate::PushBackWrapper())
+ .startBlocking();
}
// blocking filteredReduced() on sequences
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
-ResultType blockingFilteredReduced(const Sequence &sequence,
+ResultType blockingFilteredReduced(QThreadPool *pool,
+ const Sequence &sequence,
KeepFunctor keep,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return startFilteredReduced<ResultType>(sequence, keep, reduce, options)
+ return startFilteredReduced<ResultType>(pool, sequence, keep, reduce, options)
.startBlocking();
}
+template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
+ResultType blockingFilteredReduced(const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
+ sequence, keep, reduce, options).startBlocking();
+}
+
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-ResultType blockingFilteredReduced(const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce,
+ResultType blockingFilteredReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
- return startFilteredReduced<ResultType>(
- sequence, keep,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options)
- .startBlocking();
+ return startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
+}
+
+template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+ResultType blockingFilteredReduced(const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
}
#ifndef Q_CLANG_QDOC
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
-typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(const Sequence &sequence,
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(
+ QThreadPool *pool,
+ const Sequence &sequence,
KeepFunctor keep,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
- (sequence,
- keep,
- reduce,
- options).startBlocking();
+ (pool, sequence, keep, reduce, options).startBlocking();
+}
+
+template <typename Sequence, typename KeepFunctor, typename ReduceFunctor>
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(
+ const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), sequence, keep, reduce, options).startBlocking();
}
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-ResultType blockingFilteredReduced(const Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce,
+ResultType blockingFilteredReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
- return startFilteredReduced<ResultType>(
- sequence, keep,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options)
- .startBlocking();
+ return startFilteredReduced<ResultType>(pool, sequence, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
+}
+
+template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
+ typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+ResultType blockingFilteredReduced(const Sequence &sequence,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), sequence, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
}
#endif
// blocking filteredReduced() on iterators
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
-ResultType blockingFilteredReduced(Iterator begin,
+ResultType blockingFilteredReduced(QThreadPool *pool,
+ Iterator begin,
Iterator end,
KeepFunctor keep,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return startFilteredReduced<ResultType>
- (begin, end,
- keep,
- reduce,
- options)
+ return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce, options)
.startBlocking();
}
+template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
+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();
+}
+
+
+template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+ResultType blockingFilteredReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
+}
+
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-ResultType blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor keep,
- ReduceFunctor reduce, InitialValueType &&initialValue,
+ResultType blockingFilteredReduced(Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
- return startFilteredReduced<ResultType>(
- begin, end, keep,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options)
- .startBlocking();
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
}
#ifndef Q_CLANG_QDOC
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor>
-typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(Iterator begin,
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(
+ QThreadPool *pool,
+ Iterator begin,
Iterator end,
KeepFunctor keep,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
- (begin, end,
- keep,
- reduce,
- options)
- .startBlocking();
+ (pool, begin, end, keep, reduce, options).startBlocking();
+}
+
+template <typename Iterator, typename KeepFunctor, typename ReduceFunctor>
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingFilteredReduced(
+ Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), begin, end, keep, reduce, options).startBlocking();
+}
+
+template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
+ typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+ResultType blockingFilteredReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end, KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startFilteredReduced<ResultType>(pool, begin, end, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
}
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-ResultType blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor keep,
- ReduceFunctor reduce, InitialValueType &&initialValue,
+ResultType blockingFilteredReduced(Iterator begin,
+ Iterator end,
+ KeepFunctor keep,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
- return startFilteredReduced<ResultType>(
- begin, end, keep,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options)
- .startBlocking();
+ return startFilteredReduced<ResultType>(QThreadPool::globalInstance(), begin, end, keep, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
}
#endif
// blocking filtered() on sequences
template <typename Sequence, typename KeepFunctor>
+Sequence blockingFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor keep)
+{
+ return startFilteredReduced<Sequence>(pool, sequence, keep, QtPrivate::PushBackWrapper(),
+ OrderedReduce).startBlocking();
+}
+
+template <typename Sequence, typename KeepFunctor>
Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep)
{
- return startFilteredReduced<Sequence>(sequence, keep, QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking();
+ return startFilteredReduced<Sequence>(QThreadPool::globalInstance(), sequence, keep,
+ QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking();
}
// blocking filtered() on iterators
template <typename OutputSequence, typename Iterator, typename KeepFunctor>
+OutputSequence blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor keep)
+{
+ return startFilteredReduced<OutputSequence>(pool, begin, end, keep,
+ QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking();
+}
+
+template <typename OutputSequence, typename Iterator, typename KeepFunctor>
OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep)
{
- return startFilteredReduced<OutputSequence>(begin, end,
- keep,
- QtPrivate::PushBackWrapper(),
- OrderedReduce).startBlocking();
+ return startFilteredReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end, keep,
+ QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking();
}
} // namespace QtConcurrent
diff --git a/src/concurrent/qtconcurrentfilterkernel.h b/src/concurrent/qtconcurrentfilterkernel.h
index babd173ff8..90d5b9aa77 100644
--- a/src/concurrent/qtconcurrentfilterkernel.h
+++ b/src/concurrent/qtconcurrentfilterkernel.h
@@ -87,8 +87,9 @@ class FilterKernel : public IterateKernel<typename Sequence::const_iterator, voi
Reducer reducer;
public:
- FilterKernel(Sequence &_sequence, KeepFunctor _keep, ReduceFunctor _reduce)
- : IterateKernelType(const_cast<const Sequence &>(_sequence).begin(), const_cast<const Sequence &>(_sequence).end()), reducedResult(),
+ FilterKernel(QThreadPool *pool, Sequence &_sequence, KeepFunctor _keep, ReduceFunctor _reduce)
+ : IterateKernelType(pool, const_cast<const Sequence &>(_sequence).begin(),
+ const_cast<const Sequence &>(_sequence).end()), reducedResult(),
sequence(_sequence),
keep(_keep),
reduce(_reduce),
@@ -165,17 +166,20 @@ class FilteredReducedKernel : public IterateKernel<Iterator, ReducedResultType>
typedef IterateKernel<Iterator, ReducedResultType> IterateKernelType;
public:
- FilteredReducedKernel(Iterator begin,
+ FilteredReducedKernel(QThreadPool *pool,
+ Iterator begin,
Iterator end,
KeepFunctor _keep,
ReduceFunctor _reduce,
ReduceOptions reduceOption)
- : IterateKernelType(begin, end), reducedResult(), keep(_keep), reduce(_reduce), reducer(reduceOption)
+ : IterateKernelType(pool, begin, end), reducedResult(), keep(_keep), reduce(_reduce),
+ reducer(reduceOption)
{ }
- FilteredReducedKernel(Iterator begin, Iterator end, KeepFunctor _keep, ReduceFunctor _reduce,
- ReducedResultType &&initialValue, ReduceOptions reduceOption)
- : IterateKernelType(begin, end),
+ FilteredReducedKernel(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor _keep,
+ ReduceFunctor _reduce, ReducedResultType &&initialValue,
+ ReduceOptions reduceOption)
+ : IterateKernelType(pool, begin, end),
reducedResult(std::forward<ReducedResultType>(initialValue)),
keep(_keep),
reduce(_reduce),
@@ -251,8 +255,8 @@ public:
typedef T ReturnType;
typedef T ResultType;
- FilteredEachKernel(Iterator begin, Iterator end, KeepFunctor _keep)
- : IterateKernelType(begin, end), keep(_keep)
+ FilteredEachKernel(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor _keep)
+ : IterateKernelType(pool, begin, end), keep(_keep)
{ }
void start() override
@@ -296,73 +300,98 @@ public:
template <typename Iterator, typename KeepFunctor>
inline
ThreadEngineStarter<typename qValueType<Iterator>::value_type>
-startFiltered(Iterator begin, Iterator end, KeepFunctor functor)
+startFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor functor)
{
- return startThreadEngine(new FilteredEachKernel<Iterator, KeepFunctor>(begin, end, functor));
+ return startThreadEngine(new FilteredEachKernel<Iterator, KeepFunctor>
+ (pool, begin, end, functor));
}
//! [QtConcurrent-3]
template <typename Sequence, typename KeepFunctor>
inline ThreadEngineStarter<typename Sequence::value_type>
-startFiltered(const Sequence &sequence, KeepFunctor functor)
+startFiltered(QThreadPool *pool, const Sequence &sequence, KeepFunctor functor)
{
typedef SequenceHolder1<Sequence,
FilteredEachKernel<typename Sequence::const_iterator, KeepFunctor>,
KeepFunctor>
SequenceHolderType;
- return startThreadEngine(new SequenceHolderType(sequence, functor));
+ return startThreadEngine(new SequenceHolderType(pool, sequence, functor));
}
//! [QtConcurrent-4]
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
-inline ThreadEngineStarter<ResultType> startFilteredReduced(const Sequence & sequence,
- MapFunctor mapFunctor, ReduceFunctor reduceFunctor,
- ReduceOptions options)
+inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor mapFunctor,
+ ReduceFunctor reduceFunctor,
+ ReduceOptions options)
{
typedef typename Sequence::const_iterator Iterator;
- typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type > Reducer;
- typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer> FilteredReduceType;
- typedef SequenceHolder2<Sequence, FilteredReduceType, MapFunctor, ReduceFunctor> SequenceHolderType;
- return startThreadEngine(new SequenceHolderType(sequence, mapFunctor, reduceFunctor, options));
+ typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type >
+ Reducer;
+ typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
+ FilteredReduceType;
+ typedef SequenceHolder2<Sequence, FilteredReduceType, MapFunctor, ReduceFunctor>
+ SequenceHolderType;
+ return startThreadEngine(new SequenceHolderType(pool, sequence, mapFunctor,
+ reduceFunctor, options));
}
//! [QtConcurrent-5]
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
-inline ThreadEngineStarter<ResultType> startFilteredReduced(Iterator begin, Iterator end,
- MapFunctor mapFunctor, ReduceFunctor reduceFunctor,
- ReduceOptions options)
+inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor mapFunctor,
+ ReduceFunctor reduceFunctor,
+ ReduceOptions options)
{
- typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type> Reducer;
- typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer> FilteredReduceType;
- return startThreadEngine(new FilteredReduceType(begin, end, mapFunctor, reduceFunctor, options));
+ typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type>
+ Reducer;
+ typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
+ FilteredReduceType;
+ return startThreadEngine(new FilteredReduceType(pool, begin, end, mapFunctor,
+ reduceFunctor, options));
}
// Repeat the two functions above, but now with an initial value!
//! [QtConcurrent-6]
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
-inline ThreadEngineStarter<ResultType> startFilteredReduced(const Sequence & sequence,
- MapFunctor mapFunctor, ReduceFunctor reduceFunctor,
- ResultType &&initialValue,
- ReduceOptions options)
+inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor mapFunctor,
+ ReduceFunctor reduceFunctor,
+ ResultType &&initialValue,
+ ReduceOptions options)
{
typedef typename Sequence::const_iterator Iterator;
- typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type > Reducer;
- typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer> FilteredReduceType;
- typedef SequenceHolder2<Sequence, FilteredReduceType, MapFunctor, ReduceFunctor> SequenceHolderType;
- return startThreadEngine(new SequenceHolderType(sequence, mapFunctor, reduceFunctor, std::forward<ResultType>(initialValue), options));
+ typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type >
+ Reducer;
+ typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
+ FilteredReduceType;
+ typedef SequenceHolder2<Sequence, FilteredReduceType, MapFunctor, ReduceFunctor>
+ SequenceHolderType;
+ return startThreadEngine(new SequenceHolderType(pool, sequence, mapFunctor, reduceFunctor,
+ std::forward<ResultType>(initialValue), options));
}
//! [QtConcurrent-7]
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
-inline ThreadEngineStarter<ResultType> startFilteredReduced(Iterator begin, Iterator end,
- MapFunctor mapFunctor, ReduceFunctor reduceFunctor,
- ResultType &&initialValue,
- ReduceOptions options)
+inline ThreadEngineStarter<ResultType> startFilteredReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor mapFunctor,
+ ReduceFunctor reduceFunctor,
+ ResultType &&initialValue,
+ ReduceOptions options)
{
- typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type> Reducer;
- typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer> FilteredReduceType;
- return startThreadEngine(new FilteredReduceType(begin, end, mapFunctor, reduceFunctor, std::forward<ResultType>(initialValue), options));
+ typedef ReduceKernel<ReduceFunctor, ResultType, typename qValueType<Iterator>::value_type>
+ Reducer;
+ typedef FilteredReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
+ FilteredReduceType;
+ return startThreadEngine(new FilteredReduceType(pool, begin, end, mapFunctor, reduceFunctor,
+ std::forward<ResultType>(initialValue), options));
}
diff --git a/src/concurrent/qtconcurrentiteratekernel.h b/src/concurrent/qtconcurrentiteratekernel.h
index 09009efedc..efe679ccf2 100644
--- a/src/concurrent/qtconcurrentiteratekernel.h
+++ b/src/concurrent/qtconcurrentiteratekernel.h
@@ -158,8 +158,8 @@ class IterateKernel : public ThreadEngine<T>
public:
typedef T ResultType;
- IterateKernel(Iterator _begin, Iterator _end)
- : begin(_begin), end(_end), current(_begin), currentIndex(0),
+ IterateKernel(QThreadPool *pool, Iterator _begin, Iterator _end)
+ : ThreadEngine<T>(pool), begin(_begin), end(_end), current(_begin), currentIndex(0),
forIteration(selectIteration(typename std::iterator_traits<Iterator>::iterator_category())), progressReportingEnabled(true)
{
iterationCount = forIteration ? std::distance(_begin, _end) : 0;
diff --git a/src/concurrent/qtconcurrentmap.cpp b/src/concurrent/qtconcurrentmap.cpp
index 2ad5483540..e60e35af32 100644
--- a/src/concurrent/qtconcurrentmap.cpp
+++ b/src/concurrent/qtconcurrentmap.cpp
@@ -320,26 +320,59 @@
*/
/*!
+ \fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(QThreadPool *pool, Sequence &sequence, MapFunctor function)
+
+ Calls \a function once for each item in \a sequence.
+ All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
+ The \a function takes a reference to the item, so that any modifications done to the item
+ will appear in \a sequence.
+
+ \sa {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename Sequence, typename MapFunctor> QFuture<void> QtConcurrent::map(Sequence &sequence, MapFunctor function)
- Calls \a function once for each item in \a sequence. The \a function is
- passed a reference to the item, so that any modifications done to the item
+ Calls \a function once for each item in \a sequence. The \a function takes
+ a reference to the item, so that any modifications done to the item
will appear in \a sequence.
\sa {Concurrent Map and Map-Reduce}
*/
/*!
+ \fn template <typename Iterator, typename MapFunctor> QFuture<void> QtConcurrent::map(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor function)
+
+ Calls \a function once for each item from \a begin to \a end.
+ All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
+ The \a function takes a reference to the item, so that any modifications
+ done to the item will appear in the sequence which the iterators belong to.
+
+ \sa {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename Iterator, typename MapFunctor> QFuture<void> QtConcurrent::map(Iterator begin, Iterator end, MapFunctor function)
Calls \a function once for each item from \a begin to \a end. The
- \a function is passed a reference to the item, so that any modifications
+ \a function takes a reference to the item, so that any modifications
done to the item will appear in the sequence which the iterators belong to.
\sa {Concurrent Map and Map-Reduce}
*/
/*!
+ \fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(QThreadPool *pool, const Sequence &sequence, MapFunctor function)
+
+ Calls \a function once for each item in \a sequence and returns a future
+ with each mapped item as a result. All calls to \a function are invoked from the
+ threads taken from the QThreadPool \a pool. You can use QFuture::const_iterator or
+ QFutureIterator to iterate through the results.
+
+ \sa {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename Sequence, typename MapFunctor> QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> QtConcurrent::mapped(const Sequence &sequence, MapFunctor function)
Calls \a function once for each item in \a sequence and returns a future
@@ -350,6 +383,17 @@
*/
/*!
+ \fn template <typename Iterator, typename MapFunctor> QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> QtConcurrent::mapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor function)
+
+ Calls \a function once for each item from \a begin to \a end and returns a
+ future with each mapped item as a result. All calls to \a function are invoked from the
+ threads taken from the QThreadPool \a pool. You can use
+ QFuture::const_iterator or QFutureIterator to iterate through the results.
+
+ \sa {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename Iterator, typename MapFunctor> QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> QtConcurrent::mapped(Iterator begin, Iterator end, MapFunctor function)
Calls \a function once for each item from \a begin to \a end and returns a
@@ -360,6 +404,20 @@
*/
/*!
+ \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a mapFunction once for each item in \a sequence.
+ All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
+ The return value of each \a mapFunction is passed to \a reduceFunction.
+
+ Note that while \a mapFunction is called concurrently, only one thread at a
+ time will call \a reduceFunction. The order in which \a reduceFunction is
+ called is determined by \a reduceOptions.
+
+ \sa {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
Calls \a mapFunction once for each item in \a sequence. The return value of
@@ -373,6 +431,23 @@
*/
/*!
+ \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a mapFunction once for each item in \a sequence.
+ All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
+ The return value of each \a mapFunction is passed to \a reduceFunction.
+ The result value is initialized to \a initialValue when the function is
+ called, and the first call to \a reduceFunction will operate on
+ this value.
+
+ Note that while \a mapFunction is called concurrently, only one thread at a
+ time will call \a reduceFunction. The order in which \a reduceFunction is
+ called is determined by \a reduceOptions.
+
+ \sa {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
Calls \a mapFunction once for each item in \a sequence. The return value of
@@ -389,6 +464,22 @@
*/
/*!
+ \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a mapFunction once for each item from \a begin to \a end.
+ All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
+ The return value of each \a mapFunction is passed to \a reduceFunction.
+
+ Note that while \a mapFunction is called concurrently, only one thread at a
+ time will call \a reduceFunction. By default, the order in which
+ \a reduceFunction is called is undefined.
+
+ \note QtConcurrent::OrderedReduce results in the ordered reduction.
+
+ \sa {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> QFuture<ResultType> QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
Calls \a mapFunction once for each item from \a begin to \a end. The return
@@ -404,6 +495,25 @@
*/
/*!
+ \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a mapFunction once for each item from \a begin to \a end.
+ All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
+ The return value of each \a mapFunction is passed to \a reduceFunction.
+ The result value is initialized to \a initialValue when the function is
+ called, and the first call to \a reduceFunction will operate on
+ this value.
+
+ Note that while \a mapFunction is called concurrently, only one thread at a
+ time will call \a reduceFunction. By default, the order in which
+ \a reduceFunction is called is undefined.
+
+ \note QtConcurrent::OrderedReduce results in the ordered reduction.
+
+ \sa {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> QFuture<ResultType> QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
Calls \a mapFunction once for each item from \a begin to \a end. The return
@@ -422,10 +532,23 @@
*/
/*!
+ \fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(QThreadPool *pool, Sequence &sequence, MapFunctor function)
+
+ Calls \a function once for each item in \a sequence.
+ All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
+ The \a function takes a reference to the item, so that any modifications done to the item
+ will appear in \a sequence.
+
+ \note This function will block until all items in the sequence have been processed.
+
+ \sa map(), {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename Sequence, typename MapFunctor> void QtConcurrent::blockingMap(Sequence &sequence, MapFunctor function)
- Calls \a function once for each item in \a sequence. The \a function is
- passed a reference to the item, so that any modifications done to the item
+ Calls \a function once for each item in \a sequence. The \a function takes
+ a reference to the item, so that any modifications done to the item
will appear in \a sequence.
\note This function will block until all items in the sequence have been processed.
@@ -434,10 +557,24 @@
*/
/*!
+ \fn template <typename Iterator, typename MapFunctor> void QtConcurrent::blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor function)
+
+ Calls \a function once for each item from \a begin to \a end.
+ All calls to \a function are invoked from the threads taken from the QThreadPool \a pool.
+ The \a function takes a reference to the item, so that any modifications
+ done to the item will appear in the sequence which the iterators belong to.
+
+ \note This function will block until the iterator reaches the end of the
+ sequence being processed.
+
+ \sa map(), {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename Iterator, typename MapFunctor> void QtConcurrent::blockingMap(Iterator begin, Iterator end, MapFunctor function)
Calls \a function once for each item from \a begin to \a end. The
- \a function is passed a reference to the item, so that any modifications
+ \a function takes a reference to the item, so that any modifications
done to the item will appear in the sequence which the iterators belong to.
\note This function will block until the iterator reaches the end of the
@@ -447,6 +584,18 @@
*/
/*!
+ \fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(QThreadPool *pool, const InputSequence &sequence, MapFunctor function)
+
+ Calls \a function once for each item in \a sequence and returns an OutputSequence containing
+ the results. All calls to \a function are invoked from the threads taken from the QThreadPool
+ \a pool. The type of the results will match the type returned my the MapFunctor.
+
+ \note This function will block until all items in the sequence have been processed.
+
+ \sa mapped(), {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename OutputSequence, typename InputSequence, typename MapFunctor> OutputSequence QtConcurrent::blockingMapped(const InputSequence &sequence, MapFunctor function)
Calls \a function once for each item in \a sequence and returns an OutputSequence containing
@@ -458,10 +607,28 @@
*/
/*!
+ \fn template <typename Sequence, typename Iterator, typename MapFunctor> Sequence QtConcurrent::blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor function)
+
+ Calls \a function once for each item from \a begin to \a end and returns a
+ container with the results. All calls to \a function are invoked from the threads
+ taken from the QThreadPool \a pool. You can specify the type of container as the a template
+ argument, like this:
+
+ \code
+ QList<int> ints = QtConcurrent::blockingMapped<QList<int> >(beginIterator, endIterator, fn);
+ \endcode
+
+ \note This function will block until the iterator reaches the end of the
+ sequence being processed.
+
+ \sa mapped(), {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename Sequence, typename Iterator, typename MapFunctor> Sequence QtConcurrent::blockingMapped(Iterator begin, Iterator end, MapFunctor function)
Calls \a function once for each item from \a begin to \a end and returns a
- container with the results. Specify the type of container as the a template
+ container with the results. You can specify the type of container as the a template
argument, like this:
\code
@@ -475,6 +642,22 @@
*/
/*!
+ \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a mapFunction once for each item in \a sequence.
+ All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
+ The return value of each \a mapFunction is passed to \a reduceFunction.
+
+ Note that while \a mapFunction is called concurrently, only one thread at a
+ time will call \a reduceFunction. The order in which \a reduceFunction is
+ called is determined by \a reduceOptions.
+
+ \note This function will block until all items in the sequence have been processed.
+
+ \sa mapped(), {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
Calls \a mapFunction once for each item in \a sequence. The return value of
@@ -490,6 +673,25 @@
*/
/*!
+ \fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a mapFunction once for each item in \a sequence.
+ All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
+ The return value of each \a mapFunction is passed to \a reduceFunction.
+ The result value is initialized to \a initialValue when the function is
+ called, and the first call to \a reduceFunction will operate on
+ this value.
+
+ Note that while \a mapFunction is called concurrently, only one thread at a
+ time will call \a reduceFunction. The order in which \a reduceFunction is
+ called is determined by \a reduceOptions.
+
+ \note This function will block until all items in the sequence have been processed.
+
+ \sa mapped(), {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
Calls \a mapFunction once for each item in \a sequence. The return value of
@@ -508,6 +710,23 @@
*/
/*!
+ \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a mapFunction once for each item from \a begin to \a end.
+ All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
+ The return value of each \a mapFunction is passed to \a reduceFunction.
+
+ Note that while \a mapFunction is called concurrently, only one thread at a
+ time will call \a reduceFunction. The order in which \a reduceFunction is
+ called is undefined.
+
+ \note This function will block until the iterator reaches the end of the
+ sequence being processed.
+
+ \sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions)
Calls \a mapFunction once for each item from \a begin to \a end. The return
@@ -524,6 +743,26 @@
*/
/*!
+ \fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
+
+ Calls \a mapFunction once for each item from \a begin to \a end.
+ All calls to \a mapFunction are invoked from the threads taken from the QThreadPool \a pool.
+ The return value of each \a mapFunction is passed to \a reduceFunction.
+ The result value is initialized to \a initialValue when the function is
+ called, and the first call to \a reduceFunction will operate on
+ this value.
+
+ Note that while \a mapFunction is called concurrently, only one thread at a
+ time will call \a reduceFunction. The order in which \a reduceFunction is
+ called is undefined.
+
+ \note This function will block until the iterator reaches the end of the
+ sequence being processed.
+
+ \sa blockingMappedReduced(), {Concurrent Map and Map-Reduce}
+*/
+
+/*!
\fn template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType> ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions)
Calls \a mapFunction once for each item from \a begin to \a end. The return
diff --git a/src/concurrent/qtconcurrentmap.h b/src/concurrent/qtconcurrentmap.h
index 9b8ccc3eaf..7076d9ecde 100644
--- a/src/concurrent/qtconcurrentmap.h
+++ b/src/concurrent/qtconcurrentmap.h
@@ -57,119 +57,254 @@ namespace QtConcurrent {
// map() on sequences
template <typename Sequence, typename MapFunctor>
+QFuture<void> map(QThreadPool *pool, Sequence &sequence, MapFunctor map)
+{
+ return startMap(pool, sequence.begin(), sequence.end(), map);
+}
+
+template <typename Sequence, typename MapFunctor>
QFuture<void> map(Sequence &sequence, MapFunctor map)
{
- return startMap(sequence.begin(), sequence.end(), map);
+ return startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), map);
}
// map() on iterators
template <typename Iterator, typename MapFunctor>
+QFuture<void> map(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map)
+{
+ return startMap(pool, begin, end, map);
+}
+
+template <typename Iterator, typename MapFunctor>
QFuture<void> map(Iterator begin, Iterator end, MapFunctor map)
{
- return startMap(begin, end, map);
+ return startMap(QThreadPool::globalInstance(), begin, end, map);
}
// mappedReduced() for sequences.
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
+QFuture<ResultType> mappedReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
+ (pool, sequence, map, reduce, options);
+}
+
+template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
QFuture<ResultType> mappedReduced(const Sequence &sequence,
MapFunctor map,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
- (sequence,
- map,
- reduce,
+ (QThreadPool::globalInstance(), sequence, map, reduce, options);
+}
+
+template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+QFuture<ResultType> mappedReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
+ (pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options);
}
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-QFuture<ResultType> mappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce,
+QFuture<ResultType> mappedReduced(const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
+ return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
+ (QThreadPool::globalInstance(), sequence, map, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
+}
+
+template <typename Sequence, typename MapFunctor, typename ReduceFunctor>
+QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(
+ QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>,
- ResultType>(sequence, map,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)),
- options);
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (pool, sequence, map, reduce, options);
}
template <typename Sequence, typename MapFunctor, typename ReduceFunctor>
-QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(const Sequence &sequence,
+QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(
+ const Sequence &sequence,
MapFunctor map,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
- (sequence,
- map,
- reduce,
- options);
+ (QThreadPool::globalInstance(), sequence, map, reduce, options);
}
template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-QFuture<ResultType> mappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce,
+QFuture<ResultType> mappedReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
return startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>,
- typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>(
- sequence, map,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options);
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
+ options);
+}
+
+template <typename Sequence, typename MapFunctor, typename ReduceFunctor,
+ typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+QFuture<ResultType> mappedReduced(const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startMappedReduced
+ <QtPrivate::MapResultType<Sequence, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), sequence, map, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
}
// mappedReduced() for iterators
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
+QFuture<ResultType> mappedReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
+ (pool, begin, end, map, reduce, options);
+}
+
+template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
QFuture<ResultType> mappedReduced(Iterator begin,
Iterator end,
MapFunctor map,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
- (begin, end,
- map,
- reduce,
- options);
+ (QThreadPool::globalInstance(), begin, end, map, reduce, options);
}
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-QFuture<ResultType> mappedReduced(Iterator begin, Iterator end, MapFunctor map,
- ReduceFunctor reduce, InitialValueType &&initialValue,
+QFuture<ResultType> mappedReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
+ (pool, begin, end, map, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
+}
+
+template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+QFuture<ResultType> mappedReduced(Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
+ (QThreadPool::globalInstance(), begin, end, map, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
+}
+
+template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
+QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(
+ QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>,
- ResultType>(begin, end, map,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)),
- options);
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (pool, begin, end, map, reduce, options);
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
-QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(Iterator begin,
+QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(
+ Iterator begin,
Iterator end,
MapFunctor map,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>,
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
- (begin, end,
- map,
- reduce,
+ (QThreadPool::globalInstance(), begin, end, map, reduce, options);
+}
+
+template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
+ typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(
+ QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options);
}
@@ -178,156 +313,328 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(
- Iterator begin, Iterator end, MapFunctor map, ReduceFunctor reduce,
- InitialValueType &&initialValue,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>,
- typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>(
- begin, end, map,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options);
+ return startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), begin, end, map, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options);
}
// mapped() for sequences
template <typename Sequence, typename MapFunctor>
-QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped(const Sequence &sequence, MapFunctor map)
+QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped(
+ QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor map)
+{
+ return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>(pool, sequence, map);
+}
+
+template <typename Sequence, typename MapFunctor>
+QFuture<QtPrivate::MapResultType<Sequence, MapFunctor>> mapped(
+ const Sequence &sequence,
+ MapFunctor map)
{
- return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>(sequence, map);
+ return startMapped<QtPrivate::MapResultType<Sequence, MapFunctor>>
+ (QThreadPool::globalInstance(), sequence, map);
}
// mapped() for iterator ranges.
template <typename Iterator, typename MapFunctor>
-QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> mapped(Iterator begin, Iterator end, MapFunctor map)
+QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> mapped(
+ QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor map)
{
- return startMapped<QtPrivate::MapResultType<Iterator, MapFunctor>>(begin, end, map);
+ return startMapped<QtPrivate::MapResultType<Iterator, MapFunctor>>(pool, begin, end, map);
+}
+
+template <typename Iterator, typename MapFunctor>
+QFuture<QtPrivate::MapResultType<Iterator, MapFunctor>> mapped(
+ Iterator begin,
+ Iterator end,
+ MapFunctor map)
+{
+ return startMapped<QtPrivate::MapResultType<Iterator, MapFunctor>>
+ (QThreadPool::globalInstance(), begin, end, map);
}
// blockingMap() for sequences
template <typename Sequence, typename MapFunctor>
+void blockingMap(QThreadPool *pool, Sequence &sequence, MapFunctor map)
+{
+ startMap(pool, sequence.begin(), sequence.end(), map).startBlocking();
+}
+
+template <typename Sequence, typename MapFunctor>
void blockingMap(Sequence &sequence, MapFunctor map)
{
- startMap(sequence.begin(), sequence.end(), map).startBlocking();
+ startMap(QThreadPool::globalInstance(), sequence.begin(), sequence.end(), map).startBlocking();
}
// blockingMap() for iterator ranges
template <typename Iterator, typename MapFunctor>
+void blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map)
+{
+ startMap(pool, begin, end, map).startBlocking();
+}
+
+template <typename Iterator, typename MapFunctor>
void blockingMap(Iterator begin, Iterator end, MapFunctor map)
{
- startMap(begin, end, map).startBlocking();
+ startMap(QThreadPool::globalInstance(), begin, end, map).startBlocking();
}
// blockingMappedReduced() for sequences
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
+ResultType blockingMappedReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
+ (pool, sequence, map, reduce, options).startBlocking();
+}
+
+template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
ResultType blockingMappedReduced(const Sequence &sequence,
MapFunctor map,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return QtConcurrent::startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
- (sequence,
- map,
- reduce,
- options)
- .startBlocking();
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
+ (QThreadPool::globalInstance(), sequence, map, reduce, options).startBlocking();
}
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-ResultType blockingMappedReduced(const Sequence &sequence, MapFunctor map, ReduceFunctor reduce,
+ResultType blockingMappedReduced(QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
InitialValueType &&initialValue,
ReduceOptions options = ReduceOptions(UnorderedReduce
| SequentialReduce))
{
- return QtConcurrent::startMappedReduced<
- QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>(
- sequence, map,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options)
- .startBlocking();
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
+ (pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
+ options).startBlocking();
}
-template <typename MapFunctor, typename ReduceFunctor, typename Sequence>
-typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(const Sequence &sequence,
+template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+ResultType blockingMappedReduced(const Sequence &sequence,
MapFunctor map,
ReduceFunctor reduce,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
-{
- return QtConcurrent::startMappedReduced<QtPrivate::MapResultType<Sequence, MapFunctor>,
- typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
- (sequence,
- map,
- reduce,
- options)
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
+ (QThreadPool::globalInstance(), sequence, map, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options)
.startBlocking();
}
+template <typename MapFunctor, typename ReduceFunctor, typename Sequence>
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(
+ QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Sequence, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (pool, sequence, map, reduce, options).startBlocking();
+}
+
+template <typename MapFunctor, typename ReduceFunctor, typename Sequence>
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Sequence, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), sequence, map, reduce, options).startBlocking();
+}
+
+template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
+ typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(
+ QThreadPool *pool,
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Sequence, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (pool, sequence, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
+ options).startBlocking();
+}
+
template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(
- const Sequence &sequence, MapFunctor map, ReduceFunctor reduce,
- InitialValueType &&initialValue,
- ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
+ const Sequence &sequence,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return QtConcurrent::startMappedReduced<
- QtPrivate::MapResultType<Sequence, MapFunctor>,
- typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>(
- sequence, map,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options)
- .startBlocking();
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Sequence, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), sequence, map, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
}
// blockingMappedReduced() for iterator ranges
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
+ResultType blockingMappedReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
+ (pool, begin, end, map, reduce, options).startBlocking();
+}
+
+template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
ResultType blockingMappedReduced(Iterator begin,
Iterator end,
MapFunctor map,
ReduceFunctor reduce,
- QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return QtConcurrent::startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
- (begin, end,
- map,
- reduce,
- options)
- .startBlocking();
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
+ (QThreadPool::globalInstance(), begin, end, map, reduce, options).startBlocking();
+}
+
+template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+ResultType blockingMappedReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
+ (pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
+ options).startBlocking();
}
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
-ResultType blockingMappedReduced(Iterator begin, Iterator end, MapFunctor map, ReduceFunctor reduce,
+ResultType blockingMappedReduced(Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
InitialValueType &&initialValue,
- QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(
- QtConcurrent::UnorderedReduce
- | QtConcurrent::SequentialReduce))
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return QtConcurrent::startMappedReduced<
- QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>(
- begin, end, map,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options)
- .startBlocking();
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
+ (QThreadPool::globalInstance(), begin, end, map, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
-typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(Iterator begin,
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(
+ QThreadPool *pool,
+ Iterator begin,
Iterator end,
MapFunctor map,
ReduceFunctor reduce,
- QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
-{
- return QtConcurrent::startMappedReduced<QtPrivate::MapResultType<Iterator, MapFunctor>,
- typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
- (begin, end,
- map,
- reduce,
- options)
- .startBlocking();
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (pool, begin, end, map, reduce, options).startBlocking();
+}
+
+template <typename Iterator, typename MapFunctor, typename ReduceFunctor>
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), begin, end, map, reduce, options).startBlocking();
+}
+
+template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
+ typename ResultType = typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType,
+ typename InitialValueType,
+ std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
+typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(
+ QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
+{
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
+ options).startBlocking();
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
@@ -335,62 +642,83 @@ template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
typename InitialValueType,
std::enable_if_t<std::is_convertible_v<InitialValueType, ResultType>, int> = 0>
typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(
- Iterator begin, Iterator end, MapFunctor map, ReduceFunctor reduce,
- InitialValueType &&initialValue,
- QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(
- QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
+ Iterator begin,
+ Iterator end,
+ MapFunctor map,
+ ReduceFunctor reduce,
+ InitialValueType &&initialValue,
+ ReduceOptions options = ReduceOptions(UnorderedReduce
+ | SequentialReduce))
{
- return QtConcurrent::startMappedReduced<
- QtPrivate::MapResultType<Iterator, MapFunctor>,
- typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>(
- begin, end, map,
- reduce,
- ResultType(std::forward<InitialValueType>(initialValue)), options)
- .startBlocking();
+ return QtConcurrent::startMappedReduced
+ <QtPrivate::MapResultType<Iterator, MapFunctor>,
+ typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType>
+ (QThreadPool::globalInstance(), begin, end, map, reduce,
+ ResultType(std::forward<InitialValueType>(initialValue)), options).startBlocking();
}
// mapped() for sequences with a different putput sequence type.
template <typename OutputSequence, typename InputSequence, typename MapFunctor>
+OutputSequence blockingMapped(QThreadPool *pool, const InputSequence &sequence, MapFunctor map)
+{
+ return blockingMappedReduced<OutputSequence>(pool, sequence, map,
+ QtPrivate::PushBackWrapper(), OrderedReduce);
+}
+
+template <typename OutputSequence, typename InputSequence, typename MapFunctor>
OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map)
{
- return blockingMappedReduced<OutputSequence>
- (sequence,
- map,
- QtPrivate::PushBackWrapper(),
- QtConcurrent::OrderedReduce);
+ return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(), sequence, map,
+ QtPrivate::PushBackWrapper(), OrderedReduce);
+}
+
+template <typename MapFunctor, typename InputSequence>
+auto blockingMapped(QThreadPool *pool, const InputSequence &sequence, MapFunctor map)
+{
+ using OutputSequence = typename QtPrivate::MapSequenceResultType<InputSequence,
+ MapFunctor>::ResultType;
+ return blockingMappedReduced<OutputSequence>(pool, sequence, map, QtPrivate::PushBackWrapper(),
+ OrderedReduce);
}
template <typename MapFunctor, typename InputSequence>
auto blockingMapped(const InputSequence &sequence, MapFunctor map)
{
- using OutputSequence = typename QtPrivate::MapSequenceResultType<InputSequence, MapFunctor>::ResultType;
- return blockingMappedReduced<OutputSequence>
- (sequence,
- map,
- QtPrivate::PushBackWrapper(),
- QtConcurrent::OrderedReduce);
+ using OutputSequence = typename QtPrivate::MapSequenceResultType<InputSequence,
+ MapFunctor>::ResultType;
+ return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(), sequence, map,
+ QtPrivate::PushBackWrapper(), OrderedReduce);
}
// mapped() for iterator ranges
template <typename Sequence, typename Iterator, typename MapFunctor>
+Sequence blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map)
+{
+ return blockingMappedReduced<Sequence>(pool, begin, end, map,
+ QtPrivate::PushBackWrapper(), OrderedReduce);
+}
+
+template <typename Sequence, typename Iterator, typename MapFunctor>
Sequence blockingMapped(Iterator begin, Iterator end, MapFunctor map)
{
- return blockingMappedReduced<Sequence>
- (begin, end,
- map,
- QtPrivate::PushBackWrapper(),
- QtConcurrent::OrderedReduce);
+ return blockingMappedReduced<Sequence>(QThreadPool::globalInstance(), begin, end, map,
+ QtPrivate::PushBackWrapper(), OrderedReduce);
+}
+
+template <typename Iterator, typename MapFunctor>
+auto blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor map)
+{
+ using OutputSequence = QtPrivate::MapResultType<Iterator, MapFunctor>;
+ return blockingMappedReduced<OutputSequence>(pool, begin, end, map,
+ QtPrivate::PushBackWrapper(), OrderedReduce);
}
template <typename Iterator, typename MapFunctor>
auto blockingMapped(Iterator begin, Iterator end, MapFunctor map)
{
using OutputSequence = QtPrivate::MapResultType<Iterator, MapFunctor>;
- return blockingMappedReduced<OutputSequence>
- (begin, end,
- map,
- QtPrivate::PushBackWrapper(),
- QtConcurrent::OrderedReduce);
+ return blockingMappedReduced<OutputSequence>(QThreadPool::globalInstance(), begin, end, map,
+ QtPrivate::PushBackWrapper(), OrderedReduce);
}
} // namespace QtConcurrent
diff --git a/src/concurrent/qtconcurrentmapkernel.h b/src/concurrent/qtconcurrentmapkernel.h
index 346ffbfc7f..e882dbfa75 100644
--- a/src/concurrent/qtconcurrentmapkernel.h
+++ b/src/concurrent/qtconcurrentmapkernel.h
@@ -60,8 +60,8 @@ class MapKernel : public IterateKernel<Iterator, void>
MapFunctor map;
public:
typedef void ReturnType;
- MapKernel(Iterator begin, Iterator end, MapFunctor _map)
- : IterateKernel<Iterator, void>(begin, end), map(_map)
+ MapKernel(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor _map)
+ : IterateKernel<Iterator, void>(pool, begin, end), map(_map)
{ }
bool runIteration(Iterator it, int, void *) override
@@ -100,13 +100,16 @@ class MappedReducedKernel : public IterateKernel<Iterator, ReducedResultType>
public:
typedef ReducedResultType ReturnType;
- MappedReducedKernel(Iterator begin, Iterator end, MapFunctor _map, ReduceFunctor _reduce, ReduceOptions reduceOptions)
- : IterateKernel<Iterator, ReducedResultType>(begin, end), reducedResult(), map(_map), reduce(_reduce), reducer(reduceOptions)
+ MappedReducedKernel(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor _map,
+ ReduceFunctor _reduce, ReduceOptions reduceOptions)
+ : IterateKernel<Iterator, ReducedResultType>(pool, begin, end), reducedResult(),
+ map(_map), reduce(_reduce), reducer(reduceOptions)
{ }
- MappedReducedKernel(Iterator begin, Iterator end, MapFunctor _map, ReduceFunctor _reduce,
- ReducedResultType &&initialValue, ReduceOptions reduceOptions)
- : IterateKernel<Iterator, ReducedResultType>(begin, end),
+ MappedReducedKernel(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor _map,
+ ReduceFunctor _reduce, ReducedResultType &&initialValue,
+ ReduceOptions reduceOptions)
+ : IterateKernel<Iterator, ReducedResultType>(pool, begin, end),
reducedResult(std::forward<ReducedResultType>(initialValue)),
map(_map),
reduce(_reduce),
@@ -172,8 +175,8 @@ class MappedEachKernel : public IterateKernel<Iterator, QtPrivate::MapResultType
using T = QtPrivate::MapResultType<Iterator, MapFunctor>;
public:
- MappedEachKernel(Iterator begin, Iterator end, MapFunctor _map)
- : IterateKernel<Iterator, T>(begin, end), map(_map) { }
+ MappedEachKernel(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor _map)
+ : IterateKernel<Iterator, T>(pool, begin, end), map(_map) { }
bool runIteration(Iterator it, int, T *result) override
{
@@ -197,16 +200,18 @@ public:
//! [qtconcurrentmapkernel-1]
template <typename Iterator, typename Functor>
-inline ThreadEngineStarter<void> startMap(Iterator begin, Iterator end, Functor functor)
+inline ThreadEngineStarter<void> startMap(QThreadPool *pool, Iterator begin,
+ Iterator end, Functor functor)
{
- return startThreadEngine(new MapKernel<Iterator, Functor>(begin, end, functor));
+ return startThreadEngine(new MapKernel<Iterator, Functor>(pool, begin, end, functor));
}
//! [qtconcurrentmapkernel-2]
template <typename T, typename Iterator, typename Functor>
-inline ThreadEngineStarter<T> startMapped(Iterator begin, Iterator end, Functor functor)
+inline ThreadEngineStarter<T> startMapped(QThreadPool *pool, Iterator begin,
+ Iterator end, Functor functor)
{
- return startThreadEngine(new MappedEachKernel<Iterator, Functor>(begin, end, functor));
+ return startThreadEngine(new MappedEachKernel<Iterator, Functor>(pool, begin, end, functor));
}
/*
@@ -216,8 +221,8 @@ inline ThreadEngineStarter<T> startMapped(Iterator begin, Iterator end, Functor
template <typename Sequence, typename Base, typename Functor>
struct SequenceHolder1 : public Base
{
- SequenceHolder1(const Sequence &_sequence, Functor functor)
- : Base(_sequence.begin(), _sequence.end(), functor), sequence(_sequence)
+ SequenceHolder1(QThreadPool *pool, const Sequence &_sequence, Functor functor)
+ : Base(pool, _sequence.begin(), _sequence.end(), functor), sequence(_sequence)
{ }
Sequence sequence;
@@ -233,43 +238,57 @@ struct SequenceHolder1 : public Base
//! [qtconcurrentmapkernel-3]
template <typename T, typename Sequence, typename Functor>
-inline ThreadEngineStarter<T> startMapped(const Sequence &sequence, Functor functor)
+inline ThreadEngineStarter<T> startMapped(QThreadPool *pool, const Sequence &sequence,
+ Functor functor)
{
typedef SequenceHolder1<Sequence,
MappedEachKernel<typename Sequence::const_iterator , Functor>, Functor>
SequenceHolderType;
- return startThreadEngine(new SequenceHolderType(sequence, functor));
+ return startThreadEngine(new SequenceHolderType(pool, sequence, functor));
}
//! [qtconcurrentmapkernel-4]
-template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
-inline ThreadEngineStarter<ResultType> startMappedReduced(const Sequence & sequence,
- MapFunctor mapFunctor, ReduceFunctor reduceFunctor,
- ReduceOptions options)
+template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor,
+ typename ReduceFunctor>
+inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
+ const Sequence & sequence,
+ MapFunctor mapFunctor,
+ ReduceFunctor reduceFunctor,
+ ReduceOptions options)
{
typedef typename Sequence::const_iterator Iterator;
typedef ReduceKernel<ReduceFunctor, ResultType, IntermediateType> Reducer;
- typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer> MappedReduceType;
- typedef SequenceHolder2<Sequence, MappedReduceType, MapFunctor, ReduceFunctor> SequenceHolderType;
- return startThreadEngine(new SequenceHolderType(sequence, mapFunctor, reduceFunctor, options));
+ typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
+ MappedReduceType;
+ typedef SequenceHolder2<Sequence, MappedReduceType, MapFunctor, ReduceFunctor>
+ SequenceHolderType;
+ return startThreadEngine(new SequenceHolderType(pool, sequence, mapFunctor, reduceFunctor,
+ options));
}
//! [qtconcurrentmapkernel-5]
-template <typename IntermediateType, typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
-inline ThreadEngineStarter<ResultType> startMappedReduced(Iterator begin, Iterator end,
- MapFunctor mapFunctor, ReduceFunctor reduceFunctor,
- ReduceOptions options)
+template <typename IntermediateType, typename ResultType, typename Iterator, typename MapFunctor,
+ typename ReduceFunctor>
+inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
+ MapFunctor mapFunctor,
+ ReduceFunctor reduceFunctor,
+ ReduceOptions options)
{
typedef ReduceKernel<ReduceFunctor, ResultType, IntermediateType> Reducer;
- typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer> MappedReduceType;
- return startThreadEngine(new MappedReduceType(begin, end, mapFunctor, reduceFunctor, options));
+ typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
+ MappedReduceType;
+ return startThreadEngine(new MappedReduceType(pool, begin, end, mapFunctor, reduceFunctor,
+ options));
}
//! [qtconcurrentmapkernel-6]
template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor,
typename ReduceFunctor>
-inline ThreadEngineStarter<ResultType> startMappedReduced(const Sequence &sequence,
+inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
+ const Sequence &sequence,
MapFunctor mapFunctor,
ReduceFunctor reduceFunctor,
ResultType &&initialValue,
@@ -282,13 +301,16 @@ inline ThreadEngineStarter<ResultType> startMappedReduced(const Sequence &sequen
typedef SequenceHolder2<Sequence, MappedReduceType, MapFunctor, ReduceFunctor>
SequenceHolderType;
return startThreadEngine(new SequenceHolderType(
- sequence, mapFunctor, reduceFunctor, std::forward<ResultType>(initialValue), options));
+ pool, sequence, mapFunctor, reduceFunctor, std::forward<ResultType>(initialValue),
+ options));
}
//! [qtconcurrentmapkernel-7]
template <typename IntermediateType, typename ResultType, typename Iterator, typename MapFunctor,
typename ReduceFunctor>
-inline ThreadEngineStarter<ResultType> startMappedReduced(Iterator begin, Iterator end,
+inline ThreadEngineStarter<ResultType> startMappedReduced(QThreadPool *pool,
+ Iterator begin,
+ Iterator end,
MapFunctor mapFunctor,
ReduceFunctor reduceFunctor,
ResultType &&initialValue,
@@ -297,7 +319,7 @@ inline ThreadEngineStarter<ResultType> startMappedReduced(Iterator begin, Iterat
typedef ReduceKernel<ReduceFunctor, ResultType, IntermediateType> Reducer;
typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer>
MappedReduceType;
- return startThreadEngine(new MappedReduceType(begin, end, mapFunctor, reduceFunctor,
+ return startThreadEngine(new MappedReduceType(pool, begin, end, mapFunctor, reduceFunctor,
std::forward<ResultType>(initialValue), options));
}
diff --git a/src/concurrent/qtconcurrentreducekernel.h b/src/concurrent/qtconcurrentreducekernel.h
index a487ec26a2..4c023ebb4a 100644
--- a/src/concurrent/qtconcurrentreducekernel.h
+++ b/src/concurrent/qtconcurrentreducekernel.h
@@ -224,21 +224,24 @@ public:
template <typename Sequence, typename Base, typename Functor1, typename Functor2>
struct SequenceHolder2 : public Base
{
- SequenceHolder2(const Sequence &_sequence,
+ SequenceHolder2(QThreadPool *pool,
+ const Sequence &_sequence,
Functor1 functor1,
Functor2 functor2,
ReduceOptions reduceOptions)
- : Base(_sequence.begin(), _sequence.end(), functor1, functor2, reduceOptions),
+ : Base(pool, _sequence.begin(), _sequence.end(), functor1, functor2, reduceOptions),
sequence(_sequence)
{ }
template <typename InitialValueType>
- SequenceHolder2(const Sequence &_sequence,
+ SequenceHolder2(QThreadPool *pool,
+ const Sequence &_sequence,
Functor1 functor1,
Functor2 functor2,
InitialValueType &&initialValue,
ReduceOptions reduceOptions)
- : Base(_sequence.begin(), _sequence.end(), functor1, functor2, std::forward<InitialValueType>(initialValue), reduceOptions),
+ : Base(pool, _sequence.begin(), _sequence.end(), functor1, functor2,
+ std::forward<InitialValueType>(initialValue), reduceOptions),
sequence(_sequence)
{ }
diff --git a/src/concurrent/qtconcurrentthreadengine.cpp b/src/concurrent/qtconcurrentthreadengine.cpp
index cf424912b3..7dfc29c68f 100644
--- a/src/concurrent/qtconcurrentthreadengine.cpp
+++ b/src/concurrent/qtconcurrentthreadengine.cpp
@@ -160,8 +160,8 @@ bool ThreadEngineBarrier::releaseUnlessLast()
}
}
-ThreadEngineBase::ThreadEngineBase()
-:futureInterface(0), threadPool(QThreadPool::globalInstance())
+ThreadEngineBase::ThreadEngineBase(QThreadPool *pool)
+ : futureInterface(0), threadPool(pool)
{
setAutoDelete(false);
}
diff --git a/src/concurrent/qtconcurrentthreadengine.h b/src/concurrent/qtconcurrentthreadengine.h
index a04f69f8e4..eb11c34c06 100644
--- a/src/concurrent/qtconcurrentthreadengine.h
+++ b/src/concurrent/qtconcurrentthreadengine.h
@@ -88,7 +88,7 @@ class Q_CONCURRENT_EXPORT ThreadEngineBase: public QRunnable
{
public:
// Public API:
- ThreadEngineBase();
+ ThreadEngineBase(QThreadPool *pool);
virtual ~ThreadEngineBase();
void startSingleThreaded();
void startBlocking();
@@ -131,6 +131,8 @@ class ThreadEngine : public ThreadEngineBase
public:
typedef T ResultType;
+ ThreadEngine(QThreadPool *pool) : ThreadEngineBase(pool) {}
+
virtual T *result() { return nullptr; }
QFutureInterface<T> *futureInterfaceTyped()