From 8a11641bb9709b2c6cb5051163eb5086838c8fac Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 28 Apr 2020 14:19:42 +0200 Subject: Enable setting custom QThreadPool for QtConcurrent methods Task-number: QTBUG-53465 Change-Id: Icff05d5f65dce453ff702502b85c35e20fca86a9 Reviewed-by: Sona Kurazyan --- src/concurrent/qtconcurrentmap.cpp | 253 ++++++++++++++++++++++++++++++++++++- 1 file changed, 246 insertions(+), 7 deletions(-) (limited to 'src/concurrent/qtconcurrentmap.cpp') diff --git a/src/concurrent/qtconcurrentmap.cpp b/src/concurrent/qtconcurrentmap.cpp index 2ad54835409..e60e35af328 100644 --- a/src/concurrent/qtconcurrentmap.cpp +++ b/src/concurrent/qtconcurrentmap.cpp @@ -319,26 +319,59 @@ \snippet code/src_concurrent_qtconcurrentmap.cpp 13 */ +/*! + \fn template QFuture 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 QFuture 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 QFuture 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 QFuture 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 QFuture> 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 QFuture> QtConcurrent::mapped(const Sequence &sequence, MapFunctor function) @@ -349,6 +382,17 @@ \sa {Concurrent Map and Map-Reduce} */ +/*! + \fn template QFuture> 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 QFuture> QtConcurrent::mapped(Iterator begin, Iterator end, MapFunctor function) @@ -359,6 +403,20 @@ \sa {Concurrent Map and Map-Reduce} */ +/*! + \fn template QFuture 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 QFuture QtConcurrent::mappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) @@ -372,6 +430,23 @@ \sa {Concurrent Map and Map-Reduce} */ +/*! + \fn template QFuture 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 QFuture QtConcurrent::mappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions) @@ -388,6 +463,22 @@ \sa {Concurrent Map and Map-Reduce} */ +/*! + \fn template QFuture 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 QFuture QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) @@ -403,6 +494,25 @@ \sa {Concurrent Map and Map-Reduce} */ +/*! + \fn template QFuture 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 QFuture QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions) @@ -421,11 +531,24 @@ \sa {Concurrent Map and Map-Reduce} */ +/*! + \fn template 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 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. @@ -433,11 +556,25 @@ \sa map(), {Concurrent Map and Map-Reduce} */ +/*! + \fn template 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 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 @@ -446,6 +583,18 @@ \sa map(), {Concurrent Map and Map-Reduce} */ +/*! + \fn template 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 OutputSequence QtConcurrent::blockingMapped(const InputSequence &sequence, MapFunctor function) @@ -457,11 +606,29 @@ \sa mapped(), {Concurrent Map and Map-Reduce} */ +/*! + \fn template 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 ints = QtConcurrent::blockingMapped >(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 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 @@ -474,6 +641,22 @@ \sa mapped(), {Concurrent Map and Map-Reduce} */ +/*! + \fn template 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 ResultType QtConcurrent::blockingMappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) @@ -489,6 +672,25 @@ \sa mapped(), {Concurrent Map and Map-Reduce} */ +/*! + \fn template 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 ResultType QtConcurrent::blockingMappedReduced(const Sequence &sequence, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions) @@ -507,6 +709,23 @@ \sa mapped(), {Concurrent Map and Map-Reduce} */ +/*! + \fn template 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 ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, QtConcurrent::ReduceOptions reduceOptions) @@ -523,6 +742,26 @@ \sa blockingMappedReduced(), {Concurrent Map and Map-Reduce} */ +/*! + \fn template 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 ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor mapFunction, ReduceFunctor reduceFunction, InitialValueType &&initialValue, QtConcurrent::ReduceOptions reduceOptions) -- cgit v1.2.3