diff options
Diffstat (limited to 'src/corelib')
42 files changed, 15 insertions, 9864 deletions
diff --git a/src/corelib/concurrent/concurrent.pri b/src/corelib/concurrent/concurrent.pri deleted file mode 100644 index 940297139c..0000000000 --- a/src/corelib/concurrent/concurrent.pri +++ /dev/null @@ -1,42 +0,0 @@ -SOURCES += \ - concurrent/qfuture.cpp \ - concurrent/qfutureinterface.cpp \ - concurrent/qfuturesynchronizer.cpp \ - concurrent/qfuturewatcher.cpp \ - concurrent/qrunnable.cpp \ - concurrent/qtconcurrentfilter.cpp \ - concurrent/qtconcurrentmap.cpp \ - concurrent/qtconcurrentresultstore.cpp \ - concurrent/qtconcurrentthreadengine.cpp \ - concurrent/qtconcurrentiteratekernel.cpp \ - concurrent/qtconcurrentexception.cpp \ - concurrent/qthreadpool.cpp - -HEADERS += \ - concurrent/qfuture.h \ - concurrent/qfutureinterface.h \ - concurrent/qfuturesynchronizer.h \ - concurrent/qfuturewatcher.h \ - concurrent/qrunnable.h \ - concurrent/qtconcurrentcompilertest.h \ - concurrent/qtconcurrentexception.h \ - concurrent/qtconcurrentfilter.h \ - concurrent/qtconcurrentfilterkernel.h \ - concurrent/qtconcurrentfunctionwrappers.h \ - concurrent/qtconcurrentiteratekernel.h \ - concurrent/qtconcurrentmap.h \ - concurrent/qtconcurrentmapkernel.h \ - concurrent/qtconcurrentmedian.h \ - concurrent/qtconcurrentreducekernel.h \ - concurrent/qtconcurrentresultstore.h \ - concurrent/qtconcurrentrun.h \ - concurrent/qtconcurrentrunbase.h \ - concurrent/qtconcurrentstoredfunctioncall.h \ - concurrent/qtconcurrentthreadengine.h \ - concurrent/qthreadpool.h - -# private headers -HEADERS += \ - concurrent/qfutureinterface_p.h \ - concurrent/qfuturewatcher_p.h \ - concurrent/qthreadpool_p.h diff --git a/src/corelib/concurrent/qfuture.cpp b/src/corelib/concurrent/qfuture.cpp deleted file mode 100644 index 9805454cb2..0000000000 --- a/src/corelib/concurrent/qfuture.cpp +++ /dev/null @@ -1,697 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! \class QFuture - \threadsafe - \brief The QFuture class represents the result of an asynchronous computation. - \since 4.4 - - \ingroup thread - - To start a computation, use one of the APIs in the - \l {Concurrent Programming}{Qt Concurrent} framework. - - QFuture allows threads to be synchronized against one or more results - which will be ready at a later point in time. The result can be of any type - that has a default constructor and a copy constructor. If a result is not - available at the time of calling the result(), resultAt(), or results() - functions, QFuture will wait until the result becomes available. You can - use the isResultReadyAt() function to determine if a result is ready or - not. For QFuture objects that report more than one result, the - resultCount() function returns the number of continuous results. This - means that it is always safe to iterate through the results from 0 to - resultCount(). - - QFuture provides a \l{Java-style iterators}{Java-style iterator} - (QFutureIterator) and an \l{STL-style iterators}{STL-style iterator} - (QFuture::const_iterator). Using these iterators is another way to access - results in the future. - - QFuture also offers ways to interact with a runnning computation. For - instance, the computation can be canceled with the cancel() function. To - pause the computation, use the setPaused() function or one of the pause(), - resume(), or togglePaused() convenience functions. Be aware that not all - asynchronous computations can be canceled or paused. For example, the - future returned by QtConcurrent::run() cannot be canceled; but the - future returned by QtConcurrent::mappedReduced() can. - - Progress information is provided by the progressValue(), - progressMinimum(), progressMaximum(), and progressText() functions. The - waitForFinished() function causes the calling thread to block and wait for - the computation to finish, ensuring that all results are available. - - The state of the computation represented by a QFuture can be queried using - the isCanceled(), isStarted(), isFinished(), isRunning(), or isPaused() - functions. - - QFuture is a lightweight reference counted class that can be passed by - value. - - QFuture<void> is specialized to not contain any of the result fetching - functions. Any QFuture<T> can be assigned or copied into a QFuture<void> - as well. This is useful if only status or progress information is needed - - not the actual result data. - - To interact with running tasks using signals and slots, use QFutureWatcher. - - \sa QFutureWatcher, {Concurrent Programming}{Qt Concurrent} -*/ - -/*! \fn QFuture::QFuture() - - Constructs an empty future. -*/ - -/*! \fn QFuture::QFuture(const QFuture &other) - - Constructs a copy of \a other. - - \sa operator=() -*/ - -/*! \fn QFuture::QFuture(QFutureInterface<T> *resultHolder) - \internal -*/ - -/*! \fn QFuture::~QFuture() - - Destroys the future. - - Note that this neither waits nor cancels the asynchronous computation. Use - waitForFinished() or QFutureSynchronizer when you need to ensure that the - computation is completed before the future is destroyed. -*/ - -/*! \fn QFuture &QFuture::operator=(const QFuture &other) - - Assigns \a other to this future and returns a reference to this future. -*/ - -/*! \fn bool QFuture::operator==(const QFuture &other) const - - Returns true if \a other is a copy of this future; otherwise returns false. -*/ - -/*! \fn bool QFuture::operator!=(const QFuture &other) const - - Returns true if \a other is \e not a copy of this future; otherwise returns - false. -*/ - -/*! \fn void QFuture::cancel() - - Cancels the asynchronous computation represented by this future. Note that - the cancelation is asynchronous. Use waitForFinished() after calling - cancel() when you need synchronous cancelation. - - Results currently available may still be accessed on a canceled future, - but new results will \e not become available after calling this function. - Any QFutureWatcher object that is watching this future will not deliver - progress and result ready signals on a canceled future. - - Be aware that not all asynchronous computations can be canceled. For - example, the future returned by QtConcurrent::run() cannot be canceled; - but the future returned by QtConcurrent::mappedReduced() can. -*/ - -/*! \fn bool QFuture::isCanceled() const - - Returns true if the asynchronous computation has been canceled with the - cancel() function; otherwise returns false. - - Be aware that the computation may still be running even though this - function returns true. See cancel() for more details. -*/ - -/*! \fn void QFuture::setPaused(bool paused) - - If \a paused is true, this function pauses the asynchronous computation - represented by the future. If the computation is already paused, this - function does nothing. Any QFutureWatcher object that is watching this - future will stop delivering progress and result ready signals while the - future is paused. Signal delivery will continue once the future is - resumed. - - If \a paused is false, this function resumes the asynchronous computation. - If the computation was not previously paused, this function does nothing. - - Be aware that not all computations can be paused. For example, the future - returned by QtConcurrent::run() cannot be paused; but the future returned - by QtConcurrent::mappedReduced() can. - - \sa pause(), resume(), togglePaused() -*/ - -/*! \fn bool QFuture::isPaused() const - - Returns true if the asynchronous computation has been paused with the - pause() function; otherwise returns false. - - Be aware that the computation may still be running even though this - function returns true. See setPaused() for more details. - - \sa setPaused(), togglePaused() -*/ - -/*! \fn void QFuture::pause() - - Pauses the asynchronous computation represented by this future. This is a - convenience method that simply calls setPaused(true). - - \sa resume() -*/ - -/*! \fn void QFuture::resume() - - Resumes the asynchronous computation represented by this future. This is a - convenience method that simply calls setPaused(false). - - \sa pause() -*/ - -/*! \fn void QFuture::togglePaused() - - Toggles the paused state of the asynchronous computation. In other words, - if the computation is currently paused, calling this function resumes it; - if the computation is running, it is paused. This is a convenience method - for calling setPaused(!isPaused()). - - \sa setPaused(), pause(), resume() -*/ - -/*! \fn bool QFuture::isStarted() const - - Returns true if the asynchronous computation represented by this future - has been started; otherwise returns false. -*/ - -/*! \fn bool QFuture::isFinished() const - - Returns true if the asynchronous computation represented by this future - has finished; otherwise returns false. -*/ - -/*! \fn bool QFuture::isRunning() const - - Returns true if the asynchronous computation represented by this future is - currently running; otherwise returns false. -*/ - -/*! \fn int QFuture::resultCount() const - - Returns the number of continuous results available in this future. The real - number of results stored might be different from this value, due to gaps - in the result set. It is always safe to iterate through the results from 0 - to resultCount(). - \sa result(), resultAt(), results() -*/ - -/*! \fn int QFuture::progressValue() const - - Returns the current progress value, which is between the progressMinimum() - and progressMaximum(). - - \sa progressMinimum(), progressMaximum() -*/ - -/*! \fn int QFuture::progressMinimum() const - - Returns the minimum progressValue(). - - \sa progressValue(), progressMaximum() -*/ - -/*! \fn int QFuture::progressMaximum() const - - Returns the maximum progressValue(). - - \sa progressValue(), progressMinimum() -*/ - -/*! \fn QString QFuture::progressText() const - - Returns the (optional) textual representation of the progress as reported - by the asynchronous computation. - - Be aware that not all computations provide a textual representation of the - progress, and as such, this function may return an empty string. -*/ - -/*! \fn void QFuture::waitForFinished() - - Waits for the asynchronous computation to finish (including cancel()ed - computations). -*/ - -/*! \fn T QFuture::result() const - - Returns the first result in the future. If the result is not immediately - available, this function will block and wait for the result to become - available. This is a convenience method for calling resultAt(0). - - \sa resultAt(), results() -*/ - -/*! \fn T QFuture::resultAt(int index) const - - Returns the result at \a index in the future. If the result is not - immediately available, this function will block and wait for the result to - become available. - - \sa result(), results(), resultCount() -*/ - -/*! \fn bool QFuture::isResultReadyAt(int index) const - - Returns true if the result at \a index is immediately available; otherwise - returns false. - - \sa resultAt(), resultCount() -*/ - -/*! \fn QFuture::operator T() const - - Returns the first result in the future. If the result is not immediately - available, this function will block and wait for the result to become - available. This is a convenience method for calling result() or - resultAt(0). - - \sa result(), resultAt(), results() -*/ - -/*! \fn QList<T> QFuture::results() const - - Returns all results from the future. If the results are not immediately - available, this function will block and wait for them to become available. - - \sa result(), resultAt(), resultCount() -*/ - -/*! \fn QFuture::const_iterator QFuture::begin() const - - Returns a const \l{STL-style iterator} pointing to the first result in the - future. - - \sa constBegin(), end() -*/ - -/*! \fn QFuture::const_iterator QFuture::end() const - - Returns a const \l{STL-style iterator} pointing to the imaginary result - after the last result in the future. - - \sa begin(), constEnd() -*/ - -/*! \fn QFuture::const_iterator QFuture::constBegin() const - - Returns a const \l{STL-style iterator} pointing to the first result in the - future. - - \sa begin(), constEnd() -*/ - -/*! \fn QFuture::const_iterator QFuture::constEnd() const - - Returns a const \l{STL-style iterator} pointing to the imaginary result - after the last result in the future. - - \sa constBegin(), end() -*/ - -/*! \class QFuture::const_iterator - \reentrant - \since 4.4 - - \brief The QFuture::const_iterator class provides an STL-style const - iterator for QFuture. - - QFuture provides both \l{STL-style iterators} and \l{Java-style iterators}. - The STL-style iterators are more low-level and more cumbersome to use; on - the other hand, they are slightly faster and, for developers who already - know STL, have the advantage of familiarity. - - The default QFuture::const_iterator constructor creates an uninitialized - iterator. You must initialize it using a QFuture function like - QFuture::constBegin() or QFuture::constEnd() before you start iterating. - Here's a typical loop that prints all the results available in a future: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp 0 - - \sa QFutureIterator, QFuture -*/ - -/*! \typedef QFuture::const_iterator::iterator_category - - Typedef for std::bidirectional_iterator_tag. Provided for STL compatibility. -*/ - -/*! \typedef QFuture::const_iterator::difference_type - - Typedef for ptrdiff_t. Provided for STL compatibility. -*/ - -/*! \typedef QFuture::const_iterator::value_type - - Typedef for T. Provided for STL compatibility. -*/ - -/*! \typedef QFuture::const_iterator::pointer - - Typedef for const T *. Provided for STL compatibility. -*/ - -/*! \typedef QFuture::const_iterator::reference - - Typedef for const T &. Provided for STL compatibility. -*/ - -/*! \fn QFuture::const_iterator::const_iterator() - - Constructs an uninitialized iterator. - - Functions like operator*() and operator++() should not be called on an - uninitialized iterartor. Use operator=() to assign a value to it before - using it. - - \sa QFuture::constBegin() QFuture::constEnd() -*/ - -/*! \fn QFuture::const_iterator::const_iterator(QFuture const * const future, int index) - \internal -*/ - -/*! \fn QFuture::const_iterator::const_iterator(const const_iterator &other) - - Constructs a copy of \a other. -*/ - -/*! \fn QFuture::const_iterator &QFuture::const_iterator::operator=(const const_iterator &other) - - Assigns \a other to this iterator. -*/ - -/*! \fn const T &QFuture::const_iterator::operator*() const - - Returns the current result. -*/ - -/*! \fn const T *QFuture::const_iterator::operator->() const - - Returns a pointer to the current result. -*/ - -/*! \fn bool QFuture::const_iterator::operator!=(const const_iterator &other) const - - Returns true if \a other points to a different result than this iterator; - otherwise returns false. - - \sa operator==() -*/ - -/*! \fn bool QFuture::const_iterator::operator==(const const_iterator &other) const - - Returns true if \a other points to the same result as this iterator; - otherwise returns false. - - \sa operator!=() -*/ - -/*! \fn QFuture::const_iterator &QFuture::const_iterator::operator++() - - The prefix ++ operator (\c{++it}) advances the iterator to the next result - in the future and returns an iterator to the new current result. - - Calling this function on QFuture::constEnd() leads to undefined results. - - \sa operator--() -*/ - -/*! \fn QFuture::const_iterator QFuture::const_iterator::operator++(int) - - \overload - - The postfix ++ operator (\c{it++}) advances the iterator to the next - result in the future and returns an iterator to the previously current - result. -*/ - -/*! \fn QFuture::const_iterator &QFuture::const_iterator::operator--() - - The prefix -- operator (\c{--it}) makes the preceding result current and - returns an iterator to the new current result. - - Calling this function on QFuture::constBegin() leads to undefined results. - - \sa operator++() -*/ - -/*! \fn QFuture::const_iterator QFuture::const_iterator::operator--(int) - - \overload - - The postfix -- operator (\c{it--}) makes the preceding result current and - returns an iterator to the previously current result. -*/ - -/*! \fn QFuture::const_iterator &QFuture::const_iterator::operator+=(int j) - - Advances the iterator by \a j results. (If \a j is negative, the iterator - goes backward.) - - \sa operator-=(), operator+() -*/ - -/*! \fn QFuture::const_iterator &QFuture::const_iterator::operator-=(int j) - - Makes the iterator go back by \a j results. (If \a j is negative, the - iterator goes forward.) - - \sa operator+=(), operator-() -*/ - -/*! \fn QFuture::const_iterator QFuture::const_iterator::operator+(int j) const - - Returns an iterator to the results at \a j positions forward from this - iterator. (If \a j is negative, the iterator goes backward.) - - \sa operator-(), operator+=() -*/ - -/*! \fn QFuture::const_iterator QFuture::const_iterator::operator-(int j) const - - Returns an iterator to the result at \a j positions backward from this - iterator. (If \a j is negative, the iterator goes forward.) - - \sa operator+(), operator-=() -*/ - -/*! \typedef QFuture::ConstIterator - - Qt-style synonym for QFuture::const_iterator. -*/ - -/*! - \class QFutureIterator - \reentrant - \since 4.4 - \inmodule QtCore - - \brief The QFutureIterator class provides a Java-style const iterator for - QFuture. - - QFuture has both \l{Java-style iterators} and \l{STL-style iterators}. The - Java-style iterators are more high-level and easier to use than the - STL-style iterators; on the other hand, they are slightly less efficient. - - An alternative to using iterators is to use index positions. Some QFuture - member functions take an index as their first parameter, making it - possible to access results without using iterators. - - QFutureIterator\<T\> allows you to iterate over a QFuture\<T\>. Note that - there is no mutable iterator for QFuture (unlike the other Java-style - iterators). - - The QFutureIterator constructor takes a QFuture as its argument. After - construction, the iterator is located at the very beginning of the result - list (i.e. before the first result). Here's how to iterate over all the - results sequentially: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp 1 - - The next() function returns the next result (waiting for it to become - available, if necessary) from the future and advances the iterator. Unlike - STL-style iterators, Java-style iterators point \e between results rather - than directly \e at results. The first call to next() advances the iterator - to the position between the first and second result, and returns the first - result; the second call to next() advances the iterator to the position - between the second and third result, and returns the second result; and - so on. - - \img javaiterators1.png - - Here's how to iterate over the elements in reverse order: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuture.cpp 2 - - If you want to find all occurrences of a particular value, use findNext() - or findPrevious() in a loop. - - Multiple iterators can be used on the same future. If the future is - modified while a QFutureIterator is active, the QFutureIterator will - continue iterating over the original future, ignoring the modified copy. - - \sa QFuture::const_iterator, QFuture -*/ - -/*! - \fn QFutureIterator::QFutureIterator(const QFuture<T> &future) - - Constructs an iterator for traversing \a future. The iterator is set to be - at the front of the result list (before the first result). - - \sa operator=() -*/ - -/*! \fn QFutureIterator &QFutureIterator::operator=(const QFuture<T> &future) - - Makes the iterator operate on \a future. The iterator is set to be at the - front of the result list (before the first result). - - \sa toFront(), toBack() -*/ - -/*! \fn void QFutureIterator::toFront() - - Moves the iterator to the front of the result list (before the first - result). - - \sa toBack(), next() -*/ - -/*! \fn void QFutureIterator::toBack() - - Moves the iterator to the back of the result list (after the last result). - - \sa toFront(), previous() -*/ - -/*! \fn bool QFutureIterator::hasNext() const - - Returns true if there is at least one result ahead of the iterator, e.g., - the iterator is \e not at the back of the result list; otherwise returns - false. - - \sa hasPrevious(), next() -*/ - -/*! \fn const T &QFutureIterator::next() - - Returns the next result and advances the iterator by one position. - - Calling this function on an iterator located at the back of the result - list leads to undefined results. - - \sa hasNext(), peekNext(), previous() -*/ - -/*! \fn const T &QFutureIterator::peekNext() const - - Returns the next result without moving the iterator. - - Calling this function on an iterator located at the back of the result - list leads to undefined results. - - \sa hasNext(), next(), peekPrevious() -*/ - -/*! \fn bool QFutureIterator::hasPrevious() const - - Returns true if there is at least one result ahead of the iterator, e.g., - the iterator is \e not at the front of the result list; otherwise returns - false. - - \sa hasNext(), previous() -*/ - -/*! \fn const T &QFutureIterator::previous() - - Returns the previous result and moves the iterator back by one position. - - Calling this function on an iterator located at the front of the result - list leads to undefined results. - - \sa hasPrevious(), peekPrevious(), next() -*/ - -/*! \fn const T &QFutureIterator::peekPrevious() const - - Returns the previous result without moving the iterator. - - Calling this function on an iterator located at the front of the result - list leads to undefined results. - - \sa hasPrevious(), previous(), peekNext() -*/ - -/*! \fn bool QFutureIterator::findNext(const T &value) - - Searches for \a value starting from the current iterator position forward. - Returns true if \a value is found; otherwise returns false. - - After the call, if \a value was found, the iterator is positioned just - after the matching result; otherwise, the iterator is positioned at the - back of the result list. - - \sa findPrevious() -*/ - -/*! \fn bool QFutureIterator::findPrevious(const T &value) - - Searches for \a value starting from the current iterator position - backward. Returns true if \a value is found; otherwise returns false. - - After the call, if \a value was found, the iterator is positioned just - before the matching result; otherwise, the iterator is positioned at the - front of the result list. - - \sa findNext() -*/ diff --git a/src/corelib/concurrent/qfuture.h b/src/corelib/concurrent/qfuture.h deleted file mode 100644 index a22168aaba..0000000000 --- a/src/corelib/concurrent/qfuture.h +++ /dev/null @@ -1,277 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFUTURE_H -#define QFUTURE_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_QFUTURE - -#include <QtCore/qfutureinterface.h> -#include <QtCore/qstring.h> -#include <QtCore/qtconcurrentcompilertest.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -template <typename T> -class QFutureWatcher; -template <> -class QFutureWatcher<void>; - -template <typename T> -class QFuture -{ -public: - QFuture() - : d(QFutureInterface<T>::canceledResult()) - { } - explicit QFuture(QFutureInterface<T> *p) // internal - : d(*p) - { } - QFuture(const QFuture &other) - : d(other.d) - { } - ~QFuture() - { } - - inline QFuture &operator=(const QFuture &other); - bool operator==(const QFuture &other) const { return (d == other.d); } - bool operator!=(const QFuture &other) const { return (d != other.d); } - - void cancel() { d.cancel(); } - bool isCanceled() const { return d.isCanceled(); } - - void setPaused(bool paused) { d.setPaused(paused); } - bool isPaused() const { return d.isPaused(); } - void pause() { setPaused(true); } - void resume() { setPaused(false); } - void togglePaused() { d.togglePaused(); } - - bool isStarted() const { return d.isStarted(); } - bool isFinished() const { return d.isFinished(); } - bool isRunning() const { return d.isRunning(); } - - int resultCount() const { return d.resultCount(); } - int progressValue() const { return d.progressValue(); } - int progressMinimum() const { return d.progressMinimum(); } - int progressMaximum() const { return d.progressMaximum(); } - QString progressText() const { return d.progressText(); } - void waitForFinished() { d.waitForFinished(); } - - inline T result() const; - inline T resultAt(int index) const; - bool isResultReadyAt(int resultIndex) const { return d.isResultReadyAt(resultIndex); } - - operator T() const { return result(); } - QList<T> results() const { return d.results(); } - - class const_iterator - { - public: - typedef std::bidirectional_iterator_tag iterator_category; - typedef qptrdiff difference_type; - typedef T value_type; - typedef const T *pointer; - typedef const T &reference; - - inline const_iterator() {} - inline const_iterator(QFuture const * const _future, int _index) : future(_future), index(_index) {} - inline const_iterator(const const_iterator &o) : future(o.future), index(o.index) {} - inline const_iterator &operator=(const const_iterator &o) - { future = o.future; index = o.index; return *this; } - inline const T &operator*() const { return future->d.resultReference(index); } - inline const T *operator->() const { return future->d.resultPointer(index); } - - inline bool operator!=(const const_iterator &other) const - { - if (index == -1 && other.index == -1) // comparing end != end? - return false; - if (other.index == -1) - return (future->isRunning() || (index < future->resultCount())); - return (index != other.index); - } - - inline bool operator==(const const_iterator &o) const { return !operator!=(o); } - inline const_iterator &operator++() { ++index; return *this; } - inline const_iterator operator++(int) { const_iterator r = *this; ++index; return r; } - inline const_iterator &operator--() { --index; return *this; } - inline const_iterator operator--(int) { const_iterator r = *this; --index; return r; } - inline const_iterator operator+(int j) const { return const_iterator(future, index + j); } - inline const_iterator operator-(int j) const { return const_iterator(future, index - j); } - inline const_iterator &operator+=(int j) { index += j; return *this; } - inline const_iterator &operator-=(int j) { index -= j; return *this; } - private: - QFuture const * future; - int index; - }; - friend class const_iterator; - typedef const_iterator ConstIterator; - - const_iterator begin() const { return const_iterator(this, 0); } - const_iterator constBegin() const { return const_iterator(this, 0); } - const_iterator end() const { return const_iterator(this, -1); } - const_iterator constEnd() const { return const_iterator(this, -1); } - -private: - friend class QFutureWatcher<T>; - -public: // Warning: the d pointer is not documented and is considered private. - mutable QFutureInterface<T> d; -}; - -template <typename T> -inline QFuture<T> &QFuture<T>::operator=(const QFuture<T> &other) -{ - d = other.d; - return *this; -} - -template <typename T> -inline T QFuture<T>::result() const -{ - d.waitForResult(0); - return d.resultReference(0); -} - -template <typename T> -inline T QFuture<T>::resultAt(int index) const -{ - d.waitForResult(index); - return d.resultReference(index); -} - -template <typename T> -inline QFuture<T> QFutureInterface<T>::future() -{ - return QFuture<T>(this); -} - -Q_DECLARE_SEQUENTIAL_ITERATOR(Future) - -template <> -class QFuture<void> -{ -public: - QFuture() - : d(QFutureInterface<void>::canceledResult()) - { } - explicit QFuture(QFutureInterfaceBase *p) // internal - : d(*p) - { } - QFuture(const QFuture &other) - : d(other.d) - { } - ~QFuture() - { } - - QFuture &operator=(const QFuture &other); - bool operator==(const QFuture &other) const { return (d == other.d); } - bool operator!=(const QFuture &other) const { return (d != other.d); } - -#if !defined(Q_CC_XLC) - template <typename T> - QFuture(const QFuture<T> &other) - : d(other.d) - { } - - template <typename T> - QFuture<void> &operator=(const QFuture<T> &other) - { - d = other.d; - return *this; - } -#endif - - void cancel() { d.cancel(); } - bool isCanceled() const { return d.isCanceled(); } - - void setPaused(bool paused) { d.setPaused(paused); } - bool isPaused() const { return d.isPaused(); } - void pause() { setPaused(true); } - void resume() { setPaused(false); } - void togglePaused() { d.togglePaused(); } - - bool isStarted() const { return d.isStarted(); } - bool isFinished() const { return d.isFinished(); } - bool isRunning() const { return d.isRunning(); } - - int resultCount() const { return d.resultCount(); } - int progressValue() const { return d.progressValue(); } - int progressMinimum() const { return d.progressMinimum(); } - int progressMaximum() const { return d.progressMaximum(); } - QString progressText() const { return d.progressText(); } - void waitForFinished() { d.waitForFinished(); } - -private: - friend class QFutureWatcher<void>; - -#ifdef QFUTURE_TEST -public: -#endif - mutable QFutureInterfaceBase d; -}; - -inline QFuture<void> &QFuture<void>::operator=(const QFuture<void> &other) -{ - d = other.d; - return *this; -} - -inline QFuture<void> QFutureInterface<void>::future() -{ - return QFuture<void>(this); -} - -template <typename T> -QFuture<void> qToVoidFuture(const QFuture<T> &future) -{ - return QFuture<void>(future.d); -} - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif // QFUTURE_H diff --git a/src/corelib/concurrent/qfutureinterface.cpp b/src/corelib/concurrent/qfutureinterface.cpp deleted file mode 100644 index 9a273a1076..0000000000 --- a/src/corelib/concurrent/qfutureinterface.cpp +++ /dev/null @@ -1,565 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// qfutureinterface.h included from qfuture.h -#include "qfuture.h" - -#ifndef QT_NO_QFUTURE - -#include <QtCore/qatomic.h> -#include <QtCore/qthread.h> -#include <QtCore/qthreadpool.h> -#include <private/qthreadpool_p.h> - -#include "qfutureinterface_p.h" - -QT_BEGIN_NAMESPACE - -enum { - MaxProgressEmitsPerSecond = 25 -}; - -QFutureInterfaceBase::QFutureInterfaceBase(State initialState) - : d(new QFutureInterfaceBasePrivate(initialState)) -{ } - -QFutureInterfaceBase::QFutureInterfaceBase(const QFutureInterfaceBase &other) - : d(other.d) -{ - d->refCount.ref(); -} - -QFutureInterfaceBase::~QFutureInterfaceBase() -{ - if (!d->refCount.deref()) - delete d; -} - -void QFutureInterfaceBase::cancel() -{ - QMutexLocker locker(&d->m_mutex); - if (d->state & Canceled) - return; - - d->state = State((d->state & ~Paused) | Canceled); - d->waitCondition.wakeAll(); - d->pausedWaitCondition.wakeAll(); - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); -} - -void QFutureInterfaceBase::setPaused(bool paused) -{ - QMutexLocker locker(&d->m_mutex); - if (paused) { - d->state = State(d->state | Paused); - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); - } else { - d->state = State(d->state & ~Paused); - d->pausedWaitCondition.wakeAll(); - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed)); - } -} - -void QFutureInterfaceBase::togglePaused() -{ - QMutexLocker locker(&d->m_mutex); - if (d->state & Paused) { - d->state = State(d->state & ~Paused); - d->pausedWaitCondition.wakeAll(); - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Resumed)); - } else { - d->state = State(d->state | Paused); - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); - } -} - -void QFutureInterfaceBase::setThrottled(bool enable) -{ - // bail out if we are not changing the state - if ((enable && (d->state & Throttled)) || (!enable && !(d->state & Throttled))) - return; - - // lock and change the state - QMutexLocker lock(&d->m_mutex); - if (enable) { - d->state = State(d->state | Throttled); - } else { - d->state = State(d->state & ~Throttled); - if (!(d->state & Paused)) - d->pausedWaitCondition.wakeAll(); - } -} - - -bool QFutureInterfaceBase::isRunning() const -{ - return queryState(Running); -} - -bool QFutureInterfaceBase::isStarted() const -{ - return queryState(Started); -} - -bool QFutureInterfaceBase::isCanceled() const -{ - return queryState(Canceled); -} - -bool QFutureInterfaceBase::isFinished() const -{ - return queryState(Finished); -} - -bool QFutureInterfaceBase::isPaused() const -{ - return queryState(Paused); -} - -bool QFutureInterfaceBase::isThrottled() const -{ - return queryState(Throttled); -} - -bool QFutureInterfaceBase::isResultReadyAt(int index) const -{ - QMutexLocker lock(&d->m_mutex); - return d->internal_isResultReadyAt(index); -} - -bool QFutureInterfaceBase::waitForNextResult() -{ - QMutexLocker lock(&d->m_mutex); - return d->internal_waitForNextResult(); -} - -void QFutureInterfaceBase::waitForResume() -{ - // return early if possible to avoid taking the mutex lock. - if ((d->state & Paused) == false || (d->state & Canceled)) - return; - - QMutexLocker lock(&d->m_mutex); - if ((d->state & Paused) == false || (d->state & Canceled)) - return; - - // decrease active thread count since this thread will wait. - QThreadPool::globalInstance()->releaseThread(); - - d->pausedWaitCondition.wait(&d->m_mutex); - - QThreadPool::globalInstance()->reserveThread(); -} - -int QFutureInterfaceBase::progressValue() const -{ - return d->m_progressValue; -} - -int QFutureInterfaceBase::progressMinimum() const -{ - return d->m_progressMinimum; -} - -int QFutureInterfaceBase::progressMaximum() const -{ - return d->m_progressMaximum; -} - -int QFutureInterfaceBase::resultCount() const -{ - QMutexLocker lock(&d->m_mutex); - return d->internal_resultCount(); -} - -QString QFutureInterfaceBase::progressText() const -{ - QMutexLocker locker(&d->m_mutex); - return d->m_progressText; -} - -bool QFutureInterfaceBase::isProgressUpdateNeeded() const -{ - QMutexLocker locker(&d->m_mutex); - return !d->progressTime.isValid() || (d->progressTime.elapsed() > (1000 / MaxProgressEmitsPerSecond)); -} - -void QFutureInterfaceBase::reportStarted() -{ - QMutexLocker locker(&d->m_mutex); - if ((d->state & Started) || (d->state & Canceled) || (d->state & Finished)) - return; - - d->setState(State(Started | Running)); - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Started)); -} - -void QFutureInterfaceBase::reportCanceled() -{ - cancel(); -} - -#ifndef QT_NO_EXCEPTIONS -void QFutureInterfaceBase::reportException(const QtConcurrent::Exception &exception) -{ - QMutexLocker locker(&d->m_mutex); - if ((d->state & Canceled) || (d->state & Finished)) - return; - - d->m_exceptionStore.setException(exception); - d->state = State(d->state | Canceled); - d->waitCondition.wakeAll(); - d->pausedWaitCondition.wakeAll(); - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); -} -#endif - -void QFutureInterfaceBase::reportFinished() -{ - QMutexLocker locker(&d->m_mutex); - if (!(d->state & Finished)) { - d->state = State((d->state & ~Running) | Finished); - d->waitCondition.wakeAll(); - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Finished)); - } -} - -void QFutureInterfaceBase::setExpectedResultCount(int resultCount) -{ - if (d->manualProgress == false) - setProgressRange(0, resultCount); - d->m_expectedResultCount = resultCount; -} - -int QFutureInterfaceBase::expectedResultCount() -{ - return d->m_expectedResultCount; -} - -bool QFutureInterfaceBase::queryState(State state) const -{ - return (d->state & state); -} - -void QFutureInterfaceBase::waitForResult(int resultIndex) -{ - d->m_exceptionStore.throwPossibleException(); - - if (!(d->state & Running)) - return; - - // To avoid deadlocks and reduce the number of threads used, try to - // run the runnable in the current thread. - QThreadPool::globalInstance()->d_func()->stealRunnable(d->runnable); - - QMutexLocker lock(&d->m_mutex); - - if (!(d->state & Running)) - return; - - const int waitIndex = (resultIndex == -1) ? INT_MAX : resultIndex; - while ((d->state & Running) && d->internal_isResultReadyAt(waitIndex) == false) - d->waitCondition.wait(&d->m_mutex); - - d->m_exceptionStore.throwPossibleException(); -} - -void QFutureInterfaceBase::waitForFinished() -{ - if (d->state & Running) { - QThreadPool::globalInstance()->d_func()->stealRunnable(d->runnable); - - QMutexLocker lock(&d->m_mutex); - - while (d->state & Running) - d->waitCondition.wait(&d->m_mutex); - } - - d->m_exceptionStore.throwPossibleException(); -} - -void QFutureInterfaceBase::reportResultsReady(int beginIndex, int endIndex) -{ - if ((d->state & Canceled) || (d->state & Finished) || beginIndex == endIndex) - return; - - d->waitCondition.wakeAll(); - - if (d->manualProgress == false) { - if (d->internal_updateProgress(d->m_progressValue + endIndex - beginIndex) == false) { - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, - beginIndex, - endIndex)); - return; - } - - d->sendCallOuts(QFutureCallOutEvent(QFutureCallOutEvent::Progress, - d->m_progressValue, - d->m_progressText), - QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, - beginIndex, - endIndex)); - return; - } - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, beginIndex, endIndex)); -} - -void QFutureInterfaceBase::setRunnable(QRunnable *runnable) -{ - d->runnable = runnable; -} - -void QFutureInterfaceBase::setFilterMode(bool enable) -{ - QMutexLocker locker(&d->m_mutex); - resultStoreBase().setFilterMode(enable); -} - -void QFutureInterfaceBase::setProgressRange(int minimum, int maximum) -{ - QMutexLocker locker(&d->m_mutex); - d->m_progressMinimum = minimum; - d->m_progressMaximum = maximum; - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::ProgressRange, minimum, maximum)); -} - -void QFutureInterfaceBase::setProgressValue(int progressValue) -{ - setProgressValueAndText(progressValue, QString()); -} - -void QFutureInterfaceBase::setProgressValueAndText(int progressValue, - const QString &progressText) -{ - QMutexLocker locker(&d->m_mutex); - if (d->manualProgress == false) - d->manualProgress = true; - if (d->m_progressValue >= progressValue) - return; - - if ((d->state & Canceled) || (d->state & Finished)) - return; - - if (d->internal_updateProgress(progressValue, progressText)) { - d->sendCallOut(QFutureCallOutEvent(QFutureCallOutEvent::Progress, - d->m_progressValue, - d->m_progressText)); - } -} - -QMutex *QFutureInterfaceBase::mutex() const -{ - return &d->m_mutex; -} - -QtConcurrent::internal::ExceptionStore &QFutureInterfaceBase::exceptionStore() -{ - return d->m_exceptionStore; -} - -QtConcurrent::ResultStoreBase &QFutureInterfaceBase::resultStoreBase() -{ - return d->m_results; -} - -const QtConcurrent::ResultStoreBase &QFutureInterfaceBase::resultStoreBase() const -{ - return d->m_results; -} - -QFutureInterfaceBase &QFutureInterfaceBase::operator=(const QFutureInterfaceBase &other) -{ - other.d->refCount.ref(); - if (!d->refCount.deref()) - delete d; - d = other.d; - return *this; -} - -bool QFutureInterfaceBase::referenceCountIsOne() const -{ - return d->refCount.load() == 1; -} - -QFutureInterfaceBasePrivate::QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState) - : refCount(1), m_progressValue(0), m_progressMinimum(0), m_progressMaximum(0), - state(initialState), pendingResults(0), - manualProgress(false), m_expectedResultCount(0), runnable(0) -{ - progressTime.invalidate(); -} - -int QFutureInterfaceBasePrivate::internal_resultCount() const -{ - return m_results.count(); // ### subtract canceled results. -} - -bool QFutureInterfaceBasePrivate::internal_isResultReadyAt(int index) const -{ - return (m_results.contains(index)); -} - -bool QFutureInterfaceBasePrivate::internal_waitForNextResult() -{ - if (m_results.hasNextResult()) - return true; - - while ((state & QFutureInterfaceBase::Running) && m_results.hasNextResult() == false) - waitCondition.wait(&m_mutex); - - return (!(state & QFutureInterfaceBase::Canceled) && m_results.hasNextResult()); -} - -bool QFutureInterfaceBasePrivate::internal_updateProgress(int progress, - const QString &progressText) -{ - if (m_progressValue >= progress) - return false; - - m_progressValue = progress; - m_progressText = progressText; - - if (progressTime.isValid() && m_progressValue != m_progressMaximum) // make sure the first and last steps are emitted. - if (progressTime.elapsed() < (1000 / MaxProgressEmitsPerSecond)) - return false; - - progressTime.start(); - return true; -} - -void QFutureInterfaceBasePrivate::internal_setThrottled(bool enable) -{ - // bail out if we are not changing the state - if ((enable && (state & QFutureInterfaceBase::Throttled)) - || (!enable && !(state & QFutureInterfaceBase::Throttled))) - return; - - // change the state - if (enable) { - state = QFutureInterfaceBase::State(state | QFutureInterfaceBase::Throttled); - } else { - state = QFutureInterfaceBase::State(state & ~QFutureInterfaceBase::Throttled); - if (!(state & QFutureInterfaceBase::Paused)) - pausedWaitCondition.wakeAll(); - } -} - -void QFutureInterfaceBasePrivate::sendCallOut(const QFutureCallOutEvent &callOutEvent) -{ - if (outputConnections.isEmpty()) - return; - - for (int i = 0; i < outputConnections.count(); ++i) - outputConnections.at(i)->postCallOutEvent(callOutEvent); -} - -void QFutureInterfaceBasePrivate::sendCallOuts(const QFutureCallOutEvent &callOutEvent1, - const QFutureCallOutEvent &callOutEvent2) -{ - if (outputConnections.isEmpty()) - return; - - for (int i = 0; i < outputConnections.count(); ++i) { - QFutureCallOutInterface *interface = outputConnections.at(i); - interface->postCallOutEvent(callOutEvent1); - interface->postCallOutEvent(callOutEvent2); - } -} - -// This function connects an output interface (for example a QFutureWatcher) -// to this future. While holding the lock we check the state and ready results -// and add the appropriate callouts to the queue. In order to avoid deadlocks, -// the actual callouts are made at the end while not holding the lock. -void QFutureInterfaceBasePrivate::connectOutputInterface(QFutureCallOutInterface *interface) -{ - QMutexLocker locker(&m_mutex); - - if (state & QFutureInterfaceBase::Started) { - interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Started)); - interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::ProgressRange, - m_progressMinimum, - m_progressMaximum)); - interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Progress, - m_progressValue, - m_progressText)); - } - - QtConcurrent::ResultIteratorBase it = m_results.begin(); - while (it != m_results.end()) { - const int begin = it.resultIndex(); - const int end = begin + it.batchSize(); - interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::ResultsReady, - begin, - end)); - it.batchedAdvance(); - } - - if (state & QFutureInterfaceBase::Paused) - interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Paused)); - - if (state & QFutureInterfaceBase::Canceled) - interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Canceled)); - - if (state & QFutureInterfaceBase::Finished) - interface->postCallOutEvent(QFutureCallOutEvent(QFutureCallOutEvent::Finished)); - - outputConnections.append(interface); -} - -void QFutureInterfaceBasePrivate::disconnectOutputInterface(QFutureCallOutInterface *interface) -{ - QMutexLocker lock(&m_mutex); - const int index = outputConnections.indexOf(interface); - if (index == -1) - return; - outputConnections.removeAt(index); - - interface->callOutInterfaceDisconnected(); -} - -void QFutureInterfaceBasePrivate::setState(QFutureInterfaceBase::State newState) -{ - state = newState; -} - -QT_END_NAMESPACE - -#endif // QT_NO_CONCURRENT diff --git a/src/corelib/concurrent/qfutureinterface.h b/src/corelib/concurrent/qfutureinterface.h deleted file mode 100644 index 85272bc565..0000000000 --- a/src/corelib/concurrent/qfutureinterface.h +++ /dev/null @@ -1,312 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFUTUREINTERFACE_H -#define QFUTUREINTERFACE_H - -#include <QtCore/qglobal.h> -#include <QtCore/qrunnable.h> - -#ifndef QT_NO_QFUTURE - -#include <QtCore/qmutex.h> -#include <QtCore/qtconcurrentexception.h> -#include <QtCore/qtconcurrentresultstore.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -template <typename T> class QFuture; -class QFutureInterfaceBasePrivate; -class QFutureWatcherBase; -class QFutureWatcherBasePrivate; - -class Q_CORE_EXPORT QFutureInterfaceBase -{ -public: - enum State { - NoState = 0x00, - Running = 0x01, - Started = 0x02, - Finished = 0x04, - Canceled = 0x08, - Paused = 0x10, - Throttled = 0x20 - }; - - QFutureInterfaceBase(State initialState = NoState); - QFutureInterfaceBase(const QFutureInterfaceBase &other); - virtual ~QFutureInterfaceBase(); - - // reporting functions available to the engine author: - void reportStarted(); - void reportFinished(); - void reportCanceled(); -#ifndef QT_NO_EXCEPTIONS - void reportException(const QtConcurrent::Exception &e); -#endif - void reportResultsReady(int beginIndex, int endIndex); - - void setRunnable(QRunnable *runnable); - void setFilterMode(bool enable); - void setProgressRange(int minimum, int maximum); - int progressMinimum() const; - int progressMaximum() const; - bool isProgressUpdateNeeded() const; - void setProgressValue(int progressValue); - int progressValue() const; - void setProgressValueAndText(int progressValue, const QString &progressText); - QString progressText() const; - - void setExpectedResultCount(int resultCount); - int expectedResultCount(); - int resultCount() const; - - bool queryState(State state) const; - bool isRunning() const; - bool isStarted() const; - bool isCanceled() const; - bool isFinished() const; - bool isPaused() const; - bool isThrottled() const; - bool isResultReadyAt(int index) const; - - void cancel(); - void setPaused(bool paused); - void togglePaused(); - void setThrottled(bool enable); - - void waitForFinished(); - bool waitForNextResult(); - void waitForResult(int resultIndex); - void waitForResume(); - - QMutex *mutex() const; - QtConcurrent::internal::ExceptionStore &exceptionStore(); - QtConcurrent::ResultStoreBase &resultStoreBase(); - const QtConcurrent::ResultStoreBase &resultStoreBase() const; - - inline bool operator==(const QFutureInterfaceBase &other) const { return d == other.d; } - inline bool operator!=(const QFutureInterfaceBase &other) const { return d != other.d; } - QFutureInterfaceBase &operator=(const QFutureInterfaceBase &other); - -protected: - bool referenceCountIsOne() const; -public: - -#ifndef QFUTURE_TEST -private: -#endif - QFutureInterfaceBasePrivate *d; - -private: - friend class QFutureWatcherBase; - friend class QFutureWatcherBasePrivate; -}; - -template <typename T> -class QFutureInterface : public QFutureInterfaceBase -{ -public: - QFutureInterface(State initialState = NoState) - : QFutureInterfaceBase(initialState) - { } - QFutureInterface(const QFutureInterface &other) - : QFutureInterfaceBase(other) - { } - ~QFutureInterface() - { - if (referenceCountIsOne()) - resultStore().clear(); - } - - static QFutureInterface canceledResult() - { return QFutureInterface(State(Started | Finished | Canceled)); } - - QFutureInterface &operator=(const QFutureInterface &other) - { - if (referenceCountIsOne()) - resultStore().clear(); - QFutureInterfaceBase::operator=(other); - return *this; - } - - inline QFuture<T> future(); // implemented in qfuture.h - - inline void reportResult(const T *result, int index = -1); - inline void reportResult(const T &result, int index = -1); - inline void reportResults(const QVector<T> &results, int beginIndex = -1, int count = -1); - inline void reportFinished(const T *result = 0); - - inline const T &resultReference(int index) const; - inline const T *resultPointer(int index) const; - inline QList<T> results(); -private: - QtConcurrent::ResultStore<T> &resultStore() - { return static_cast<QtConcurrent::ResultStore<T> &>(resultStoreBase()); } - const QtConcurrent::ResultStore<T> &resultStore() const - { return static_cast<const QtConcurrent::ResultStore<T> &>(resultStoreBase()); } -}; - -template <typename T> -inline void QFutureInterface<T>::reportResult(const T *result, int index) -{ - QMutexLocker locker(mutex()); - if (this->queryState(Canceled) || this->queryState(Finished)) { - return; - } - - QtConcurrent::ResultStore<T> &store = resultStore(); - - - if (store.filterMode()) { - const int resultCountBefore = store.count(); - store.addResult(index, result); - this->reportResultsReady(resultCountBefore, resultCountBefore + store.count()); - } else { - const int insertIndex = store.addResult(index, result); - this->reportResultsReady(insertIndex, insertIndex + 1); - } -} - -template <typename T> -inline void QFutureInterface<T>::reportResult(const T &result, int index) -{ - reportResult(&result, index); -} - -template <typename T> -inline void QFutureInterface<T>::reportResults(const QVector<T> &_results, int beginIndex, int count) -{ - QMutexLocker locker(mutex()); - if (this->queryState(Canceled) || this->queryState(Finished)) { - return; - } - - QtConcurrent::ResultStore<T> &store = resultStore(); - - if (store.filterMode()) { - const int resultCountBefore = store.count(); - store.addResults(beginIndex, &_results, count); - this->reportResultsReady(resultCountBefore, store.count()); - } else { - const int insertIndex = store.addResults(beginIndex, &_results, count); - this->reportResultsReady(insertIndex, insertIndex + _results.count()); - } -} - -template <typename T> -inline void QFutureInterface<T>::reportFinished(const T *result) -{ - if (result) - reportResult(result); - QFutureInterfaceBase::reportFinished(); -} - -template <typename T> -inline const T &QFutureInterface<T>::resultReference(int index) const -{ - QMutexLocker lock(mutex()); - return resultStore().resultAt(index).value(); -} - -template <typename T> -inline const T *QFutureInterface<T>::resultPointer(int index) const -{ - QMutexLocker lock(mutex()); - return resultStore().resultAt(index).pointer(); -} - -template <typename T> -inline QList<T> QFutureInterface<T>::results() -{ - if (this->isCanceled()) { - exceptionStore().throwPossibleException(); - return QList<T>(); - } - QFutureInterfaceBase::waitForResult(-1); - - QList<T> res; - QMutexLocker lock(mutex()); - - QtConcurrent::ResultIterator<T> it = resultStore().begin(); - while (it != resultStore().end()) { - res.append(it.value()); - ++it; - } - - return res; -} - -template <> -class QFutureInterface<void> : public QFutureInterfaceBase -{ -public: - QFutureInterface<void>(State initialState = NoState) - : QFutureInterfaceBase(initialState) - { } - QFutureInterface<void>(const QFutureInterface<void> &other) - : QFutureInterfaceBase(other) - { } - - static QFutureInterface<void> canceledResult() - { return QFutureInterface(State(Started | Finished | Canceled)); } - - QFutureInterface<void> &operator=(const QFutureInterface<void> &other) - { - QFutureInterfaceBase::operator=(other); - return *this; - } - - inline QFuture<void> future(); // implemented in qfuture.h - - void reportResult(const void *, int) { } - void reportResults(const QVector<void> &, int) { } - void reportFinished(void * = 0) { QFutureInterfaceBase::reportFinished(); } -}; - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif // QFUTUREINTERFACE_H diff --git a/src/corelib/concurrent/qfutureinterface_p.h b/src/corelib/concurrent/qfutureinterface_p.h deleted file mode 100644 index ea52621378..0000000000 --- a/src/corelib/concurrent/qfutureinterface_p.h +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFUTUREINTERFACE_P_H -#define QFUTUREINTERFACE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qelapsedtimer.h> -#include <QtCore/qcoreevent.h> -#include <QtCore/qlist.h> -#include <QtCore/qwaitcondition.h> -#include <QtCore/qrunnable.h> - -QT_BEGIN_NAMESPACE - -class QFutureCallOutEvent : public QEvent -{ -public: - enum CallOutType { - Started, - Finished, - Canceled, - Paused, - Resumed, - Progress, - ProgressRange, - ResultsReady - }; - - QFutureCallOutEvent() - : QEvent(QEvent::FutureCallOut), callOutType(CallOutType(0)), index1(-1), index2(-1) - { } - QFutureCallOutEvent(CallOutType callOutType, int index1 = -1) - : QEvent(QEvent::FutureCallOut), callOutType(callOutType), index1(index1), index2(-1) - { } - QFutureCallOutEvent(CallOutType callOutType, int index1, int index2) - : QEvent(QEvent::FutureCallOut), callOutType(callOutType), index1(index1), index2(index2) - { } - - QFutureCallOutEvent(CallOutType callOutType, int index1, const QString &text) - : QEvent(QEvent::FutureCallOut), - callOutType(callOutType), - index1(index1), - index2(-1), - text(text) - { } - - CallOutType callOutType; - int index1; - int index2; - QString text; - - QFutureCallOutEvent *clone() const - { - return new QFutureCallOutEvent(callOutType, index1, index2, text); - } - -private: - QFutureCallOutEvent(CallOutType callOutType, - int index1, - int index2, - const QString &text) - : QEvent(QEvent::FutureCallOut), - callOutType(callOutType), - index1(index1), - index2(index2), - text(text) - { } -}; - -class QFutureCallOutInterface -{ -public: - virtual ~QFutureCallOutInterface() {} - virtual void postCallOutEvent(const QFutureCallOutEvent &) = 0; - virtual void callOutInterfaceDisconnected() = 0; -}; - -class QFutureInterfaceBasePrivate -{ -public: - QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState); - - QAtomicInt refCount; - mutable QMutex m_mutex; - QWaitCondition waitCondition; - QList<QFutureCallOutInterface *> outputConnections; - int m_progressValue; - int m_progressMinimum; - int m_progressMaximum; - QFutureInterfaceBase::State state; - QElapsedTimer progressTime; - QWaitCondition pausedWaitCondition; - int pendingResults; - QtConcurrent::ResultStoreBase m_results; - bool manualProgress; - int m_expectedResultCount; - QtConcurrent::internal::ExceptionStore m_exceptionStore; - QString m_progressText; - QRunnable *runnable; - - // Internal functions that does not change the mutex state. - // The mutex must be locked when calling these. - int internal_resultCount() const; - bool internal_isResultReadyAt(int index) const; - bool internal_waitForNextResult(); - bool internal_updateProgress(int progress, const QString &progressText = QString()); - void internal_setThrottled(bool enable); - void sendCallOut(const QFutureCallOutEvent &callOut); - void sendCallOuts(const QFutureCallOutEvent &callOut1, const QFutureCallOutEvent &callOut2); - void connectOutputInterface(QFutureCallOutInterface *iface); - void disconnectOutputInterface(QFutureCallOutInterface *iface); - - void setState(QFutureInterfaceBase::State state); -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/corelib/concurrent/qfuturesynchronizer.cpp b/src/corelib/concurrent/qfuturesynchronizer.cpp deleted file mode 100644 index 34b00daf4f..0000000000 --- a/src/corelib/concurrent/qfuturesynchronizer.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! \class QFutureSynchronizer - \since 4.4 - - \brief The QFutureSynchronizer class is a convenience class that simplifies - QFuture synchronization. - - \ingroup thread - - QFutureSynchronizer is a template class that simplifies synchronization of - one or more QFuture objects. Futures are added using the addFuture() or - setFuture() functions. The futures() function returns a list of futures. - Use clearFutures() to remove all futures from the QFutureSynchronizer. - - The waitForFinished() function waits for all futures to finish. - The destructor of QFutureSynchronizer calls waitForFinished(), providing - an easy way to ensure that all futures have finished before returning from - a function: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuturesynchronizer.cpp 0 - - The behavior of waitForFinished() can be changed using the - setCancelOnWait() function. Calling setCancelOnWait(true) will cause - waitForFinished() to cancel all futures before waiting for them to finish. - You can query the status of the cancel-on-wait feature using the - cancelOnWait() function. - - \sa QFuture, QFutureWatcher, {Concurrent Programming}{Qt Concurrent} -*/ - -/*! - \fn QFutureSynchronizer::QFutureSynchronizer() - - Constructs a QFutureSynchronizer. -*/ - -/*! - \fn QFutureSynchronizer::QFutureSynchronizer(const QFuture<T> &future) - - Constructs a QFutureSynchronizer and begins watching \a future by calling - addFuture(). - - \sa addFuture() -*/ - -/*! - \fn QFutureSynchronizer::~QFutureSynchronizer() - - Calls waitForFinished() function to ensure that all futures have finished - before destroying this QFutureSynchronizer. - - \sa waitForFinished() -*/ - -/*! - \fn void QFutureSynchronizer::setFuture(const QFuture<T> &future) - - Sets \a future to be the only future managed by this QFutureSynchronizer. - This is a convenience function that calls waitForFinished(), - then clearFutures(), and finally passes \a future to addFuture(). - - \sa addFuture(), waitForFinished(), clearFutures() -*/ - -/*! - \fn void QFutureSynchronizer::addFuture(const QFuture<T> &future) - - Adds \a future to the list of managed futures. - - \sa futures() -*/ - -/*! - \fn void QFutureSynchronizer::waitForFinished() - - Waits for all futures to finish. If cancelOnWait() returns true, each - future is canceled before waiting for them to finish. - - \sa cancelOnWait(), setCancelOnWait() -*/ - -/*! - \fn void QFutureSynchronizer::clearFutures() - - Removes all managed futures from this QFutureSynchronizer. - - \sa addFuture(), setFuture() -*/ - -/*! - \fn QList<QFuture<T> > QFutureSynchronizer::futures() const - - Returns a list of all managed futures. - - \sa addFuture(), setFuture() -*/ - -/*! - \fn void QFutureSynchronizer::setCancelOnWait(bool enabled) - - Enables or disables the cancel-on-wait feature based on the \a enabled - argument. If \a enabled is true, the waitForFinished() function will cancel - all futures before waiting for them to finish. - - \sa waitForFinished() -*/ - -/*! - \fn bool QFutureSynchronizer::cancelOnWait() const - - Returns true if the cancel-on-wait feature is enabled; otherwise returns - false. If cancel-on-wait is enabled, the waitForFinished() function will - cancel all futures before waiting for them to finish. - - \sa waitForFinished() -*/ diff --git a/src/corelib/concurrent/qfuturesynchronizer.h b/src/corelib/concurrent/qfuturesynchronizer.h deleted file mode 100644 index 1661cae13c..0000000000 --- a/src/corelib/concurrent/qfuturesynchronizer.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFUTRUESYNCHRONIZER_H -#define QFUTRUESYNCHRONIZER_H - -#include <QtCore/qfuture.h> - -#ifndef QT_NO_CONCURRENT - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -template <typename T> -class QFutureSynchronizer -{ - Q_DISABLE_COPY(QFutureSynchronizer) - -public: - QFutureSynchronizer() : m_cancelOnWait(false) { } - explicit QFutureSynchronizer(const QFuture<T> &future) - : m_cancelOnWait(false) - { addFuture(future); } - ~QFutureSynchronizer() { waitForFinished(); } - - void setFuture(const QFuture<T> &future) - { - waitForFinished(); - m_futures.clear(); - addFuture(future); - } - - void addFuture(const QFuture<T> &future) - { - m_futures.append(future); - } - - void waitForFinished() - { - if (m_cancelOnWait) { - for (int i = 0; i < m_futures.count(); ++i) { - m_futures[i].cancel(); - } - } - - for (int i = 0; i < m_futures.count(); ++i) { - m_futures[i].waitForFinished(); - } - } - - void clearFutures() - { - m_futures.clear(); - } - - QList<QFuture<T> > futures() const - { - return m_futures; - } - - void setCancelOnWait(bool enabled) - { - m_cancelOnWait = enabled; - } - - bool cancelOnWait() const - { - return m_cancelOnWait; - } - -protected: - QList<QFuture<T> > m_futures; - bool m_cancelOnWait; -}; - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif // QFUTRUESYNCHRONIZER_H diff --git a/src/corelib/concurrent/qfuturewatcher.cpp b/src/corelib/concurrent/qfuturewatcher.cpp deleted file mode 100644 index d3a1122a07..0000000000 --- a/src/corelib/concurrent/qfuturewatcher.cpp +++ /dev/null @@ -1,592 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qfuturewatcher.h" - -#ifndef QT_NO_QFUTURE - -#include <QtCore/qcoreevent.h> -#include <QtCore/qcoreapplication.h> -#include <QtCore/qthread.h> - -#include "qfuturewatcher_p.h" - -QT_BEGIN_NAMESPACE - -/*! \class QFutureWatcher - \reentrant - \since 4.4 - - \ingroup thread - - \brief The QFutureWatcher class allows monitoring a QFuture using signals - and slots. - - QFutureWatcher provides information and notifications about a QFuture. Use - the setFuture() function to start watching a particular QFuture. The - future() function returns the future set with setFuture(). - - For convenience, several of QFuture's functions are also available in - QFutureWatcher: progressValue(), progressMinimum(), progressMaximum(), - progressText(), isStarted(), isFinished(), isRunning(), isCanceled(), - isPaused(), waitForFinished(), result(), and resultAt(). The cancel(), - setPaused(), pause(), resume(), and togglePaused() functions are slots in - QFutureWatcher. - - Status changes are reported via the started(), finished(), canceled(), - paused(), resumed(), resultReadyAt(), and resultsReadyAt() signals. - Progress information is provided from the progressRangeChanged(), - void progressValueChanged(), and progressTextChanged() signals. - - Throttling control is provided by the setPendingResultsLimit() function. - When the number of pending resultReadyAt() or resultsReadyAt() signals - exceeds the limit, the computation represented by the future will be - throttled automatically. The computation will resume once the number of - pending signals drops below the limit. - - Example: Starting a computation and getting a slot callback when it's - finished: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qfuturewatcher.cpp 0 - - Be aware that not all asynchronous computations can be canceled or paused. - For example, the future returned by QtConcurrent::run() cannot be - canceled; but the future returned by QtConcurrent::mappedReduced() can. - - QFutureWatcher<void> is specialized to not contain any of the result - fetching functions. Any QFuture<T> can be watched by a - QFutureWatcher<void> as well. This is useful if only status or progress - information is needed; not the actual result data. - - \sa QFuture, {Concurrent Programming}{Qt Concurrent} -*/ - -/*! \fn QFutureWatcher::QFutureWatcher(QObject *parent) - - Constructs a new QFutureWatcher with the given \a parent. -*/ -QFutureWatcherBase::QFutureWatcherBase(QObject *parent) - :QObject(*new QFutureWatcherBasePrivate, parent) -{ } - -/*! \fn QFutureWatcher::~QFutureWatcher() - - Destroys the QFutureWatcher. -*/ - -/*! \fn void QFutureWatcher::cancel() - - Cancels the asynchronous computation represented by the future(). Note that - the cancelation is asynchronous. Use waitForFinished() after calling - cancel() when you need synchronous cancelation. - - Currently available results may still be accessed on a canceled QFuture, - but new results will \e not become available after calling this function. - Also, this QFutureWatcher will not deliver progress and result ready - signals once canceled. This includes the progressValueChanged(), - progressRangeChanged(), progressTextChanged(), resultReadyAt(), and - resultsReadyAt() signals. - - Be aware that not all asynchronous computations can be canceled. For - example, the QFuture returned by QtConcurrent::run() cannot be canceled; - but the QFuture returned by QtConcurrent::mappedReduced() can. -*/ -void QFutureWatcherBase::cancel() -{ - futureInterface().cancel(); -} - -/*! \fn void QFutureWatcher::setPaused(bool paused) - - If \a paused is true, this function pauses the asynchronous computation - represented by the future(). If the computation is already paused, this - function does nothing. This QFutureWatcher will stop delivering progress - and result ready signals while the future is paused. Signal delivery will - continue once the computation is resumed. - - If \a paused is false, this function resumes the asynchronous computation. - If the computation was not previously paused, this function does nothing. - - Be aware that not all computations can be paused. For example, the - QFuture returned by QtConcurrent::run() cannot be paused; but the QFuture - returned by QtConcurrent::mappedReduced() can. - - \sa pause(), resume(), togglePaused() -*/ -void QFutureWatcherBase::setPaused(bool paused) -{ - futureInterface().setPaused(paused); -} - -/*! \fn void QFutureWatcher::pause() - - Pauses the asynchronous computation represented by the future(). This is a - convenience method that simply calls setPaused(true). - - \sa resume() -*/ -void QFutureWatcherBase::pause() -{ - futureInterface().setPaused(true); -} - -/*! \fn void QFutureWatcher::resume() - - Resumes the asynchronous computation represented by the future(). This is - a convenience method that simply calls setPaused(false). - - \sa pause() -*/ -void QFutureWatcherBase::resume() -{ - futureInterface().setPaused(false); -} - -/*! \fn void QFutureWatcher::togglePaused() - - Toggles the paused state of the asynchronous computation. In other words, - if the computation is currently paused, calling this function resumes it; - if the computation is running, it becomes paused. This is a convenience - method for calling setPaused(!isPaused()). - - \sa setPaused(), pause(), resume() -*/ -void QFutureWatcherBase::togglePaused() -{ - futureInterface().togglePaused(); -} - -/*! \fn int QFutureWatcher::progressValue() const - - Returns the current progress value, which is between the progressMinimum() - and progressMaximum(). - - \sa progressMinimum(), progressMaximum() -*/ -int QFutureWatcherBase::progressValue() const -{ - return futureInterface().progressValue(); -} - -/*! \fn int QFutureWatcher::progressMinimum() const - - Returns the minimum progressValue(). - - \sa progressValue(), progressMaximum() -*/ -int QFutureWatcherBase::progressMinimum() const -{ - return futureInterface().progressMinimum(); -} - -/*! \fn int QFutureWatcher::progressMaximum() const - - Returns the maximum progressValue(). - - \sa progressValue(), progressMinimum() -*/ -int QFutureWatcherBase::progressMaximum() const -{ - return futureInterface().progressMaximum(); -} - -/*! \fn QString QFutureWatcher::progressText() const - - Returns the (optional) textual representation of the progress as reported - by the asynchronous computation. - - Be aware that not all computations provide a textual representation of the - progress, and as such, this function may return an empty string. -*/ -QString QFutureWatcherBase::progressText() const -{ - return futureInterface().progressText(); -} - -/*! \fn bool QFutureWatcher::isStarted() const - - Returns true if the asynchronous computation represented by the future() - has been started; otherwise returns false. -*/ -bool QFutureWatcherBase::isStarted() const -{ - return futureInterface().queryState(QFutureInterfaceBase::Started); -} - -/*! \fn bool QFutureWatcher::isFinished() const - - Returns true if the asynchronous computation represented by the future() - has finished; otherwise returns false. -*/ -bool QFutureWatcherBase::isFinished() const -{ - Q_D(const QFutureWatcherBase); - return d->finished; -} - -/*! \fn bool QFutureWatcher::isRunning() const - - Returns true if the asynchronous computation represented by the future() - is currently running; otherwise returns false. -*/ -bool QFutureWatcherBase::isRunning() const -{ - return futureInterface().queryState(QFutureInterfaceBase::Running); -} - -/*! \fn bool QFutureWatcher::isCanceled() const - - Returns true if the asynchronous computation has been canceled with the - cancel() function; otherwise returns false. - - Be aware that the computation may still be running even though this - function returns true. See cancel() for more details. -*/ -bool QFutureWatcherBase::isCanceled() const -{ - return futureInterface().queryState(QFutureInterfaceBase::Canceled); -} - -/*! \fn bool QFutureWatcher::isPaused() const - - Returns true if the asynchronous computation has been paused with the - pause() function; otherwise returns false. - - Be aware that the computation may still be running even though this - function returns true. See setPaused() for more details. - - \sa setPaused(), togglePaused() -*/ -bool QFutureWatcherBase::isPaused() const -{ - return futureInterface().queryState(QFutureInterfaceBase::Paused); -} - -/*! \fn void QFutureWatcher::waitForFinished() - - Waits for the asynchronous computation to finish (including cancel()ed - computations). -*/ -void QFutureWatcherBase::waitForFinished() -{ - futureInterface().waitForFinished(); -} - -/*! \fn void QFutureWatcher::setPendingResultsLimit(int limit) - - The setPendingResultsLimit() provides throttling control. When the number - of pending resultReadyAt() or resultsReadyAt() signals exceeds the - \a limit, the computation represented by the future will be throttled - automatically. The computation will resume once the number of pending - signals drops below the \a limit. -*/ - -bool QFutureWatcherBase::event(QEvent *event) -{ - Q_D(QFutureWatcherBase); - if (event->type() == QEvent::FutureCallOut) { - QFutureCallOutEvent *callOutEvent = static_cast<QFutureCallOutEvent *>(event); - - if (futureInterface().isPaused()) { - d->pendingCallOutEvents.append(callOutEvent->clone()); - return true; - } - - if (callOutEvent->callOutType == QFutureCallOutEvent::Resumed - && !d->pendingCallOutEvents.isEmpty()) { - // send the resume - d->sendCallOutEvent(callOutEvent); - - // next send all pending call outs - for (int i = 0; i < d->pendingCallOutEvents.count(); ++i) - d->sendCallOutEvent(d->pendingCallOutEvents.at(i)); - qDeleteAll(d->pendingCallOutEvents); - d->pendingCallOutEvents.clear(); - } else { - d->sendCallOutEvent(callOutEvent); - } - return true; - } - return QObject::event(event); -} - -void QFutureWatcherBase::setPendingResultsLimit(int limit) -{ - Q_D(QFutureWatcherBase); - d->maximumPendingResultsReady = limit; -} - -void QFutureWatcherBase::connectNotify(const char * signal) -{ - Q_D(QFutureWatcherBase); - if (qstrcmp(signal, SIGNAL(resultReadyAt(int))) == 0) - d->resultAtConnected.ref(); -#ifndef QT_NO_DEBUG - if (qstrcmp(signal, SIGNAL(finished())) == 0) { - if (futureInterface().isRunning()) { - //connections should be established before calling stFuture to avoid race. - // (The future could finish before the connection is made.) - qWarning("QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race"); - } - } -#endif -} - -void QFutureWatcherBase::disconnectNotify(const char * signal) -{ - Q_D(QFutureWatcherBase); - if (qstrcmp(signal, SIGNAL(resultReadyAt(int))) == 0) - d->resultAtConnected.deref(); -} - -/*! - \internal -*/ -QFutureWatcherBasePrivate::QFutureWatcherBasePrivate() - : maximumPendingResultsReady(QThread::idealThreadCount() * 2), - resultAtConnected(0) -{ } - -/*! - \internal -*/ -void QFutureWatcherBase::connectOutputInterface() -{ - futureInterface().d->connectOutputInterface(d_func()); -} - -/*! - \internal -*/ -void QFutureWatcherBase::disconnectOutputInterface(bool pendingAssignment) -{ - if (pendingAssignment) { - Q_D(QFutureWatcherBase); - d->pendingResultsReady.store(0); - qDeleteAll(d->pendingCallOutEvents); - d->pendingCallOutEvents.clear(); - d->finished = false; - } - - futureInterface().d->disconnectOutputInterface(d_func()); -} - -void QFutureWatcherBasePrivate::postCallOutEvent(const QFutureCallOutEvent &callOutEvent) -{ - Q_Q(QFutureWatcherBase); - - if (callOutEvent.callOutType == QFutureCallOutEvent::ResultsReady) { - if (pendingResultsReady.fetchAndAddRelaxed(1) >= maximumPendingResultsReady) - q->futureInterface().d->internal_setThrottled(true); - } - - QCoreApplication::postEvent(q, callOutEvent.clone()); -} - -void QFutureWatcherBasePrivate::callOutInterfaceDisconnected() -{ - QCoreApplication::removePostedEvents(q_func(), QEvent::FutureCallOut); -} - -void QFutureWatcherBasePrivate::sendCallOutEvent(QFutureCallOutEvent *event) -{ - Q_Q(QFutureWatcherBase); - - switch (event->callOutType) { - case QFutureCallOutEvent::Started: - emit q->started(); - break; - case QFutureCallOutEvent::Finished: - finished = true; - emit q->finished(); - break; - case QFutureCallOutEvent::Canceled: - pendingResultsReady.store(0); - emit q->canceled(); - break; - case QFutureCallOutEvent::Paused: - if (q->futureInterface().isCanceled()) - break; - emit q->paused(); - break; - case QFutureCallOutEvent::Resumed: - if (q->futureInterface().isCanceled()) - break; - emit q->resumed(); - break; - case QFutureCallOutEvent::ResultsReady: { - if (q->futureInterface().isCanceled()) - break; - - if (pendingResultsReady.fetchAndAddRelaxed(-1) <= maximumPendingResultsReady) - q->futureInterface().setThrottled(false); - - const int beginIndex = event->index1; - const int endIndex = event->index2; - - emit q->resultsReadyAt(beginIndex, endIndex); - - if (resultAtConnected.load() <= 0) - break; - - for (int i = beginIndex; i < endIndex; ++i) - emit q->resultReadyAt(i); - - } break; - case QFutureCallOutEvent::Progress: - if (q->futureInterface().isCanceled()) - break; - - emit q->progressValueChanged(event->index1); - if (!event->text.isNull()) // ### - q->progressTextChanged(event->text); - break; - case QFutureCallOutEvent::ProgressRange: - emit q->progressRangeChanged(event->index1, event->index2); - break; - default: break; - } -} - - -/*! \fn const T &QFutureWatcher::result() const - - Returns the first result in the future(). If the result is not immediately - available, this function will block and wait for the result to become - available. This is a convenience method for calling resultAt(0). - - \sa resultAt() -*/ - -/*! \fn const T &QFutureWatcher::resultAt(int index) const - - Returns the result at \a index in the future(). If the result is not - immediately available, this function will block and wait for the result to - become available. - - \sa result() -*/ - -/*! \fn void QFutureWatcher::setFuture(const QFuture<T> &future) - - Starts watching the given \a future. - - One of the signals might be emitted for the current state of the - \a future. For example, if the future is already stopped, the - finished signal will be emitted. - - To avoid a race condition, it is important to call this function - \e after doing the connections. -*/ - -/*! \fn QFuture<T> QFutureWatcher::future() const - - Returns the watched future. -*/ - -/*! \fn void QFutureWatcher::started() - - This signal is emitted when this QFutureWatcher starts watching the future - set with setFuture(). -*/ - -/*! - \fn void QFutureWatcher::finished() - This signal is emitted when the watched future finishes. -*/ - -/*! - \fn void QFutureWatcher::canceled() - This signal is emitted if the watched future is canceled. -*/ - -/*! \fn void QFutureWatcher::paused() - This signal is emitted when the watched future is paused. -*/ - -/*! \fn void QFutureWatcher::resumed() - This signal is emitted when the watched future is resumed. -*/ - -/*! - \fn void QFutureWatcher::progressRangeChanged(int minimum, int maximum) - - The progress range for the watched future has changed to \a minimum and - \a maximum -*/ - -/*! - \fn void QFutureWatcher::progressValueChanged(int progressValue) - - This signal is emitted when the watched future reports progress, - \a progressValue gives the current progress. In order to avoid overloading - the GUI event loop, QFutureWatcher limits the progress signal emission - rate. This means that listeners connected to this slot might not get all - progress reports the future makes. The last progress update (where - \a progressValue equals the maximum value) will always be delivered. -*/ - -/*! \fn void QFutureWatcher::progressTextChanged(const QString &progressText) - - This signal is emitted when the watched future reports textual progress - information, \a progressText. -*/ - -/*! - \fn void QFutureWatcher::resultReadyAt(int index) - - This signal is emitted when the watched future reports a ready result at - \a index. If the future reports multiple results, the index will indicate - which one it is. Results can be reported out-of-order. To get the result, - call future().result(index); -*/ - -/*! - \fn void QFutureWatcher::resultsReadyAt(int beginIndex, int endIndex); - - This signal is emitted when the watched future reports ready results. - The results are indexed from \a beginIndex to \a endIndex. - -*/ - -QT_END_NAMESPACE - -#endif // QT_NO_CONCURRENT diff --git a/src/corelib/concurrent/qfuturewatcher.h b/src/corelib/concurrent/qfuturewatcher.h deleted file mode 100644 index 6029331ed1..0000000000 --- a/src/corelib/concurrent/qfuturewatcher.h +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFUTUREWATCHER_H -#define QFUTUREWATCHER_H - -#include <QtCore/qfuture.h> - -#ifndef QT_NO_QFUTURE - -#include <QtCore/qobject.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -class QEvent; - -class QFutureWatcherBasePrivate; -class Q_CORE_EXPORT QFutureWatcherBase : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QFutureWatcherBase) - -public: - QFutureWatcherBase(QObject *parent = 0); - - int progressValue() const; - int progressMinimum() const; - int progressMaximum() const; - QString progressText() const; - - bool isStarted() const; - bool isFinished() const; - bool isRunning() const; - bool isCanceled() const; - bool isPaused() const; - - void waitForFinished(); - - void setPendingResultsLimit(int limit); - - bool event(QEvent *event); - -Q_SIGNALS: - void started(); - void finished(); - void canceled(); - void paused(); - void resumed(); - void resultReadyAt(int resultIndex); - void resultsReadyAt(int beginIndex, int endIndex); - void progressRangeChanged(int minimum, int maximum); - void progressValueChanged(int progressValue); - void progressTextChanged(const QString &progressText); - -public Q_SLOTS: - void cancel(); - void setPaused(bool paused); - void pause(); - void resume(); - void togglePaused(); - -protected: - void connectNotify (const char * signal); - void disconnectNotify (const char * signal); - - // called from setFuture() implemented in template sub-classes - void connectOutputInterface(); - void disconnectOutputInterface(bool pendingAssignment = false); - -private: - // implemented in the template sub-classes - virtual const QFutureInterfaceBase &futureInterface() const = 0; - virtual QFutureInterfaceBase &futureInterface() = 0; -}; - -template <typename T> -class QFutureWatcher : public QFutureWatcherBase -{ -public: - QFutureWatcher(QObject *_parent = 0) - : QFutureWatcherBase(_parent) - { } - ~QFutureWatcher() - { disconnectOutputInterface(); } - - void setFuture(const QFuture<T> &future); - QFuture<T> future() const - { return m_future; } - - T result() const { return m_future.result(); } - T resultAt(int index) const { return m_future.resultAt(index); } - -#ifdef qdoc - int progressValue() const; - int progressMinimum() const; - int progressMaximum() const; - QString progressText() const; - - bool isStarted() const; - bool isFinished() const; - bool isRunning() const; - bool isCanceled() const; - bool isPaused() const; - - void waitForFinished(); - - void setPendingResultsLimit(int limit); - -Q_SIGNALS: - void started(); - void finished(); - void canceled(); - void paused(); - void resumed(); - void resultReadyAt(int resultIndex); - void resultsReadyAt(int beginIndex, int endIndex); - void progressRangeChanged(int minimum, int maximum); - void progressValueChanged(int progressValue); - void progressTextChanged(const QString &progressText); - -public Q_SLOTS: - void cancel(); - void setPaused(bool paused); - void pause(); - void resume(); - void togglePaused(); -#endif - -private: - QFuture<T> m_future; - const QFutureInterfaceBase &futureInterface() const { return m_future.d; } - QFutureInterfaceBase &futureInterface() { return m_future.d; } -}; - -template <typename T> -Q_INLINE_TEMPLATE void QFutureWatcher<T>::setFuture(const QFuture<T> &_future) -{ - if (_future == m_future) - return; - - disconnectOutputInterface(true); - m_future = _future; - connectOutputInterface(); -} - -template <> -class QFutureWatcher<void> : public QFutureWatcherBase -{ -public: - QFutureWatcher(QObject *_parent = 0) - : QFutureWatcherBase(_parent) - { } - ~QFutureWatcher() - { disconnectOutputInterface(); } - - void setFuture(const QFuture<void> &future); - QFuture<void> future() const - { return m_future; } - -private: - QFuture<void> m_future; - const QFutureInterfaceBase &futureInterface() const { return m_future.d; } - QFutureInterfaceBase &futureInterface() { return m_future.d; } -}; - -Q_INLINE_TEMPLATE void QFutureWatcher<void>::setFuture(const QFuture<void> &_future) -{ - if (_future == m_future) - return; - - disconnectOutputInterface(true); - m_future = _future; - connectOutputInterface(); -} - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif // QFUTUREWATCHER_H diff --git a/src/corelib/concurrent/qfuturewatcher_p.h b/src/corelib/concurrent/qfuturewatcher_p.h deleted file mode 100644 index 27bc49439a..0000000000 --- a/src/corelib/concurrent/qfuturewatcher_p.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QFUTUREWATCHER_P_H -#define QFUTUREWATCHER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qfutureinterface_p.h" -#include <qlist.h> - -#ifndef QT_NO_QFUTURE - -#include <private/qobject_p.h> - -QT_BEGIN_NAMESPACE - -class QFutureWatcherBase; -class QFutureWatcherBasePrivate : public QObjectPrivate, - public QFutureCallOutInterface -{ - Q_DECLARE_PUBLIC(QFutureWatcherBase) - -public: - QFutureWatcherBasePrivate(); - - void postCallOutEvent(const QFutureCallOutEvent &callOutEvent); - void callOutInterfaceDisconnected(); - - void sendCallOutEvent(QFutureCallOutEvent *event); - - QList<QFutureCallOutEvent *> pendingCallOutEvents; - QAtomicInt pendingResultsReady; - int maximumPendingResultsReady; - - QAtomicInt resultAtConnected; - bool finished; -}; - -QT_END_NAMESPACE - -#endif // QT_NO_QFUTURE -#endif diff --git a/src/corelib/concurrent/qtconcurrentcompilertest.h b/src/corelib/concurrent/qtconcurrentcompilertest.h deleted file mode 100644 index 7818423090..0000000000 --- a/src/corelib/concurrent/qtconcurrentcompilertest.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_COMPILERTEST_H -#define QTCONCURRENT_COMPILERTEST_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#if defined (Q_CC_MSVC) && (_MSC_VER < 1300) -# define QT_TYPENAME -#else -# define QT_TYPENAME typename -#endif - -namespace QtPrivate { - -template<class T> -class HasResultType { - typedef char Yes; - typedef void *No; - template<typename U> static Yes test(int, const typename U::result_type * = 0); - template<typename U> static No test(double); -public: - enum { Value = (sizeof(test<T>(0)) == sizeof(Yes)) }; -}; - -} - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentexception.cpp b/src/corelib/concurrent/qtconcurrentexception.cpp deleted file mode 100644 index caeaa8d9be..0000000000 --- a/src/corelib/concurrent/qtconcurrentexception.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtconcurrentexception.h" -#include "QtCore/qshareddata.h" - -#ifndef QT_NO_QFUTURE -#ifndef QT_NO_EXCEPTIONS - -QT_BEGIN_NAMESPACE - -/*! - \class QtConcurrent::Exception - \brief The Exception class provides a base class for exceptions that can transferred across threads. - \since 4.4 - - Qt Concurrent supports throwing and catching exceptions across thread - boundaries, provided that the exception inherit from QtConcurrent::Exception - and implement two helper functions: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp 0 - - QtConcurrent::Exception subclasses must be thrown by value and - caught by reference: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp 1 - - If you throw an exception that is not a subclass of QtConcurrent::Exception, - the Qt Concurrent functions will throw a QtConcurrent::UnhandledException - in the receiver thread. - - When using QFuture, transferred exceptions will be thrown when calling the following functions: - \list - \o QFuture::waitForFinished() - \o QFuture::result() - \o QFuture::resultAt() - \o QFuture::results() - \endlist -*/ - -/*! - \fn QtConcurrent::Exception::raise() const - In your QtConcurrent::Exception subclass, reimplement raise() like this: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp 2 -*/ - -/*! - \fn QtConcurrent::Exception::clone() const - In your QtConcurrent::Exception subclass, reimplement clone() like this: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentexception.cpp 3 -*/ - -/*! - \class QtConcurrent::UnhandledException - - \brief The UnhandledException class represents an unhandled exception in a worker thread. - \since 4.4 - - If a worker thread throws an exception that is not a subclass of QtConcurrent::Exception, - the Qt Concurrent functions will throw a QtConcurrent::UnhandledException - on the receiver thread side. - - Inheriting from this class is not supported. -*/ - -/*! - \fn QtConcurrent::UnhandledException::raise() const - \internal -*/ - -/*! - \fn QtConcurrent::UnhandledException::clone() const - \internal -*/ - -namespace QtConcurrent -{ - -void Exception::raise() const -{ - Exception e = *this; - throw e; -} - -Exception *Exception::clone() const -{ - return new Exception(*this); -} - -void UnhandledException::raise() const -{ - UnhandledException e = *this; - throw e; -} - -Exception *UnhandledException::clone() const -{ - return new UnhandledException(*this); -} - -#ifndef qdoc - -namespace internal { - -class Base : public QSharedData -{ -public: - Base(Exception *exception) - : exception(exception), hasThrown(false) { } - ~Base() { delete exception; } - - Exception *exception; - bool hasThrown; -}; - -ExceptionHolder::ExceptionHolder(Exception *exception) -: base(new Base(exception)) {} - -ExceptionHolder::ExceptionHolder(const ExceptionHolder &other) -: base(other.base) -{} - -void ExceptionHolder::operator=(const ExceptionHolder &other) -{ - base = other.base; -} - -ExceptionHolder::~ExceptionHolder() -{} - -Exception *ExceptionHolder::exception() const -{ - return base->exception; -} - -void ExceptionStore::setException(const Exception &e) -{ - if (hasException() == false) - exceptionHolder = ExceptionHolder(e.clone()); -} - -bool ExceptionStore::hasException() const -{ - return (exceptionHolder.exception() != 0); -} - -ExceptionHolder ExceptionStore::exception() -{ - return exceptionHolder; -} - -void ExceptionStore::throwPossibleException() -{ - if (hasException() ) { - exceptionHolder.base->hasThrown = true; - exceptionHolder.exception()->raise(); - } -} - -bool ExceptionStore::hasThrown() const { return exceptionHolder.base->hasThrown; } - -} // namespace internal - -#endif //qdoc - -} // namespace QtConcurrent - -QT_END_NAMESPACE - -#endif // QT_NO_EXCEPTIONS -#endif // QT_NO_CONCURRENT diff --git a/src/corelib/concurrent/qtconcurrentexception.h b/src/corelib/concurrent/qtconcurrentexception.h deleted file mode 100644 index b04e1f2a04..0000000000 --- a/src/corelib/concurrent/qtconcurrentexception.h +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_EXCEPTION_H -#define QTCONCURRENT_EXCEPTION_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_QFUTURE - -#include <QtCore/qatomic.h> -#include <QtCore/qshareddata.h> - -#ifndef QT_NO_EXCEPTIONS -# include <exception> -#endif - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -namespace QtConcurrent -{ - -#ifndef QT_NO_EXCEPTIONS - -class Q_CORE_EXPORT Exception : public std::exception -{ -public: - virtual void raise() const; - virtual Exception *clone() const; -}; - -class Q_CORE_EXPORT UnhandledException : public Exception -{ -public: - void raise() const; - Exception *clone() const; -}; - -namespace internal { - -class Base; -class ExceptionHolder -{ -public: - ExceptionHolder(Exception *exception = 0); - ExceptionHolder(const ExceptionHolder &other); - void operator=(const ExceptionHolder &other); - ~ExceptionHolder(); - Exception *exception() const; - QExplicitlySharedDataPointer<Base> base; -}; - -class Q_CORE_EXPORT ExceptionStore -{ -public: - void setException(const Exception &e); - bool hasException() const; - ExceptionHolder exception(); - void throwPossibleException(); - bool hasThrown() const; - ExceptionHolder exceptionHolder; -}; - -} // namespace internal - -#else // QT_NO_EXCEPTIONS - -namespace internal { - -class Q_CORE_EXPORT ExceptionStore -{ -public: - ExceptionStore() { } - inline void throwPossibleException() const {} -}; - -} // namespace internal - -#endif - -} // namespace QtConcurrent - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentfilter.cpp b/src/corelib/concurrent/qtconcurrentfilter.cpp deleted file mode 100644 index 76ce8ca659..0000000000 --- a/src/corelib/concurrent/qtconcurrentfilter.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \headerfile <QtConcurrentFilter> - \title Concurrent Filter and Filter-Reduce - \ingroup thread - - \brief The <QtConcurrentFilter> header provides concurrent Filter and - Filter-Reduce. - - These functions are a part of the \l {Concurrent Programming}{Qt Concurrent} framework. - - The QtConcurrent::filter(), QtConcurrent::filtered() and - QtConcurrent::filteredReduced() functions filter items in a sequence such - as a QList or a QVector in parallel. QtConcurrent::filter() modifies a - sequence in-place, QtConcurrent::filtered() returns a new sequence - containing the filtered content, and QtConcurrent::filteredReduced() - returns a single result. - - Each of the above functions have a blocking variant that returns the final - result instead of a QFuture. You use them in the same way as the - asynchronous variants. - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 6 - - Note that the result types above are not QFuture objects, but real result - types (in this case, QStringList and QSet<QString>). - - \section1 Concurrent Filter - - QtConcurrent::filtered() takes an input sequence and a filter function. - This filter function is then called for each item in the sequence, and a - new sequence containing the filtered values is returned. - - The filter function must be of the form: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 0 - - T must match the type stored in the sequence. The function returns true if - the item should be kept, false if it should be discarded. - - This example shows how to keep strings that are all lower-case from a - QStringList: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 1 - - The results of the filter are made available through QFuture. See the - QFuture and QFutureWatcher documentation for more information on how to - use QFuture in your applications. - - If you want to modify a sequence in-place, use QtConcurrent::filter(): - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 2 - - Since the sequence is modified in place, QtConcurrent::filter() does not - return any results via QFuture. However, you can still use QFuture and - QFutureWatcher to monitor the status of the filter. - - \section1 Concurrent Filter-Reduce - - QtConcurrent::filteredReduced() is similar to QtConcurrent::filtered(), - but instead of returing a sequence with the filtered results, the results - are combined into a single value using a reduce function. - - The reduce function must be of the form: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 3 - - T is the type of the final result, U is the type of items being filtered. - Note that the return value and return type of the reduce function are not - used. - - Call QtConcurrent::filteredReduced() like this: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 4 - - The reduce function will be called once for each result kept by the filter - function, and should merge the \e{intermediate} into the \e{result} - variable. QtConcurrent::filteredReduced() guarantees that only one thread - will call reduce at a time, so using a mutex to lock the result variable - is not necessary. The QtConcurrent::ReduceOptions enum provides a way to - control the order in which the reduction is done. - - \section1 Additional API Features - - \section2 Using Iterators instead of Sequence - - Each of the above functions has a variant that takes an iterator range - instead of a sequence. You use them in the same way as the sequence - variants: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 5 - - - \section2 Using Member Functions - - QtConcurrent::filter(), QtConcurrent::filtered(), and - QtConcurrent::filteredReduced() accept pointers to member functions. - The member function class type must match the type stored in the sequence: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 7 - - Note that when using QtConcurrent::filteredReduced(), you can mix the use of - normal and member functions freely: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 8 - - \section2 Using Function Objects - - QtConcurrent::filter(), QtConcurrent::filtered(), and - QtConcurrent::filteredReduced() accept function objects, which can be used to - add state to a function call. The result_type typedef must define the - result type of the function call operator: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 13 - - \section2 Using Bound Function Arguments - - Note that Qt does not provide support for bound functions. This is - provided by 3rd party libraries like - \l{http://www.boost.org/libs/bind/bind.html}{Boost} or - \l{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf} - {C++ TR1 Library Extensions}. - - If you want to use a filter function takes more than one argument, you can - use boost::bind() or std::tr1::bind() to transform it onto a function that - takes one argument. - - As an example, we use QString::contains(): - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 9 - - QString::contains() takes 2 arguments (including the "this" pointer) and - can't be used with QtConcurrent::filtered() directly, because - QtConcurrent::filtered() expects a function that takes one argument. To - use QString::contains() with QtConcurrent::filtered() we have to provide a - value for the \e regexp argument: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 10 - - The return value from boost::bind() is a function object (functor) with - the following signature: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 11 - - This matches what QtConcurrent::filtered() expects, and the complete - example becomes: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentfilter.cpp 12 -*/ - -/*! - \fn QFuture<void> QtConcurrent::filter(Sequence &sequence, FilterFunction filterFunction) - \relates <QtConcurrentFilter> - - Calls \a filterFunction once for each item in \a sequence. If - \a filterFunction returns true, the item is kept in \a sequence; - otherwise, the item is removed from \a sequence. -*/ - -/*! - \fn QFuture<T> QtConcurrent::filtered(const Sequence &sequence, FilterFunction filterFunction) - \relates <QtConcurrentFilter> - - Calls \a filterFunction once for each item in \a sequence and returns a - new Sequence of kept items. If \a filterFunction returns true, a copy of - the item is put in the new Sequence. Otherwise, the item will \e not - appear in the new Sequence. -*/ - -/*! - \fn QFuture<T> QtConcurrent::filtered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction) - \relates <QtConcurrentFilter> - - Calls \a filterFunction once for each item from \a begin to \a end and - returns a new Sequence of kept items. If \a filterFunction returns true, a - copy of the item is put in the new Sequence. Otherwise, the item will - \e not appear in the new Sequence. -*/ - -/*! - \fn QFuture<T> QtConcurrent::filteredReduced(const Sequence &sequence, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) - \relates <QtConcurrentFilter> - - Calls \a filterFunction once for each item in \a sequence. If - \a filterFunction returns 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 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. -*/ - -/*! - \fn QFuture<T> QtConcurrent::filteredReduced(ConstIterator begin, ConstIterator end, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) - \relates <QtConcurrentFilter> - - Calls \a filterFunction once for each item from \a begin to \a end. If - \a filterFunction returns 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 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. -*/ - -/*! - \fn void QtConcurrent::blockingFilter(Sequence &sequence, FilterFunction filterFunction) - - Calls \a filterFunction once for each item in \a sequence. If - \a filterFunction returns 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. -*/ - -/*! - \fn Sequence QtConcurrent::blockingFiltered(const Sequence &sequence, FilterFunction filterFunction) - - Calls \a filterFunction once for each item in \a sequence and returns a - new Sequence of kept items. If \a filterFunction returns 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() -*/ - -/*! - \fn Sequence QtConcurrent::blockingFiltered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction) - - Calls \a filterFunction once for each item from \a begin to \a end and - returns a new Sequence of kept items. If \a filterFunction returns 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() -*/ - -/*! - \fn T QtConcurrent::blockingFilteredReduced(const Sequence &sequence, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) - - Calls \a filterFunction once for each item in \a sequence. If - \a filterFunction returns 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 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() -*/ - -/*! - \fn T QtConcurrent::blockingFilteredReduced(ConstIterator begin, ConstIterator end, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) - - Calls \a filterFunction once for each item from \a begin to \a end. If - \a filterFunction returns 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 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() -*/ diff --git a/src/corelib/concurrent/qtconcurrentfilter.h b/src/corelib/concurrent/qtconcurrentfilter.h deleted file mode 100644 index f5c38654d3..0000000000 --- a/src/corelib/concurrent/qtconcurrentfilter.h +++ /dev/null @@ -1,269 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_FILTER_H -#define QTCONCURRENT_FILTER_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qtconcurrentfilterkernel.h> -#include <QtCore/qtconcurrentfunctionwrappers.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifdef qdoc - -namespace QtConcurrent { - - QFuture<void> filter(Sequence &sequence, FilterFunction filterFunction); - - template <typename T> - QFuture<T> filtered(const Sequence &sequence, FilterFunction filterFunction); - template <typename T> - QFuture<T> filtered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction); - - template <typename T> - QFuture<T> filteredReduced(const Sequence &sequence, - FilterFunction filterFunction, - ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); - template <typename T> - QFuture<T> filteredReduced(ConstIterator begin, - ConstIterator end, - FilterFunction filterFunction, - ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); - - void blockingFilter(Sequence &sequence, FilterFunction filterFunction); - - template <typename Sequence> - Sequence blockingFiltered(const Sequence &sequence, FilterFunction filterFunction); - template <typename Sequence> - Sequence blockingFiltered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction); - - template <typename T> - T blockingFilteredReduced(const Sequence &sequence, - FilterFunction filterFunction, - ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); - template <typename T> - T blockingFilteredReduced(ConstIterator begin, - ConstIterator end, - FilterFunction filterFunction, - ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce); - -} // namespace QtConcurrent - -#else - -namespace QtConcurrent { - -template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> -ThreadEngineStarter<void> filterInternal(Sequence &sequence, KeepFunctor keep, ReduceFunctor reduce) -{ - typedef typename Sequence::const_iterator Iterator; - typedef FilterKernel<Sequence, KeepFunctor, ReduceFunctor> KernelType; - return startThreadEngine(new KernelType(sequence, keep, reduce)); -} - -// filter() on sequences -template <typename Sequence, typename KeepFunctor> -QFuture<void> filter(Sequence &sequence, KeepFunctor keep) -{ - return filterInternal(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper()); -} - -// filteredReduced() on sequences -template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor> -QFuture<ResultType> filteredReduced(const Sequence &sequence, - KeepFunctor keep, - ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startFilteredReduced<ResultType>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(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> - (sequence, - QtPrivate::createFunctionWrapper(keep), - QtPrivate::createFunctionWrapper(reduce), - options); -} - -// filteredReduced() on iterators -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)) -{ - return startFilteredReduced<ResultType>(begin, end, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(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> - (begin, end, - QtPrivate::createFunctionWrapper(keep), - QtPrivate::createFunctionWrapper(reduce), - options); -} - -// filtered() on sequences -template <typename Sequence, typename KeepFunctor> -QFuture<typename Sequence::value_type> filtered(const Sequence &sequence, KeepFunctor keep) -{ - return startFiltered(sequence, QtPrivate::createFunctionWrapper(keep)); -} - -// filtered() on iterators -template <typename Iterator, typename KeepFunctor> -QFuture<typename qValueType<Iterator>::value_type> filtered(Iterator begin, Iterator end, KeepFunctor keep) -{ - return startFiltered(begin, end, QtPrivate::createFunctionWrapper(keep)); -} - -// blocking filter() on sequences -template <typename Sequence, typename KeepFunctor> -void blockingFilter(Sequence &sequence, KeepFunctor keep) -{ - filterInternal(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper()).startBlocking(); -} - -// blocking filteredReduced() on sequences -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>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::createFunctionWrapper(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 blockingFilteredReduced<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> - (sequence, - QtPrivate::createFunctionWrapper(keep), - QtPrivate::createFunctionWrapper(reduce), - options); -} - -// blocking filteredReduced() on iterators -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> - (begin, end, - QtPrivate::createFunctionWrapper(keep), - QtPrivate::createFunctionWrapper(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> - (begin, end, - QtPrivate::createFunctionWrapper(keep), - QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); -} - -// blocking filtered() on sequences -template <typename Sequence, typename KeepFunctor> -Sequence blockingFiltered(const Sequence &sequence, KeepFunctor keep) -{ - return startFilteredReduced<Sequence>(sequence, QtPrivate::createFunctionWrapper(keep), QtPrivate::PushBackWrapper(), OrderedReduce).startBlocking(); -} - -// blocking filtered() on iterators -template <typename OutputSequence, typename Iterator, typename KeepFunctor> -OutputSequence blockingFiltered(Iterator begin, Iterator end, KeepFunctor keep) -{ - return startFilteredReduced<OutputSequence>(begin, end, - QtPrivate::createFunctionWrapper(keep), - QtPrivate::PushBackWrapper(), - OrderedReduce).startBlocking(); -} - -} // namespace QtConcurrent - -#endif // qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentfilterkernel.h b/src/corelib/concurrent/qtconcurrentfilterkernel.h deleted file mode 100644 index ea0e5fcf5d..0000000000 --- a/src/corelib/concurrent/qtconcurrentfilterkernel.h +++ /dev/null @@ -1,350 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_FILTERKERNEL_H -#define QTCONCURRENT_FILTERKERNEL_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qtconcurrentiteratekernel.h> -#include <QtCore/qtconcurrentmapkernel.h> -#include <QtCore/qtconcurrentreducekernel.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifndef qdoc - -namespace QtConcurrent { - -template <typename T> -struct qValueType -{ - typedef typename T::value_type value_type; -}; - -template <typename T> -struct qValueType<const T*> -{ - typedef T value_type; -}; - -template <typename T> -struct qValueType<T*> -{ - typedef T value_type; -}; - -// Implementation of filter -template <typename Sequence, typename KeepFunctor, typename ReduceFunctor> -class FilterKernel : public IterateKernel<typename Sequence::const_iterator, void> -{ - typedef ReduceKernel<ReduceFunctor, Sequence, typename Sequence::value_type> Reducer; - typedef IterateKernel<typename Sequence::const_iterator, void> IterateKernelType; - typedef typename ReduceFunctor::result_type T; - - Sequence reducedResult; - Sequence &sequence; - KeepFunctor keep; - ReduceFunctor reduce; - Reducer reducer; - -public: - FilterKernel(Sequence &_sequence, KeepFunctor _keep, ReduceFunctor _reduce) - : IterateKernelType(const_cast<const Sequence &>(_sequence).begin(), const_cast<const Sequence &>(_sequence).end()), reducedResult(), - sequence(_sequence), - keep(_keep), - reduce(_reduce), - reducer(OrderedReduce) - { } - - bool runIteration(typename Sequence::const_iterator it, int index, T *) - { - IntermediateResults<typename Sequence::value_type> results; - results.begin = index; - results.end = index + 1; - - if (keep(*it)) - results.vector.append(*it); - - reducer.runReduce(reduce, reducedResult, results); - return false; - } - - bool runIterations(typename Sequence::const_iterator sequenceBeginIterator, int begin, int end, T *) - { - IntermediateResults<typename Sequence::value_type> results; - results.begin = begin; - results.end = end; - results.vector.reserve(end - begin); - - - typename Sequence::const_iterator it = sequenceBeginIterator; - advance(it, begin); - for (int i = begin; i < end; ++i) { - if (keep(*it)) - results.vector.append(*it); - advance(it, 1); - } - - reducer.runReduce(reduce, reducedResult, results); - return false; - } - - void finish() - { - reducer.finish(reduce, reducedResult); - sequence = reducedResult; - } - - inline bool shouldThrottleThread() - { - return IterateKernelType::shouldThrottleThread() || reducer.shouldThrottle(); - } - - inline bool shouldStartThread() - { - return IterateKernelType::shouldStartThread() && reducer.shouldStartThread(); - } - - typedef void ReturnType; - typedef void ResultType; -}; - -// Implementation of filter-reduce -template <typename ReducedResultType, - typename Iterator, - typename KeepFunctor, - typename ReduceFunctor, - typename Reducer = ReduceKernel<ReduceFunctor, - ReducedResultType, - typename qValueType<Iterator>::value_type> > -class FilteredReducedKernel : public IterateKernel<Iterator, ReducedResultType> -{ - ReducedResultType reducedResult; - KeepFunctor keep; - ReduceFunctor reduce; - Reducer reducer; - typedef IterateKernel<Iterator, ReducedResultType> IterateKernelType; - -public: - FilteredReducedKernel(Iterator begin, - Iterator end, - KeepFunctor _keep, - ReduceFunctor _reduce, - ReduceOptions reduceOption) - : IterateKernelType(begin, end), reducedResult(), keep(_keep), reduce(_reduce), reducer(reduceOption) - { } - -#if 0 - FilteredReducedKernel(ReducedResultType initialValue, - KeepFunctor keep, - ReduceFunctor reduce, - ReduceOption reduceOption) - : reducedResult(initialValue), keep(keep), reduce(reduce), reducer(reduceOption) - { } -#endif - - bool runIteration(Iterator it, int index, ReducedResultType *) - { - IntermediateResults<typename qValueType<Iterator>::value_type> results; - results.begin = index; - results.end = index + 1; - - if (keep(*it)) - results.vector.append(*it); - - reducer.runReduce(reduce, reducedResult, results); - return false; - } - - bool runIterations(Iterator sequenceBeginIterator, int begin, int end, ReducedResultType *) - { - IntermediateResults<typename qValueType<Iterator>::value_type> results; - results.begin = begin; - results.end = end; - results.vector.reserve(end - begin); - - Iterator it = sequenceBeginIterator; - advance(it, begin); - for (int i = begin; i < end; ++i) { - if (keep(*it)) - results.vector.append(*it); - advance(it, 1); - } - - reducer.runReduce(reduce, reducedResult, results); - return false; - } - - void finish() - { - reducer.finish(reduce, reducedResult); - } - - inline bool shouldThrottleThread() - { - return IterateKernelType::shouldThrottleThread() || reducer.shouldThrottle(); - } - - inline bool shouldStartThread() - { - return IterateKernelType::shouldStartThread() && reducer.shouldStartThread(); - } - - typedef ReducedResultType ReturnType; - typedef ReducedResultType ResultType; - ReducedResultType *result() - { - return &reducedResult; - } -}; - -// Implementation of filter that reports individual results via QFutureInterface -template <typename Iterator, typename KeepFunctor> -class FilteredEachKernel : public IterateKernel<Iterator, typename qValueType<Iterator>::value_type> -{ - typedef typename qValueType<Iterator>::value_type T; - typedef IterateKernel<Iterator, T> IterateKernelType; - - KeepFunctor keep; - -public: - typedef T ReturnType; - typedef T ResultType; - - FilteredEachKernel(Iterator begin, Iterator end, KeepFunctor _keep) - : IterateKernelType(begin, end), keep(_keep) - { } - - void start() - { - if (this->futureInterface) - this->futureInterface->setFilterMode(true); - IterateKernelType::start(); - } - - bool runIteration(Iterator it, int index, T *) - { - if (keep(*it)) - this->reportResult(&(*it), index); - else - this->reportResult(0, index); - return false; - } - - bool runIterations(Iterator sequenceBeginIterator, int begin, int end, T *) - { - const int count = end - begin; - IntermediateResults<typename qValueType<Iterator>::value_type> results; - results.begin = begin; - results.end = end; - results.vector.reserve(count); - - Iterator it = sequenceBeginIterator; - advance(it, begin); - for (int i = begin; i < end; ++i) { - if (keep(*it)) - results.vector.append(*it); - advance(it, 1); - } - - this->reportResults(results.vector, begin, count); - return false; - } -}; - -template <typename Iterator, typename KeepFunctor> -inline -ThreadEngineStarter<typename qValueType<Iterator>::value_type> -startFiltered(Iterator begin, Iterator end, KeepFunctor functor) -{ - return startThreadEngine(new FilteredEachKernel<Iterator, KeepFunctor>(begin, end, functor)); -} - -template <typename Sequence, typename KeepFunctor> -inline ThreadEngineStarter<typename Sequence::value_type> -startFiltered(const Sequence &sequence, KeepFunctor functor) -{ - typedef SequenceHolder1<Sequence, - FilteredEachKernel<typename Sequence::const_iterator, KeepFunctor>, - KeepFunctor> - SequenceHolderType; - return startThreadEngine(new SequenceHolderType(sequence, functor)); -} - -template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> -inline ThreadEngineStarter<ResultType> startFilteredReduced(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)); -} - - -template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor> -inline ThreadEngineStarter<ResultType> startFilteredReduced(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)); -} - - -} // namespace QtConcurrent - -#endif // qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentfunctionwrappers.h b/src/corelib/concurrent/qtconcurrentfunctionwrappers.h deleted file mode 100644 index 9b86b73f6d..0000000000 --- a/src/corelib/concurrent/qtconcurrentfunctionwrappers.h +++ /dev/null @@ -1,303 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_FUNCTIONWRAPPERS_H -#define QTCONCURRENT_FUNCTIONWRAPPERS_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifndef qdoc - -namespace QtConcurrent { - -template <typename T> -class FunctionWrapper0 -{ -public: - typedef T (*FunctionPointerType)(); - typedef T result_type; - inline FunctionWrapper0(FunctionPointerType _functionPointer) - :functionPointer(_functionPointer) { } - - inline T operator()() - { - return functionPointer(); - } -private: - FunctionPointerType functionPointer; -}; - -template <typename T, typename U> -class FunctionWrapper1 -{ -public: - typedef T (*FunctionPointerType)(U u); - typedef T result_type; - inline FunctionWrapper1(FunctionPointerType _functionPointer) - :functionPointer(_functionPointer) { } - - inline T operator()(U u) - { - return functionPointer(u); - } - -private: - FunctionPointerType functionPointer; -}; - -template <typename T, typename U, typename V> -class FunctionWrapper2 -{ -public: - typedef T (*FunctionPointerType)(U u, V v); - typedef T result_type; - inline FunctionWrapper2(FunctionPointerType _functionPointer) - :functionPointer(_functionPointer) { } - - inline T operator()(U u, V v) - { - return functionPointer(u, v); - } -private: - FunctionPointerType functionPointer; -}; - -template <typename T, typename C> -class MemberFunctionWrapper -{ -public: - typedef T (C::*FunctionPointerType)(); - typedef T result_type; - inline MemberFunctionWrapper(FunctionPointerType _functionPointer) - :functionPointer(_functionPointer) { } - - inline T operator()(C &c) - { - return (c.*functionPointer)(); - } -private: - FunctionPointerType functionPointer; -}; - -template <typename T, typename C, typename U> -class MemberFunctionWrapper1 -{ -public: - typedef T (C::*FunctionPointerType)(U); - typedef T result_type; - - inline MemberFunctionWrapper1(FunctionPointerType _functionPointer) - : functionPointer(_functionPointer) - { } - - inline T operator()(C &c, U u) - { - return (c.*functionPointer)(u); - } - -private: - FunctionPointerType functionPointer; -}; - -template <typename T, typename C> -class ConstMemberFunctionWrapper -{ -public: - typedef T (C::*FunctionPointerType)() const; - typedef T result_type; - inline ConstMemberFunctionWrapper(FunctionPointerType _functionPointer) - :functionPointer(_functionPointer) { } - - inline T operator()(const C &c) const - { - return (c.*functionPointer)(); - } -private: - FunctionPointerType functionPointer; -}; - -} // namespace QtConcurrent. - -namespace QtPrivate { - -template <typename T> -const T& createFunctionWrapper(const T& t) -{ - return t; -} - -template <typename T, typename U> -QtConcurrent::FunctionWrapper1<T, U> createFunctionWrapper(T (*func)(U)) -{ - return QtConcurrent::FunctionWrapper1<T, U>(func); -} - -template <typename T, typename C> -QtConcurrent::MemberFunctionWrapper<T, C> createFunctionWrapper(T (C::*func)()) -{ - return QtConcurrent::MemberFunctionWrapper<T, C>(func); -} - -template <typename T, typename C, typename U> -QtConcurrent::MemberFunctionWrapper1<T, C, U> createFunctionWrapper(T (C::*func)(U)) -{ - return QtConcurrent::MemberFunctionWrapper1<T, C, U>(func); -} - -template <typename T, typename C> -QtConcurrent::ConstMemberFunctionWrapper<T, C> createFunctionWrapper(T (C::*func)() const) -{ - return QtConcurrent::ConstMemberFunctionWrapper<T, C>(func); -} - -struct PushBackWrapper -{ - typedef void result_type; - - template <class C, class U> - inline void operator()(C &c, const U &u) const - { - return c.push_back(u); - } - -#ifdef Q_COMPILER_RVALUE_REFS - template <class C, class U> - inline void operator()(C &c, U &&u) const - { - return c.push_back(u); - } -#endif -}; - -template <typename Functor, bool foo = HasResultType<Functor>::Value> -struct LazyResultType { typedef typename Functor::result_type Type; }; -template <typename Functor> -struct LazyResultType<Functor, false> { typedef void Type; }; - -template <class T> -struct ReduceResultType; - -template <class U, class V> -struct ReduceResultType<void(*)(U&,V)> -{ - typedef U ResultType; -}; - -template <class T, class C, class U> -struct ReduceResultType<T(C::*)(U)> -{ - typedef C ResultType; -}; - -template <class InputSequence, class MapFunctor> -struct MapResultType -{ - typedef typename LazyResultType<MapFunctor>::Type ResultType; -}; - -template <class U, class V> -struct MapResultType<void, U (*)(V)> -{ - typedef U ResultType; -}; - -template <class T, class C> -struct MapResultType<void, T(C::*)() const> -{ - typedef T ResultType; -}; - -#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS - -template <template <typename> class InputSequence, typename MapFunctor, typename T> -struct MapResultType<InputSequence<T>, MapFunctor> -{ - typedef InputSequence<typename LazyResultType<MapFunctor>::Type> ResultType; -}; - -template <template <typename> class InputSequence, class T, class U, class V> -struct MapResultType<InputSequence<T>, U (*)(V)> -{ - typedef InputSequence<U> ResultType; -}; - -template <template <typename> class InputSequence, class T, class U, class C> -struct MapResultType<InputSequence<T>, U(C::*)() const> -{ - typedef InputSequence<U> ResultType; -}; - -#endif // QT_NO_TEMPLATE_TEMPLATE_PARAMETER - -template <class MapFunctor> -struct MapResultType<QStringList, MapFunctor> -{ - typedef QList<typename LazyResultType<MapFunctor>::Type> ResultType; -}; - -template <class U, class V> -struct MapResultType<QStringList, U (*)(V)> -{ - typedef QList<U> ResultType; -}; - -template <class U, class C> -struct MapResultType<QStringList, U(C::*)() const> -{ - typedef QList<U> ResultType; -}; - -} // namespace QtPrivate. - -#endif //qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentiteratekernel.cpp b/src/corelib/concurrent/qtconcurrentiteratekernel.cpp deleted file mode 100644 index b695805135..0000000000 --- a/src/corelib/concurrent/qtconcurrentiteratekernel.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtconcurrentiteratekernel.h" - -#if defined(Q_OS_MAC) -#include <mach/mach.h> -#include <mach/mach_time.h> -#include <unistd.h> -#elif defined(Q_OS_UNIX) -#if defined(Q_OS_HURD) -#include <sys/time.h> -#endif -#include <time.h> -#include <unistd.h> -#elif defined(Q_OS_WIN) -#include <qt_windows.h> -#endif - -#include "private/qfunctions_p.h" - - -#ifndef QT_NO_CONCURRENT - -QT_BEGIN_NAMESPACE - -enum { - TargetRatio = 100, - MedianSize = 7 -}; - -#if defined(Q_OS_MAC) - -static qint64 getticks() -{ - return mach_absolute_time(); -} - -#elif defined(Q_OS_UNIX) - - -static qint64 getticks() -{ -#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) - clockid_t clockId; - -#ifndef _POSIX_THREAD_CPUTIME - clockId = CLOCK_REALTIME; -#elif (_POSIX_THREAD_CPUTIME-0 <= 0) - // if we don't have CLOCK_THREAD_CPUTIME_ID, we have to just use elapsed realtime instead - clockId = CLOCK_REALTIME; - -# if (_POSIX_THREAD_CPUTIME-0 == 0) - // detect availablility of CLOCK_THREAD_CPUTIME_ID - static long useThreadCpuTime = -2; - if (useThreadCpuTime == -2) { - // sysconf() will return either -1 or _POSIX_VERSION (don't care about thread races here) - useThreadCpuTime = sysconf(_SC_THREAD_CPUTIME); - } - if (useThreadCpuTime != -1) - clockId = CLOCK_THREAD_CPUTIME_ID; -# endif -#else - clockId = CLOCK_THREAD_CPUTIME_ID; -#endif - - struct timespec ts; - if (clock_gettime(clockId, &ts) == -1) - return 0; - return (ts.tv_sec * 1000000000) + ts.tv_nsec; -#else - - // no clock_gettime(), fall back to wall time - struct timeval tv; - gettimeofday(&tv, 0); - return (tv.tv_sec * 1000000) + tv.tv_usec; -#endif -} - -#elif defined(Q_OS_WIN) - -static qint64 getticks() -{ - LARGE_INTEGER x; - if (!QueryPerformanceCounter(&x)) - return 0; - return x.QuadPart; -} - -#endif - -static double elapsed(qint64 after, qint64 before) -{ - return double(after - before); -} - -namespace QtConcurrent { - -/*! \internal - -*/ -BlockSizeManager::BlockSizeManager(int iterationCount) -: maxBlockSize(iterationCount / (QThreadPool::globalInstance()->maxThreadCount() * 2)), - beforeUser(0), afterUser(0), - controlPartElapsed(MedianSize), userPartElapsed(MedianSize), - m_blockSize(1) -{ } - -// Records the time before user code. -void BlockSizeManager::timeBeforeUser() -{ - if (blockSizeMaxed()) - return; - - beforeUser = getticks(); - controlPartElapsed.addValue(elapsed(beforeUser, afterUser)); -} - - // Records the time after user code and adjust the block size if we are spending - // to much time in the for control code compared with the user code. -void BlockSizeManager::timeAfterUser() -{ - if (blockSizeMaxed()) - return; - - afterUser = getticks(); - userPartElapsed.addValue(elapsed(afterUser, beforeUser)); - - if (controlPartElapsed.isMedianValid() == false) - return; - - if (controlPartElapsed.median() * TargetRatio < userPartElapsed.median()) - return; - - m_blockSize = qMin(m_blockSize * 2, maxBlockSize); - -#ifdef QTCONCURRENT_FOR_DEBUG - qDebug() << QThread::currentThread() << "adjusting block size" << controlPartElapsed.median() << userPartElapsed.median() << m_blockSize; -#endif - - // Reset the medians after adjusting the block size so we get - // new measurements with the new block size. - controlPartElapsed.reset(); - userPartElapsed.reset(); -} - -int BlockSizeManager::blockSize() -{ - return m_blockSize; -} - -} // namespace QtConcurrent - -QT_END_NAMESPACE - -#endif // QT_NO_CONCURRENT diff --git a/src/corelib/concurrent/qtconcurrentiteratekernel.h b/src/corelib/concurrent/qtconcurrentiteratekernel.h deleted file mode 100644 index 527bd85a22..0000000000 --- a/src/corelib/concurrent/qtconcurrentiteratekernel.h +++ /dev/null @@ -1,339 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_ITERATEKERNEL_H -#define QTCONCURRENT_ITERATEKERNEL_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qatomic.h> -#include <QtCore/qtconcurrentmedian.h> -#include <QtCore/qtconcurrentthreadengine.h> - -#ifndef QT_NO_STL -# include <iterator> -#endif - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifndef qdoc - -namespace QtConcurrent { - -#ifndef QT_NO_STL - using std::advance; -#else - template <typename It, typename T> - void advance(It &it, T value) - { - it+=value; - } -#endif - -/* - The BlockSizeManager class manages how many iterations a thread should - reserve and process at a time. This is done by measuring the time spent - in the user code versus the control part code, and then increasing - the block size if the ratio between them is to small. The block size - management is done on the basis of the median of several timing measuremens, - and it is done induvidualy for each thread. -*/ -class Q_CORE_EXPORT BlockSizeManager -{ -public: - BlockSizeManager(int iterationCount); - void timeBeforeUser(); - void timeAfterUser(); - int blockSize(); -private: - inline bool blockSizeMaxed() - { - return (m_blockSize >= maxBlockSize); - } - - const int maxBlockSize; - qint64 beforeUser; - qint64 afterUser; - Median<double> controlPartElapsed; - Median<double> userPartElapsed; - int m_blockSize; -}; - -template <typename T> -class ResultReporter -{ -public: - ResultReporter(ThreadEngine<T> *_threadEngine) - :threadEngine(_threadEngine) - { - - } - - void reserveSpace(int resultCount) - { - currentResultCount = resultCount; - vector.resize(qMax(resultCount, vector.count())); - } - - void reportResults(int begin) - { - const int useVectorThreshold = 4; // Tunable parameter. - if (currentResultCount > useVectorThreshold) { - vector.resize(currentResultCount); - threadEngine->reportResults(vector, begin); - } else { - for (int i = 0; i < currentResultCount; ++i) - threadEngine->reportResult(&vector.at(i), begin + i); - } - } - - inline T * getPointer() - { - return vector.data(); - } - - int currentResultCount; - ThreadEngine<T> *threadEngine; - QVector<T> vector; -}; - -template <> -class ResultReporter<void> -{ -public: - inline ResultReporter(ThreadEngine<void> *) { } - inline void reserveSpace(int) { } - inline void reportResults(int) { } - inline void * getPointer() { return 0; } -}; - -#ifndef QT_NO_STL -inline bool selectIteration(std::bidirectional_iterator_tag) -{ - return false; // while -} - -inline bool selectIteration(std::forward_iterator_tag) -{ - return false; // while -} - -inline bool selectIteration(std::random_access_iterator_tag) -{ - return true; // for -} -#else -// no stl support, always use while iteration -template <typename T> -inline bool selectIteration(T) -{ - return false; // while -} -#endif - -template <typename Iterator, typename T> -class IterateKernel : public ThreadEngine<T> -{ -public: - typedef T ResultType; - - IterateKernel(Iterator _begin, Iterator _end) -#if defined (QT_NO_STL) - : begin(_begin), end(_end), current(_begin), currentIndex(0), - forIteration(false), progressReportingEnabled(true) -#else - : begin(_begin), end(_end), current(_begin), currentIndex(0), - forIteration(selectIteration(typename std::iterator_traits<Iterator>::iterator_category())), progressReportingEnabled(true) -#endif - { -#if defined (QT_NO_STL) - iterationCount = 0; -#else - iterationCount = forIteration ? std::distance(_begin, _end) : 0; - -#endif - } - - virtual ~IterateKernel() { } - - virtual bool runIteration(Iterator it, int index , T *result) - { Q_UNUSED(it); Q_UNUSED(index); Q_UNUSED(result); return false; } - virtual bool runIterations(Iterator _begin, int beginIndex, int endIndex, T *results) - { Q_UNUSED(_begin); Q_UNUSED(beginIndex); Q_UNUSED(endIndex); Q_UNUSED(results); return false; } - - void start() - { - progressReportingEnabled = this->isProgressReportingEnabled(); - if (progressReportingEnabled && iterationCount > 0) - this->setProgressRange(0, iterationCount); - } - - bool shouldStartThread() - { - if (forIteration) - return (currentIndex.load() < iterationCount) && !this->shouldThrottleThread(); - else // whileIteration - return (iteratorThreads.load() == 0); - } - - ThreadFunctionResult threadFunction() - { - if (forIteration) - return this->forThreadFunction(); - else // whileIteration - return this->whileThreadFunction(); - } - - ThreadFunctionResult forThreadFunction() - { - BlockSizeManager blockSizeManager(iterationCount); - ResultReporter<T> resultReporter(this); - - for(;;) { - if (this->isCanceled()) - break; - - const int currentBlockSize = blockSizeManager.blockSize(); - - if (currentIndex.load() >= iterationCount) - break; - - // Atomically reserve a block of iterationCount for this thread. - const int beginIndex = currentIndex.fetchAndAddRelease(currentBlockSize); - const int endIndex = qMin(beginIndex + currentBlockSize, iterationCount); - - if (beginIndex >= endIndex) { - // No more work - break; - } - - this->waitForResume(); // (only waits if the qfuture is paused.) - - if (shouldStartThread()) - this->startThread(); - - const int finalBlockSize = endIndex - beginIndex; // block size adjusted for possible end-of-range - resultReporter.reserveSpace(finalBlockSize); - - // Call user code with the current iteration range. - blockSizeManager.timeBeforeUser(); - const bool resultsAvailable = this->runIterations(begin, beginIndex, endIndex, resultReporter.getPointer()); - blockSizeManager.timeAfterUser(); - - if (resultsAvailable) - resultReporter.reportResults(beginIndex); - - // Report progress if progress reporting enabled. - if (progressReportingEnabled) { - completed.fetchAndAddAcquire(finalBlockSize); - this->setProgressValue(this->completed.load()); - } - - if (this->shouldThrottleThread()) - return ThrottleThread; - } - return ThreadFinished; - } - - ThreadFunctionResult whileThreadFunction() - { - if (iteratorThreads.testAndSetAcquire(0, 1) == false) - return ThreadFinished; - - ResultReporter<T> resultReporter(this); - resultReporter.reserveSpace(1); - - while (current != end) { - // The following two lines breaks support for input iterators according to - // the sgi docs: dereferencing prev after calling ++current is not allowed - // on input iterators. (prev is dereferenced inside user.runIteration()) - Iterator prev = current; - ++current; - int index = currentIndex.fetchAndAddRelaxed(1); - iteratorThreads.testAndSetRelease(1, 0); - - this->waitForResume(); // (only waits if the qfuture is paused.) - - if (shouldStartThread()) - this->startThread(); - - const bool resultAavailable = this->runIteration(prev, index, resultReporter.getPointer()); - if (resultAavailable) - resultReporter.reportResults(index); - - if (this->shouldThrottleThread()) - return ThrottleThread; - - if (iteratorThreads.testAndSetAcquire(0, 1) == false) - return ThreadFinished; - } - - return ThreadFinished; - } - - -public: - const Iterator begin; - const Iterator end; - Iterator current; - QAtomicInt currentIndex; - bool forIteration; - QAtomicInt iteratorThreads; - int iterationCount; - - bool progressReportingEnabled; - QAtomicInt completed; -}; - -} // namespace QtConcurrent - -#endif //qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentmap.cpp b/src/corelib/concurrent/qtconcurrentmap.cpp deleted file mode 100644 index 1758cb9e95..0000000000 --- a/src/corelib/concurrent/qtconcurrentmap.cpp +++ /dev/null @@ -1,402 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \namespace QtConcurrent - \inmodule QtCore - \since 4.4 - \brief The QtConcurrent namespace provides high-level APIs that make it - possible to write multi-threaded programs without using low-level - threading primitives. - - See the \l {Concurrent Programming}{Qt Concurrent} chapter in - the \l{threads.html}{threading} documentation. - - \inheaderfile QtCore - \ingroup thread -*/ - -/*! - \namespace QtConcurrent::internal - \internal - - \brief The QtConcurrent::internal namespace contains QtConcurrent - implementation details. -*/ - -/*! - \enum QtConcurrent::ReduceOption - This enum specifies the order of which results from the map or filter - function are passed to the reduce function. - - \value UnorderedReduce Reduction is done in an arbitrary order. - \value OrderedReduce Reduction is done in the order of the - original sequence. - \value SequentialReduce Reduction is done sequentially: only one - thread will enter the reduce function at a time. (Parallel reduction - might be supported in a future version of Qt Concurrent.) -*/ - -/*! - \headerfile <QtConcurrentMap> - \title Concurrent Map and Map-Reduce - \ingroup thread - - \brief The <QtConcurrentMap> header provides concurrent Map and MapReduce. - - These functions are a part of the \l {Concurrent Programming}{Qt Concurrent} framework. - - The QtConcurrent::map(), QtConcurrent::mapped() and - QtConcurrent::mappedReduced() functions run computations in parallel on - the items in a sequence such as a QList or a QVector. QtConcurrent::map() - modifies a sequence in-place, QtConcurrent::mapped() returns a new - sequence containing the modified content, and QtConcurrent::mappedReduced() - returns a single result. - - Each of the above functions has a blocking variant that returns - the final result instead of a QFuture. You use them in the same - way as the asynchronous variants. - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 7 - - Note that the result types above are not QFuture objects, but real result - types (in this case, QList<QImage> and QImage). - - \section1 Concurrent Map - - QtConcurrent::mapped() takes an input sequence and a map function. This map - function is then called for each item in the sequence, and a new sequence - containing the return values from the map function is returned. - - The map function must be of the form: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 0 - - T and U can be any type (and they can even be the same type), but T must - match the type stored in the sequence. The function returns the modified - or \e mapped content. - - This example shows how to apply a scale function to all the items - in a sequence: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 1 - - The results of the map are made available through QFuture. See the - QFuture and QFutureWatcher documentation for more information on how to - use QFuture in your applications. - - If you want to modify a sequence in-place, use QtConcurrent::map(). The - map function must then be of the form: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 2 - - Note that the return value and return type of the map function are not - used. - - Using QtConcurrent::map() is similar to using QtConcurrent::mapped(): - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 3 - - Since the sequence is modified in place, QtConcurrent::map() does not - return any results via QFuture. However, you can still use QFuture and - QFutureWatcher to monitor the status of the map. - - \section1 Concurrent Map-Reduce - - QtConcurrent::mappedReduced() is similar to QtConcurrent::mapped(), but - instead of returning a sequence with the new results, the results are - combined into a single value using a reduce function. - - The reduce function must be of the form: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 4 - - T is the type of the final result, U is the return type of the map - function. Note that the return value and return type of the reduce - function are not used. - - Call QtConcurrent::mappedReduced() like this: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 5 - - The reduce function will be called once for each result returned by the map - function, and should merge the \e{intermediate} into the \e{result} - variable. QtConcurrent::mappedReduced() guarantees that only one thread - will call reduce at a time, so using a mutex to lock the result variable - is not necessary. The QtConcurrent::ReduceOptions enum provides a way to - control the order in which the reduction is done. If - QtConcurrent::UnorderedReduce is used (the default), the order is - undefined, while QtConcurrent::OrderedReduce ensures that the reduction - is done in the order of the original sequence. - - \section1 Additional API Features - - \section2 Using Iterators instead of Sequence - - Each of the above functions has a variant that takes an iterator range - instead of a sequence. You use them in the same way as the sequence - variants: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 6 - - \section2 Blocking Variants - - Each of the above functions has a blocking variant that returns - the final result instead of a QFuture. You use them in the same - way as the asynchronous variants. - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 7 - - Note that the result types above are not QFuture objects, but real result - types (in this case, QList<QImage> and QImage). - - \section2 Using Member Functions - - QtConcurrent::map(), QtConcurrent::mapped(), and - QtConcurrent::mappedReduced() accept pointers to member functions. - The member function class type must match the type stored in the sequence: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 8 - - Note that when using QtConcurrent::mappedReduced(), you can mix the use of - normal and member functions freely: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 9 - - \section2 Using Function Objects - - QtConcurrent::map(), QtConcurrent::mapped(), and - QtConcurrent::mappedReduced() accept function objects, which can be used to - add state to a function call. The result_type typedef must define the - result type of the function call operator: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 14 - - \section2 Using Bound Function Arguments - - Note that Qt does not provide support for bound functions. This is - provided by 3rd party libraries like - \l{http://www.boost.org/libs/bind/bind.html}{Boost} or - \l{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf}{C++ - TR1 Library Extensions}. - - If you want to use a map function that takes more than one argument you can - use boost::bind() or std::tr1::bind() to transform it onto a function that - takes one argument. - - As an example, we'll use QImage::scaledToWidth(): - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 10 - - scaledToWidth takes three arguments (including the "this" pointer) and - can't be used with QtConcurrent::mapped() directly, because - QtConcurrent::mapped() expects a function that takes one argument. To use - QImage::scaledToWidth() with QtConcurrent::mapped() we have to provide a - value for the \e{width} and the \e{transformation mode}: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 11 - - The return value from boost::bind() is a function object (functor) with - the following signature: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 12 - - This matches what QtConcurrent::mapped() expects, and the complete example - becomes: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentmap.cpp 13 -*/ - -/*! - \fn QFuture<void> QtConcurrent::map(Sequence &sequence, MapFunction function) - \relates <QtConcurrentMap> - - 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 - will appear in \a sequence. -*/ - -/*! - \fn QFuture<void> QtConcurrent::map(Iterator begin, Iterator end, MapFunction function) - \relates <QtConcurrentMap> - - 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 - done to the item will appear in the sequence which the iterators belong to. -*/ - -/*! - \fn QFuture<T> QtConcurrent::mapped(const Sequence &sequence, MapFunction function) - \relates <QtConcurrentMap> - - Calls \a function once for each item in \a sequence and returns a future - with each mapped item as a result. You can use QFuture::const_iterator or - QFutureIterator to iterate through the results. -*/ - -/*! - \fn QFuture<T> QtConcurrent::mapped(ConstIterator begin, ConstIterator end, MapFunction function) - \relates <QtConcurrentMap> - - Calls \a function once for each item from \a begin to \a end and returns a - future with each mapped item as a result. You can use - QFuture::const_iterator or QFutureIterator to iterate through the results. -*/ - -/*! - \fn QFuture<T> QtConcurrent::mappedReduced(const Sequence &sequence, - MapFunction mapFunction, ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions) - - \relates <QtConcurrentMap> - - Calls \a mapFunction once for each item in \a sequence. 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. -*/ - -/*! - \fn QFuture<T> QtConcurrent::mappedReduced(ConstIterator begin, - ConstIterator end, MapFunction mapFunction, ReduceFunction reduceFunction, - QtConcurrent::ReduceOptions reduceOptions) - - \relates <QtConcurrentMap> - - Calls \a mapFunction once for each item from \a begin to \a end. 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. -*/ - -/*! - \fn void QtConcurrent::blockingMap(Sequence &sequence, MapFunction 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 - will appear in \a sequence. - - \note This function will block until all items in the sequence have been processed. - - \sa map() -*/ - -/*! - \fn void QtConcurrent::blockingMap(Iterator begin, Iterator end, MapFunction 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 - 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() -*/ - -/*! - \fn T QtConcurrent::blockingMapped(const Sequence &sequence, MapFunction function) - - Calls \a function once for each item in \a sequence and returns a Sequence containing - the results. The type of the results will match the type returned my the MapFunction. - - \note This function will block until all items in the sequence have been processed. - - \sa mapped() -*/ - -/*! - \fn T QtConcurrent::blockingMapped(ConstIterator begin, ConstIterator end, MapFunction 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 - 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() -*/ - -/*! - \fn T QtConcurrent::blockingMappedReduced(const Sequence &sequence, MapFunction mapFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) - - \relates <QtConcurrentMap> - - Calls \a mapFunction once for each item in \a sequence. 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() -*/ - -/*! - \fn T QtConcurrent::blockingMappedReduced(ConstIterator begin, ConstIterator end, MapFunction mapFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions) - - \relates <QtConcurrentMap> - - Calls \a mapFunction once for each item from \a begin to \a end. 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() -*/ diff --git a/src/corelib/concurrent/qtconcurrentmap.h b/src/corelib/concurrent/qtconcurrentmap.h deleted file mode 100644 index ef66cc1a1a..0000000000 --- a/src/corelib/concurrent/qtconcurrentmap.h +++ /dev/null @@ -1,319 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_MAP_H -#define QTCONCURRENT_MAP_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qtconcurrentmapkernel.h> -#include <QtCore/qtconcurrentreducekernel.h> -#include <QtCore/qtconcurrentfunctionwrappers.h> -#include <QtCore/qstringlist.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifdef qdoc - -namespace QtConcurrent { - - QFuture<void> map(Sequence &sequence, MapFunction function); - QFuture<void> map(Iterator begin, Iterator end, MapFunction function); - - template <typename T> - QFuture<T> mapped(const Sequence &sequence, MapFunction function); - template <typename T> - QFuture<T> mapped(ConstIterator begin, ConstIterator end, MapFunction function); - - template <typename T> - QFuture<T> mappedReduced(const Sequence &sequence, - MapFunction function, - ReduceFunction function, - QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); - template <typename T> - QFuture<T> mappedReduced(ConstIterator begin, - ConstIterator end, - MapFunction function, - ReduceFunction function, - QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); - - void blockingMap(Sequence &sequence, MapFunction function); - void blockingMap(Iterator begin, Iterator end, MapFunction function); - - template <typename T> - T blockingMapped(const Sequence &sequence, MapFunction function); - template <typename T> - T blockingMapped(ConstIterator begin, ConstIterator end, MapFunction function); - - template <typename T> - T blockingMappedReduced(const Sequence &sequence, - MapFunction function, - ReduceFunction function, - QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); - template <typename T> - T blockingMappedReduced(ConstIterator begin, - ConstIterator end, - MapFunction function, - ReduceFunction function, - QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce); - -} // namespace QtConcurrent - -#else - -namespace QtConcurrent { - -// map() on sequences -template <typename Sequence, typename MapFunctor> -QFuture<void> map(Sequence &sequence, MapFunctor map) -{ - return startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map)); -} - -// map() on iterators -template <typename Iterator, typename MapFunctor> -QFuture<void> map(Iterator begin, Iterator end, MapFunctor map) -{ - return startMap(begin, end, QtPrivate::createFunctionWrapper(map)); -} - -// mappedReduced() for sequences. -template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> -QFuture<ResultType> mappedReduced(const Sequence &sequence, - MapFunctor map, - ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> - (sequence, - QtPrivate::createFunctionWrapper(map), - QtPrivate::createFunctionWrapper(reduce), - options); -} - -template <typename Sequence, typename MapFunctor, typename ReduceFunctor> -QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(const Sequence &sequence, - MapFunctor map, - ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> - (sequence, - QtPrivate::createFunctionWrapper(map), - QtPrivate::createFunctionWrapper(reduce), - options); -} - -// mappedReduced() for iterators -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)) -{ - return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> - (begin, end, - QtPrivate::createFunctionWrapper(map), - QtPrivate::createFunctionWrapper(reduce), - options); -} - -template <typename Iterator, typename MapFunctor, typename ReduceFunctor> -QFuture<typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> mappedReduced(Iterator begin, - Iterator end, - MapFunctor map, - ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> - (begin, end, - QtPrivate::createFunctionWrapper(map), - QtPrivate::createFunctionWrapper(reduce), - options); -} - -// mapped() for sequences -template <typename Sequence, typename MapFunctor> -QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped(const Sequence &sequence, MapFunctor map) -{ - return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(sequence, QtPrivate::createFunctionWrapper(map)); -} - -// mapped() for iterator ranges. -template <typename Iterator, typename MapFunctor> -QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped(Iterator begin, Iterator end, MapFunctor map) -{ - return startMapped<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType>(begin, end, QtPrivate::createFunctionWrapper(map)); -} - -// blockingMap() for sequences -template <typename Sequence, typename MapFunctor> -void blockingMap(Sequence &sequence, MapFunctor map) -{ - startMap(sequence.begin(), sequence.end(), QtPrivate::createFunctionWrapper(map)).startBlocking(); -} - -// blockingMap() for iterator ranges -template <typename Iterator, typename MapFunctor> -void blockingMap(Iterator begin, Iterator end, MapFunctor map) -{ - startMap(begin, end, QtPrivate::createFunctionWrapper(map)).startBlocking(); -} - -// blockingMappedReduced() for sequences -template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> -ResultType blockingMappedReduced(const Sequence &sequence, - MapFunctor map, - ReduceFunctor reduce, - ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> - (sequence, - QtPrivate::createFunctionWrapper(map), - QtPrivate::createFunctionWrapper(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<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> - (sequence, - QtPrivate::createFunctionWrapper(map), - QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); -} - -// blockingMappedReduced() for iterator ranges -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)) -{ - return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, ResultType> - (begin, end, - QtPrivate::createFunctionWrapper(map), - QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); -} - -template <typename Iterator, typename MapFunctor, typename ReduceFunctor> -typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType blockingMappedReduced(Iterator begin, - Iterator end, - MapFunctor map, - ReduceFunctor reduce, - QtConcurrent::ReduceOptions options = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce)) -{ - return QtConcurrent::startMappedReduced<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType, typename QtPrivate::ReduceResultType<ReduceFunctor>::ResultType> - (begin, end, - QtPrivate::createFunctionWrapper(map), - QtPrivate::createFunctionWrapper(reduce), - options) - .startBlocking(); -} - -// mapped() for sequences with a different putput sequence type. -template <typename OutputSequence, typename InputSequence, typename MapFunctor> -OutputSequence blockingMapped(const InputSequence &sequence, MapFunctor map) -{ - return blockingMappedReduced<OutputSequence> - (sequence, - QtPrivate::createFunctionWrapper(map), - QtPrivate::PushBackWrapper(), - QtConcurrent::OrderedReduce); -} - -template <typename MapFunctor, typename InputSequence> -typename QtPrivate::MapResultType<InputSequence, MapFunctor>::ResultType blockingMapped(const InputSequence &sequence, MapFunctor map) -{ - typedef typename QtPrivate::MapResultType<InputSequence, MapFunctor>::ResultType OutputSequence; - return blockingMappedReduced<OutputSequence> - (sequence, - QtPrivate::createFunctionWrapper(map), - QtPrivate::PushBackWrapper(), - QtConcurrent::OrderedReduce); -} - -// mapped() for iterator ranges -template <typename Sequence, typename Iterator, typename MapFunctor> -Sequence blockingMapped(Iterator begin, Iterator end, MapFunctor map) -{ - return blockingMappedReduced<Sequence> - (begin, end, - QtPrivate::createFunctionWrapper(map), - QtPrivate::PushBackWrapper(), - QtConcurrent::OrderedReduce); -} - -template <typename Iterator, typename MapFunctor> -typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType blockingMapped(Iterator begin, Iterator end, MapFunctor map) -{ - typedef typename QtPrivate::MapResultType<Iterator, MapFunctor>::ResultType OutputSequence; - return blockingMappedReduced<OutputSequence> - (begin, end, - QtPrivate::createFunctionWrapper(map), - QtPrivate::PushBackWrapper(), - QtConcurrent::OrderedReduce); -} - -} // namespace QtConcurrent - -#endif // qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentmapkernel.h b/src/corelib/concurrent/qtconcurrentmapkernel.h deleted file mode 100644 index 47cf143fff..0000000000 --- a/src/corelib/concurrent/qtconcurrentmapkernel.h +++ /dev/null @@ -1,272 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_MAPKERNEL_H -#define QTCONCURRENT_MAPKERNEL_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qtconcurrentiteratekernel.h> -#include <QtCore/qtconcurrentreducekernel.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifndef qdoc -namespace QtConcurrent { - -// map kernel, works with both parallel-for and parallel-while -template <typename Iterator, typename MapFunctor> -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) - { } - - bool runIteration(Iterator it, int, void *) - { - map(*it); - return false; - } - - bool runIterations(Iterator sequenceBeginIterator, int beginIndex, int endIndex, void *) - { - Iterator it = sequenceBeginIterator; - advance(it, beginIndex); - for (int i = beginIndex; i < endIndex; ++i) { - runIteration(it, i, 0); - advance(it, 1); - } - - return false; - } -}; - -template <typename ReducedResultType, - typename Iterator, - typename MapFunctor, - typename ReduceFunctor, - typename Reducer = ReduceKernel<ReduceFunctor, - ReducedResultType, - typename MapFunctor::result_type> > -class MappedReducedKernel : public IterateKernel<Iterator, ReducedResultType> -{ - ReducedResultType reducedResult; - MapFunctor map; - ReduceFunctor reduce; - Reducer reducer; -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(ReducedResultType initialValue, - MapFunctor _map, - ReduceFunctor _reduce) - : reducedResult(initialValue), map(_map), reduce(_reduce) - { } - - bool runIteration(Iterator it, int index, ReducedResultType *) - { - IntermediateResults<typename MapFunctor::result_type> results; - results.begin = index; - results.end = index + 1; - - results.vector.append(map(*it)); - reducer.runReduce(reduce, reducedResult, results); - return false; - } - - bool runIterations(Iterator sequenceBeginIterator, int begin, int end, ReducedResultType *) - { - IntermediateResults<typename MapFunctor::result_type> results; - results.begin = begin; - results.end = end; - results.vector.reserve(end - begin); - - Iterator it = sequenceBeginIterator; - advance(it, begin); - for (int i = begin; i < end; ++i) { - results.vector.append(map(*(it))); - advance(it, 1); - } - - reducer.runReduce(reduce, reducedResult, results); - return false; - } - - void finish() - { - reducer.finish(reduce, reducedResult); - } - - bool shouldThrottleThread() - { - return IterateKernel<Iterator, ReducedResultType>::shouldThrottleThread() || reducer.shouldThrottle(); - } - - bool shouldStartThread() - { - return IterateKernel<Iterator, ReducedResultType>::shouldStartThread() && reducer.shouldStartThread(); - } - - typedef ReducedResultType ResultType; - ReducedResultType *result() - { - return &reducedResult; - } -}; - -template <typename Iterator, typename MapFunctor> -class MappedEachKernel : public IterateKernel<Iterator, typename MapFunctor::result_type> -{ - MapFunctor map; - typedef typename MapFunctor::result_type T; -public: - typedef T ReturnType; - typedef T ResultType; - - MappedEachKernel(Iterator begin, Iterator end, MapFunctor _map) - : IterateKernel<Iterator, T>(begin, end), map(_map) { } - - bool runIteration(Iterator it, int, T *result) - { - *result = map(*it); - return true; - } - - bool runIterations(Iterator sequenceBeginIterator, int begin, int end, T *results) - { - - Iterator it = sequenceBeginIterator; - advance(it, begin); - for (int i = begin; i < end; ++i) { - runIteration(it, i, results + (i - begin)); - advance(it, 1); - } - - return true; - } -}; - -template <typename Iterator, typename Functor> -inline ThreadEngineStarter<void> startMap(Iterator begin, Iterator end, Functor functor) -{ - return startThreadEngine(new MapKernel<Iterator, Functor>(begin, end, functor)); -} - -template <typename T, typename Iterator, typename Functor> -inline ThreadEngineStarter<T> startMapped(Iterator begin, Iterator end, Functor functor) -{ - return startThreadEngine(new MappedEachKernel<Iterator, Functor>(begin, end, functor)); -} - -/* - The SequnceHolder class is used to hold a reference to the - sequence we are working on. -*/ -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) - { } - - Sequence sequence; - - void finish() - { - Base::finish(); - // Clear the sequence to make sure all temporaries are destroyed - // before finished is signaled. - sequence = Sequence(); - } -}; - -template <typename T, typename Sequence, typename Functor> -inline ThreadEngineStarter<T> startMapped(const Sequence &sequence, Functor functor) -{ - typedef SequenceHolder1<Sequence, - MappedEachKernel<typename Sequence::const_iterator , Functor>, Functor> - SequenceHolderType; - - return startThreadEngine(new SequenceHolderType(sequence, functor)); -} - -template <typename IntermediateType, typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor> -inline ThreadEngineStarter<ResultType> startMappedReduced(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)); -} - -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) -{ - typedef ReduceKernel<ReduceFunctor, ResultType, IntermediateType> Reducer; - typedef MappedReducedKernel<ResultType, Iterator, MapFunctor, ReduceFunctor, Reducer> MappedReduceType; - return startThreadEngine(new MappedReduceType(begin, end, mapFunctor, reduceFunctor, options)); -} - -} // namespace QtConcurrent - -#endif //qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentmedian.h b/src/corelib/concurrent/qtconcurrentmedian.h deleted file mode 100644 index 78fc3d97c8..0000000000 --- a/src/corelib/concurrent/qtconcurrentmedian.h +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_MEDIAN_H -#define QTCONCURRENT_MEDIAN_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qvector.h> -#include <QtCore/qalgorithms.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifndef qdoc - -namespace QtConcurrent { - -template <typename T> -class Median -{ -public: - Median(int _bufferSize) - : currentMedian(), bufferSize(_bufferSize), currentIndex(0), valid(false), dirty(true) - { - values.resize(bufferSize); - } - - void reset() - { - values.fill(0); - currentIndex = 0; - valid = false; - dirty = true; - } - - void addValue(T value) - { - currentIndex = ((currentIndex + 1) % bufferSize); - if (valid == false && currentIndex % bufferSize == 0) - valid = true; - - // Only update the cached median value when we have to, that - // is when the new value is on then other side of the median - // compared to the current value at the index. - const T currentIndexValue = values[currentIndex]; - if ((currentIndexValue > currentMedian && currentMedian > value) - || (currentMedian > currentIndexValue && value > currentMedian)) { - dirty = true; - } - - values[currentIndex] = value; - } - - bool isMedianValid() const - { - return valid; - } - - T median() - { - if (dirty) { - dirty = false; - QVector<T> sorted = values; - qSort(sorted); - currentMedian = sorted.at(bufferSize / 2 + 1); - } - return currentMedian; - } -private: - QVector<T> values; - T currentMedian; - int bufferSize; - int currentIndex; - bool valid; - bool dirty; -}; - -} // namespace QtConcurrent - -#endif //qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentreducekernel.h b/src/corelib/concurrent/qtconcurrentreducekernel.h deleted file mode 100644 index ddf56298ad..0000000000 --- a/src/corelib/concurrent/qtconcurrentreducekernel.h +++ /dev/null @@ -1,254 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_REDUCEKERNEL_H -#define QTCONCURRENT_REDUCEKERNEL_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qatomic.h> -#include <QtCore/qlist.h> -#include <QtCore/qmap.h> -#include <QtCore/qmutex.h> -#include <QtCore/qthread.h> -#include <QtCore/qthreadpool.h> -#include <QtCore/qvector.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -namespace QtConcurrent { - -#ifndef qdoc - -/* - The ReduceQueueStartLimit and ReduceQueueThrottleLimit constants - limit the reduce queue size for MapReduce. When the number of - reduce blocks in the queue exceeds ReduceQueueStartLimit, - MapReduce won't start any new threads, and when it exceeds - ReduceQueueThrottleLimit running threads will be stopped. -*/ -enum { - ReduceQueueStartLimit = 20, - ReduceQueueThrottleLimit = 30 -}; - -// IntermediateResults holds a block of intermediate results from a -// map or filter functor. The begin/end offsets indicates the origin -// and range of the block. -template <typename T> -class IntermediateResults -{ -public: - int begin, end; - QVector<T> vector; -}; - -#endif // qdoc - -enum ReduceOption { - UnorderedReduce = 0x1, - OrderedReduce = 0x2, - SequentialReduce = 0x4 - // ParallelReduce = 0x8 -}; -Q_DECLARE_FLAGS(ReduceOptions, ReduceOption) -Q_DECLARE_OPERATORS_FOR_FLAGS(ReduceOptions) - -#ifndef qdoc - -// supports both ordered and out-of-order reduction -template <typename ReduceFunctor, typename ReduceResultType, typename T> -class ReduceKernel -{ - typedef QMap<int, IntermediateResults<T> > ResultsMap; - - const ReduceOptions reduceOptions; - - QMutex mutex; - int progress, resultsMapSize, threadCount; - ResultsMap resultsMap; - - bool canReduce(int begin) const - { - return (((reduceOptions & UnorderedReduce) - && progress == 0) - || ((reduceOptions & OrderedReduce) - && progress == begin)); - } - - void reduceResult(ReduceFunctor &reduce, - ReduceResultType &r, - const IntermediateResults<T> &result) - { - for (int i = 0; i < result.vector.size(); ++i) { - reduce(r, result.vector.at(i)); - } - } - - void reduceResults(ReduceFunctor &reduce, - ReduceResultType &r, - ResultsMap &map) - { - typename ResultsMap::iterator it = map.begin(); - while (it != map.end()) { - reduceResult(reduce, r, it.value()); - ++it; - } - } - -public: - ReduceKernel(ReduceOptions _reduceOptions) - : reduceOptions(_reduceOptions), progress(0), resultsMapSize(0), - threadCount(QThreadPool::globalInstance()->maxThreadCount()) - { } - - void runReduce(ReduceFunctor &reduce, - ReduceResultType &r, - const IntermediateResults<T> &result) - { - QMutexLocker locker(&mutex); - if (!canReduce(result.begin)) { - ++resultsMapSize; - resultsMap.insert(result.begin, result); - return; - } - - if (reduceOptions & UnorderedReduce) { - // UnorderedReduce - progress = -1; - - // reduce this result - locker.unlock(); - reduceResult(reduce, r, result); - locker.relock(); - - // reduce all stored results as well - while (!resultsMap.isEmpty()) { - ResultsMap resultsMapCopy = resultsMap; - resultsMap.clear(); - - locker.unlock(); - reduceResults(reduce, r, resultsMapCopy); - locker.relock(); - - resultsMapSize -= resultsMapCopy.size(); - } - - progress = 0; - } else { - // reduce this result - locker.unlock(); - reduceResult(reduce, r, result); - locker.relock(); - - // OrderedReduce - progress += result.end - result.begin; - - // reduce as many other results as possible - typename ResultsMap::iterator it = resultsMap.begin(); - while (it != resultsMap.end()) { - if (it.value().begin != progress) - break; - - locker.unlock(); - reduceResult(reduce, r, it.value()); - locker.relock(); - - --resultsMapSize; - progress += it.value().end - it.value().begin; - it = resultsMap.erase(it); - } - } - } - - // final reduction - void finish(ReduceFunctor &reduce, ReduceResultType &r) - { - reduceResults(reduce, r, resultsMap); - } - - inline bool shouldThrottle() - { - return (resultsMapSize > (ReduceQueueThrottleLimit * threadCount)); - } - - inline bool shouldStartThread() - { - return (resultsMapSize <= (ReduceQueueStartLimit * threadCount)); - } -}; - -template <typename Sequence, typename Base, typename Functor1, typename Functor2> -struct SequenceHolder2 : public Base -{ - SequenceHolder2(const Sequence &_sequence, - Functor1 functor1, - Functor2 functor2, - ReduceOptions reduceOptions) - : Base(_sequence.begin(), _sequence.end(), functor1, functor2, reduceOptions), - sequence(_sequence) - { } - - Sequence sequence; - - void finish() - { - Base::finish(); - // Clear the sequence to make sure all temporaries are destroyed - // before finished is signaled. - sequence = Sequence(); - } -}; - -#endif //qdoc - -} // namespace QtConcurrent - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentresultstore.cpp b/src/corelib/concurrent/qtconcurrentresultstore.cpp deleted file mode 100644 index 64de8649ce..0000000000 --- a/src/corelib/concurrent/qtconcurrentresultstore.cpp +++ /dev/null @@ -1,256 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtconcurrentresultstore.h" - -#ifndef QT_NO_QFUTURE - -QT_BEGIN_NAMESPACE - -namespace QtConcurrent { - -ResultIteratorBase::ResultIteratorBase() - : mapIterator(QMap<int, ResultItem>::const_iterator()), m_vectorIndex(0) { } -ResultIteratorBase::ResultIteratorBase(QMap<int, ResultItem>::const_iterator _mapIterator, int _vectorIndex) - : mapIterator(_mapIterator), m_vectorIndex(_vectorIndex) { } - -int ResultIteratorBase::vectorIndex() const { return m_vectorIndex; } -int ResultIteratorBase::resultIndex() const { return mapIterator.key() + m_vectorIndex; } - -ResultIteratorBase ResultIteratorBase::operator++() -{ - if (canIncrementVectorIndex()) { - ++m_vectorIndex; - } else { - ++mapIterator; - m_vectorIndex = 0; - } - return *this; -} - -int ResultIteratorBase::batchSize() const -{ - return mapIterator.value().count(); -} - -void ResultIteratorBase::batchedAdvance() -{ - ++mapIterator; - m_vectorIndex = 0; -} - -bool ResultIteratorBase::operator==(const ResultIteratorBase &other) const -{ - return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex); -} - -bool ResultIteratorBase::operator!=(const ResultIteratorBase &other) const -{ - return !operator==(other); -} - -bool ResultIteratorBase::isVector() const -{ - return mapIterator.value().isVector(); -} - -bool ResultIteratorBase::canIncrementVectorIndex() const -{ - return (m_vectorIndex + 1 < mapIterator.value().m_count); -} - -ResultStoreBase::ResultStoreBase() - : insertIndex(0), resultCount(0), m_filterMode(false), filteredResults(0) { } - -void ResultStoreBase::setFilterMode(bool enable) -{ - m_filterMode = enable; -} - -bool ResultStoreBase::filterMode() const -{ - return m_filterMode; -} - -void ResultStoreBase::syncResultCount() -{ - ResultIteratorBase it = resultAt(resultCount); - while (it != end()) { - resultCount += it.batchSize(); - it = resultAt(resultCount); - } -} - -void ResultStoreBase::insertResultItemIfValid(int index, ResultItem &resultItem) -{ - if (resultItem.isValid()) { - m_results[index] = resultItem; - syncResultCount(); - } else { - filteredResults += resultItem.count(); - } -} - -int ResultStoreBase::insertResultItem(int index, ResultItem &resultItem) -{ - int storeIndex; - if (m_filterMode && index != -1 && index > insertIndex) { - pendingResults[index] = resultItem; - storeIndex = index; - } else { - storeIndex = updateInsertIndex(index, resultItem.count()); - insertResultItemIfValid(storeIndex - filteredResults, resultItem); - } - syncPendingResults(); - return storeIndex; -} - -void ResultStoreBase::syncPendingResults() -{ - // check if we can insert any of the pending results: - QMap<int, ResultItem>::iterator it = pendingResults.begin(); - while (it != pendingResults.end()) { - int index = it.key(); - if (index != resultCount + filteredResults) - break; - - ResultItem result = it.value(); - insertResultItemIfValid(index - filteredResults, result); - pendingResults.erase(it); - it = pendingResults.begin(); - } -} - -int ResultStoreBase::addResult(int index, const void *result) -{ - ResultItem resultItem(result, 0); // 0 means "not a vector" - return insertResultItem(index, resultItem); -} - -int ResultStoreBase::addResults(int index, const void *results, int vectorSize, int totalCount) -{ - if (m_filterMode == false || vectorSize == totalCount) { - ResultItem resultItem(results, vectorSize); - return insertResultItem(index, resultItem); - } else { - if (vectorSize > 0) { - ResultItem filteredIn(results, vectorSize); - insertResultItem(index, filteredIn); - } - ResultItem filteredAway(0, totalCount - vectorSize); - return insertResultItem(index + vectorSize, filteredAway); - } -} - -ResultIteratorBase ResultStoreBase::begin() const -{ - return ResultIteratorBase(m_results.begin()); -} - -ResultIteratorBase ResultStoreBase::end() const -{ - return ResultIteratorBase(m_results.end()); -} - -bool ResultStoreBase::hasNextResult() const -{ - return begin() != end(); -} - -ResultIteratorBase ResultStoreBase::resultAt(int index) const -{ - if (m_results.isEmpty()) - return ResultIteratorBase(m_results.end()); - QMap<int, ResultItem>::const_iterator it = m_results.lowerBound(index); - - // lowerBound returns either an iterator to the result or an iterator - // to the nearest greater index. If the latter happens it might be - // that the result is stored in a vector at the previous index. - if (it == m_results.end()) { - --it; - if (it.value().isVector() == false) { - return ResultIteratorBase(m_results.end()); - } - } else { - if (it.key() > index) { - if (it == m_results.begin()) - return ResultIteratorBase(m_results.end()); - --it; - } - } - - const int vectorIndex = index - it.key(); - - if (vectorIndex >= it.value().count()) - return ResultIteratorBase(m_results.end()); - else if (it.value().isVector() == false && vectorIndex != 0) - return ResultIteratorBase(m_results.end()); - return ResultIteratorBase(it, vectorIndex); -} - -bool ResultStoreBase::contains(int index) const -{ - return (resultAt(index) != end()); -} - -int ResultStoreBase::count() const -{ - return resultCount; -} - -// returns the insert index, calling this function with -// index equal to -1 returns the next available index. -int ResultStoreBase::updateInsertIndex(int index, int _count) -{ - if (index == -1) { - index = insertIndex; - insertIndex += _count; - } else { - insertIndex = qMax(index + _count, insertIndex); - } - return index; -} - -} // namespace QtConcurrent - -QT_END_NAMESPACE - -#endif // QT_NO_CONCURRENT diff --git a/src/corelib/concurrent/qtconcurrentresultstore.h b/src/corelib/concurrent/qtconcurrentresultstore.h deleted file mode 100644 index d39a45bba3..0000000000 --- a/src/corelib/concurrent/qtconcurrentresultstore.h +++ /dev/null @@ -1,238 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_RESULTSTORE_H -#define QTCONCURRENT_RESULTSTORE_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_QFUTURE - -#include <QtCore/qmap.h> -#include <QtCore/qdebug.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -/* - ResultStore stores indexed results. Results can be added and retrieved - either individually batched in a QVector. Retriveing results and checking - which indexes are in the store can be done either by iterating or by random - accees. In addition results kan be removed from the front of the store, - either individually or in batches. -*/ - -#ifndef qdoc - -namespace QtConcurrent { - -class ResultItem -{ -public: - ResultItem(const void *_result, int _count) : m_count(_count), result(_result) { } // contruct with vector of results - ResultItem(const void *_result) : m_count(0), result(_result) { } // construct with result - ResultItem() : m_count(0), result(0) { } - bool isValid() const { return result != 0; } - bool isVector() const { return m_count != 0; } - int count() const { return (m_count == 0) ? 1 : m_count; } - int m_count; // result is either a pointer to a result or to a vector of results, - const void *result; // if count is 0 it's a result, otherwise it's a vector. -}; - -class Q_CORE_EXPORT ResultIteratorBase -{ -public: - ResultIteratorBase(); - ResultIteratorBase(QMap<int, ResultItem>::const_iterator _mapIterator, int _vectorIndex = 0); - int vectorIndex() const; - int resultIndex() const; - - ResultIteratorBase operator++(); - int batchSize() const; - void batchedAdvance(); - bool operator==(const ResultIteratorBase &other) const; - bool operator!=(const ResultIteratorBase &other) const; - bool isVector() const; - bool canIncrementVectorIndex() const; -protected: - QMap<int, ResultItem>::const_iterator mapIterator; - int m_vectorIndex; -}; - -template <typename T> -class ResultIterator : public ResultIteratorBase -{ -public: - ResultIterator(const ResultIteratorBase &base) - : ResultIteratorBase(base) { } - - const T &value() const - { - return *pointer(); - } - - const T *pointer() const - { - if (mapIterator.value().isVector()) - return &(reinterpret_cast<const QVector<T> *>(mapIterator.value().result)->at(m_vectorIndex)); - else - return reinterpret_cast<const T *>(mapIterator.value().result); - } -}; - -class Q_CORE_EXPORT ResultStoreBase -{ -public: - ResultStoreBase(); - void setFilterMode(bool enable); - bool filterMode() const; - int addResult(int index, const void *result); - int addResults(int index, const void *results, int vectorSize, int logicalCount); - ResultIteratorBase begin() const; - ResultIteratorBase end() const; - bool hasNextResult() const; - ResultIteratorBase resultAt(int index) const; - bool contains(int index) const; - int count() const; - virtual ~ResultStoreBase() { } - -protected: - int insertResultItem(int index, ResultItem &resultItem); - void insertResultItemIfValid(int index, ResultItem &resultItem); - void syncPendingResults(); - void syncResultCount(); - int updateInsertIndex(int index, int _count); - - QMap<int, ResultItem> m_results; - int insertIndex; // The index where the next results(s) will be inserted. - int resultCount; // The number of consecutive results stored, starting at index 0. - - bool m_filterMode; - QMap<int, ResultItem> pendingResults; - int filteredResults; - -}; - -template <typename T> -class ResultStore : public ResultStoreBase -{ -public: - ResultStore() { } - - ResultStore(const ResultStoreBase &base) - : ResultStoreBase(base) { } - - int addResult(int index, const T *result) - { - if (result == 0) - return ResultStoreBase::addResult(index, result); - else - return ResultStoreBase::addResult(index, new T(*result)); - } - - int addResults(int index, const QVector<T> *results) - { - return ResultStoreBase::addResults(index, new QVector<T>(*results), results->count(), results->count()); - } - - int addResults(int index, const QVector<T> *results, int totalCount) - { - return ResultStoreBase::addResults(index, new QVector<T>(*results), results->count(), totalCount); - } - - int addCanceledResult(int index) - { - return addResult(index, 0); - } - - int addCanceledResults(int index, int _count) - { - QVector<T> empty; - return addResults(index, &empty, _count); - } - - ResultIterator<T> begin() const - { - return static_cast<ResultIterator<T> >(ResultStoreBase::begin()); - } - - ResultIterator<T> end() const - { - return static_cast<ResultIterator<T> >(ResultStoreBase::end()); - } - - ResultIterator<T> resultAt(int index) const - { - return static_cast<ResultIterator<T> >(ResultStoreBase::resultAt(index)); - } - - void clear() - { - QMap<int, ResultItem>::const_iterator mapIterator = m_results.constBegin(); - while (mapIterator != m_results.constEnd()) { - if (mapIterator.value().isVector()) - delete reinterpret_cast<const QVector<T> *>(mapIterator.value().result); - else - delete reinterpret_cast<const T *>(mapIterator.value().result); - ++mapIterator; - } - resultCount = 0; - m_results.clear(); - } - - ~ResultStore() - { - clear(); - } - -}; - -} // namespace QtConcurrent - -#endif //qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentrun.cpp b/src/corelib/concurrent/qtconcurrentrun.cpp deleted file mode 100644 index e51626ed13..0000000000 --- a/src/corelib/concurrent/qtconcurrentrun.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \headerfile <QtConcurrentRun> - \title Asynchronous Run - - \brief The <QtConcurrentRun> header provides a way to run a function in a - separate thread. - - \ingroup thread - - This function is a part of the \l {Concurrent Programming}{Qt Concurrent} framework. - - The QtConcurrent::run() function runs a function in a separate thread. - The return value of the function is made available through the QFuture API. - - \section1 Running a Function in a Separate Thread - - To run a function in another thread, use QtConcurrent::run(): - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 0 - - This will run \e aFunction in a separate thread obtained from the default - QThreadPool. You can use the QFuture and QFutureWatcher classes to monitor - the status of the function. - - \section1 Passing Arguments to the Function - - Passing arguments to the function is done by adding them to the - QtConcurrent::run() call immediately after the function name. For example: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 1 - - A copy of each argument is made at the point where QtConcurrent::run() is - called, and these values are passed to the thread when it begins executing - the function. Changes made to the arguments after calling - QtConcurrent::run() are \e not visible to the thread. - - \section1 Returning Values from the Function - - Any return value from the function is available via QFuture: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 2 - - As documented above, passing arguments is done like this: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 3 - - Note that the QFuture::result() function blocks and waits for the result - to become available. Use QFutureWatcher to get notification when the - function has finished execution and the result is available. - - \section1 Additional API Features - - \section2 Using Member Functions - - QtConcurrent::run() also accepts pointers to member functions. The first - argument must be either a const reference or a pointer to an instance of - the class. Passing by const reference is useful when calling const member - functions; passing by pointer is useful for calling non-const member - functions that modify the instance. - - For example, calling QByteArray::split() (a const member function) in a - separate thread is done like this: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 4 - - Calling a non-const member function is done like this: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 5 - - \section2 Using Bound Function Arguments - - Note that Qt does not provide support for bound functions. This is - provided by 3rd party libraries like - \l{http://www.boost.org/libs/bind/bind.html}{Boost} or - \l{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf} - {C++ TR1 Library Extensions}. - - You can use boost::bind() or std::tr1::bind() to \e bind a number of - arguments to a function when called. There are number of reasons for doing - this: - - \list - \o To call a function that takes more than 5 arguments. - \o To simplify calling a function with constant arguments. - \o Changing the order of arguments. - \endlist - - See the documentation for the relevant functions for details on how to use - the bind API. - - Calling a bound function is done like this: - - \snippet doc/src/snippets/code/src_corelib_concurrent_qtconcurrentrun.cpp 6 -*/ - -/*! - \fn QFuture<T> QtConcurrent::run(Function function, ...); - \relates <QtConcurrentRun> - - Runs \a function in a separate thread. The thread is taken from the global - QThreadPool. Note that the function may not run immediately; the function - will only be run when a thread is available. - - T is the same type as the return value of \a function. Non-void return - values can be accessed via the QFuture::result() function. - - Note that the QFuture returned by QtConcurrent::run() does not support - canceling, pausing, or progress reporting. The QFuture returned can only - be used to query for the running/finished status and the return value of - the function. -*/ diff --git a/src/corelib/concurrent/qtconcurrentrun.h b/src/corelib/concurrent/qtconcurrentrun.h deleted file mode 100644 index fc4bd01eaa..0000000000 --- a/src/corelib/concurrent/qtconcurrentrun.h +++ /dev/null @@ -1,347 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// Generated code, do not edit! Use generator at tools/qtconcurrent/generaterun/ -#ifndef QTCONCURRENT_RUN_H -#define QTCONCURRENT_RUN_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qtconcurrentrunbase.h> -#include <QtCore/qtconcurrentstoredfunctioncall.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifdef qdoc - -namespace QtConcurrent { - - template <typename T> - QFuture<T> run(Function function, ...); - -} // namespace QtConcurrent - -#else - -namespace QtConcurrent { - -template <typename T> -QFuture<T> run(T (*functionPointer)()) -{ - return (new StoredFunctorCall0<T, T (*)()>(functionPointer))->start(); -} -template <typename T, typename Param1, typename Arg1> -QFuture<T> run(T (*functionPointer)(Param1), const Arg1 &arg1) -{ - return (new StoredFunctorCall1<T, T (*)(Param1), Arg1>(functionPointer, arg1))->start(); -} -template <typename T, typename Param1, typename Arg1, typename Param2, typename Arg2> -QFuture<T> run(T (*functionPointer)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2) -{ - return (new StoredFunctorCall2<T, T (*)(Param1, Param2), Arg1, Arg2>(functionPointer, arg1, arg2))->start(); -} -template <typename T, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -QFuture<T> run(T (*functionPointer)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) -{ - return (new StoredFunctorCall3<T, T (*)(Param1, Param2, Param3), Arg1, Arg2, Arg3>(functionPointer, arg1, arg2, arg3))->start(); -} -template <typename T, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -QFuture<T> run(T (*functionPointer)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) -{ - return (new StoredFunctorCall4<T, T (*)(Param1, Param2, Param3, Param4), Arg1, Arg2, Arg3, Arg4>(functionPointer, arg1, arg2, arg3, arg4))->start(); -} -template <typename T, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -QFuture<T> run(T (*functionPointer)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) -{ - return (new StoredFunctorCall5<T, T (*)(Param1, Param2, Param3, Param4, Param5), Arg1, Arg2, Arg3, Arg4, Arg5>(functionPointer, arg1, arg2, arg3, arg4, arg5))->start(); -} - -#ifdef Q_COMPILER_DECLTYPE - -template <typename Functor> -auto run(Functor functor) -> typename QtPrivate::QEnableIf<!QtPrivate::HasResultType<Functor>::Value, QFuture<decltype(functor())> >::Type -{ - typedef decltype(functor()) result_type; - return (new StoredFunctorCall0<result_type, Functor>(functor))->start(); -} - -template <typename Functor, typename Arg1> -auto run(Functor functor, const Arg1 &arg1) - -> typename QtPrivate::QEnableIf<!QtPrivate::HasResultType<Functor>::Value, QFuture<decltype(functor(arg1))> >::Type -{ - typedef decltype(functor(arg1)) result_type; - return (new StoredFunctorCall1<result_type, Functor, Arg1>(functor, arg1))->start(); -} - -template <typename Functor, typename Arg1, typename Arg2> -auto run(Functor functor, const Arg1 &arg1, const Arg2 &arg2) - -> typename QtPrivate::QEnableIf<!QtPrivate::HasResultType<Functor>::Value, QFuture<decltype(functor(arg1, arg2))> >::Type -{ - typedef decltype(functor(arg1, arg2)) result_type; - return (new StoredFunctorCall2<result_type, Functor, Arg1, Arg2>(functor, arg1, arg2))->start(); -} - -template <typename Functor, typename Arg1, typename Arg2, typename Arg3> -auto run(Functor functor, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) - -> typename QtPrivate::QEnableIf<!QtPrivate::HasResultType<Functor>::Value, QFuture<decltype(functor(arg1, arg2, arg3))> >::Type -{ - typedef decltype(functor(arg1, arg2, arg3)) result_type; - return (new StoredFunctorCall3<result_type, Functor, Arg1, Arg2, Arg3>(functor, arg1, arg2, arg3))->start(); -} - -template <typename Functor, typename Arg1, typename Arg2, typename Arg3, typename Arg4> -auto run(Functor functor, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) - -> typename QtPrivate::QEnableIf<!QtPrivate::HasResultType<Functor>::Value, QFuture<decltype(functor(arg1, arg2, arg3, arg4))> >::Type -{ - typedef decltype(functor(arg1, arg2, arg3, arg4)) result_type; - return (new StoredFunctorCall4<result_type, Functor, Arg1, Arg2, Arg3, Arg4>(functor, arg1, arg2, arg3, arg4))->start(); -} - -template <typename Functor, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> -auto run(Functor functor, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) - -> typename QtPrivate::QEnableIf<!QtPrivate::HasResultType<Functor>::Value, QFuture<decltype(functor(arg1, arg2, arg3, arg4, arg5))> >::Type -{ - typedef decltype(functor(arg1, arg2, arg3, arg4, arg5)) result_type; - return (new StoredFunctorCall5<result_type, Functor, Arg1, Arg2, Arg3, Arg4, Arg5>(functor, arg1, arg2, arg3, arg4, arg5))->start(); -} - -#endif - -template <typename FunctionObject> -QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject) -{ - return (new StoredFunctorCall0<QT_TYPENAME FunctionObject::result_type, FunctionObject>(functionObject))->start(); -} -template <typename FunctionObject, typename Arg1> -QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1) -{ - return (new StoredFunctorCall1<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1>(functionObject, arg1))->start(); -} -template <typename FunctionObject, typename Arg1, typename Arg2> -QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2) -{ - return (new StoredFunctorCall2<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1, Arg2>(functionObject, arg1, arg2))->start(); -} -template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3> -QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) -{ - return (new StoredFunctorCall3<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1, Arg2, Arg3>(functionObject, arg1, arg2, arg3))->start(); -} -template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3, typename Arg4> -QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) -{ - return (new StoredFunctorCall4<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1, Arg2, Arg3, Arg4>(functionObject, arg1, arg2, arg3, arg4))->start(); -} -template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> -QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) -{ - return (new StoredFunctorCall5<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1, Arg2, Arg3, Arg4, Arg5>(functionObject, arg1, arg2, arg3, arg4, arg5))->start(); -} - -template <typename FunctionObject> -QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject) -{ - return (new QT_TYPENAME SelectStoredFunctorPointerCall0<QT_TYPENAME FunctionObject::result_type, FunctionObject>::type(functionObject))->start(); -} -template <typename FunctionObject, typename Arg1> -QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1) -{ - return (new QT_TYPENAME SelectStoredFunctorPointerCall1<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1>::type(functionObject, arg1))->start(); -} -template <typename FunctionObject, typename Arg1, typename Arg2> -QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2) -{ - return (new QT_TYPENAME SelectStoredFunctorPointerCall2<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1, Arg2>::type(functionObject, arg1, arg2))->start(); -} -template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3> -QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) -{ - return (new QT_TYPENAME SelectStoredFunctorPointerCall3<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1, Arg2, Arg3>::type(functionObject, arg1, arg2, arg3))->start(); -} -template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3, typename Arg4> -QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) -{ - return (new QT_TYPENAME SelectStoredFunctorPointerCall4<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1, Arg2, Arg3, Arg4>::type(functionObject, arg1, arg2, arg3, arg4))->start(); -} -template <typename FunctionObject, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> -QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) -{ - return (new QT_TYPENAME SelectStoredFunctorPointerCall5<QT_TYPENAME FunctionObject::result_type, FunctionObject, Arg1, Arg2, Arg3, Arg4, Arg5>::type(functionObject, arg1, arg2, arg3, arg4, arg5))->start(); -} - -template <typename T, typename Class> -QFuture<T> run(const Class &object, T (Class::*fn)()) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionCall0<T, Class>::type(fn, object))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1), const Arg1 &arg1) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionCall1<T, Class, Param1, Arg1>::type(fn, object, arg1))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionCall2<T, Class, Param1, Arg1, Param2, Arg2>::type(fn, object, arg1, arg2))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionCall3<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>::type(fn, object, arg1, arg2, arg3))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionCall4<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>::type(fn, object, arg1, arg2, arg3, arg4))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionCall5<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>::type(fn, object, arg1, arg2, arg3, arg4, arg5))->start(); -} - -template <typename T, typename Class> -QFuture<T> run(const Class &object, T (Class::*fn)() const) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionCall0<T, Class>::type(fn, object))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1) const, const Arg1 &arg1) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionCall1<T, Class, Param1, Arg1>::type(fn, object, arg1))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2) const, const Arg1 &arg1, const Arg2 &arg2) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionCall2<T, Class, Param1, Arg1, Param2, Arg2>::type(fn, object, arg1, arg2))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionCall3<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>::type(fn, object, arg1, arg2, arg3))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3, Param4) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionCall4<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>::type(fn, object, arg1, arg2, arg3, arg4))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3, Param4, Param5) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionCall5<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>::type(fn, object, arg1, arg2, arg3, arg4, arg5))->start(); -} - -template <typename T, typename Class> -QFuture<T> run(Class *object, T (Class::*fn)()) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionPointerCall0<T, Class>::type(fn, object))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1> -QFuture<T> run(Class *object, T (Class::*fn)(Param1), const Arg1 &arg1) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionPointerCall1<T, Class, Param1, Arg1>::type(fn, object, arg1))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionPointerCall2<T, Class, Param1, Arg1, Param2, Arg2>::type(fn, object, arg1, arg2))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionPointerCall3<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>::type(fn, object, arg1, arg2, arg3))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionPointerCall4<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>::type(fn, object, arg1, arg2, arg3, arg4))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) -{ - return (new QT_TYPENAME SelectStoredMemberFunctionPointerCall5<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>::type(fn, object, arg1, arg2, arg3, arg4, arg5))->start(); -} - -template <typename T, typename Class> -QFuture<T> run(const Class *object, T (Class::*fn)() const) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionPointerCall0<T, Class>::type(fn, object))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1> -QFuture<T> run(const Class *object, T (Class::*fn)(Param1) const, const Arg1 &arg1) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionPointerCall1<T, Class, Param1, Arg1>::type(fn, object, arg1))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -QFuture<T> run(const Class *object, T (Class::*fn)(Param1, Param2) const, const Arg1 &arg1, const Arg2 &arg2) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionPointerCall2<T, Class, Param1, Arg1, Param2, Arg2>::type(fn, object, arg1, arg2))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -QFuture<T> run(const Class *object, T (Class::*fn)(Param1, Param2, Param3) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionPointerCall3<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>::type(fn, object, arg1, arg2, arg3))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -QFuture<T> run(const Class *object, T (Class::*fn)(Param1, Param2, Param3, Param4) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionPointerCall4<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>::type(fn, object, arg1, arg2, arg3, arg4))->start(); -} -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -QFuture<T> run(const Class *object, T (Class::*fn)(Param1, Param2, Param3, Param4, Param5) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5) -{ - return (new QT_TYPENAME SelectStoredConstMemberFunctionPointerCall5<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>::type(fn, object, arg1, arg2, arg3, arg4, arg5))->start(); -} - -} //namespace QtConcurrent - -#endif // qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentrunbase.h b/src/corelib/concurrent/qtconcurrentrunbase.h deleted file mode 100644 index 99ca0a9699..0000000000 --- a/src/corelib/concurrent/qtconcurrentrunbase.h +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_RUNBASE_H -#define QTCONCURRENT_RUNBASE_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qfuture.h> -#include <QtCore/qrunnable.h> -#include <QtCore/qthreadpool.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifndef qdoc - -namespace QtConcurrent { - -template <typename T> -struct SelectSpecialization -{ - template <class Normal, class Void> - struct Type { typedef Normal type; }; -}; - -template <> -struct SelectSpecialization<void> -{ - template <class Normal, class Void> - struct Type { typedef Void type; }; -}; - -template <typename T> -class RunFunctionTaskBase : public QFutureInterface<T> , public QRunnable -{ -public: - QFuture<T> start() - { - this->setRunnable(this); - this->reportStarted(); - QFuture<T> theFuture = this->future(); - QThreadPool::globalInstance()->start(this, /*m_priority*/ 0); - return theFuture; - } - - void run() {} - virtual void runFunctor() = 0; -}; - -template <typename T> -class RunFunctionTask : public RunFunctionTaskBase<T> -{ -public: - void run() - { - if (this->isCanceled()) { - this->reportFinished(); - return; - } -#ifndef QT_NO_EXCEPTIONS - try { -#endif - this->runFunctor(); -#ifndef QT_NO_EXCEPTIONS - } catch (QtConcurrent::Exception &e) { - QFutureInterface<T>::reportException(e); - } catch (...) { - QFutureInterface<T>::reportException(QtConcurrent::UnhandledException()); - } -#endif - - this->reportResult(result); - this->reportFinished(); - } - T result; -}; - -template <> -class RunFunctionTask<void> : public RunFunctionTaskBase<void> -{ -public: - void run() - { - if (this->isCanceled()) { - this->reportFinished(); - return; - } -#ifndef QT_NO_EXCEPTIONS - try { -#endif - this->runFunctor(); -#ifndef QT_NO_EXCEPTIONS - } catch (QtConcurrent::Exception &e) { - QFutureInterface<void>::reportException(e); - } catch (...) { - QFutureInterface<void>::reportException(QtConcurrent::UnhandledException()); - } -#endif - this->reportFinished(); - } -}; - -} //namespace QtConcurrent - -#endif //qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentstoredfunctioncall.h b/src/corelib/concurrent/qtconcurrentstoredfunctioncall.h deleted file mode 100644 index cf426a4203..0000000000 --- a/src/corelib/concurrent/qtconcurrentstoredfunctioncall.h +++ /dev/null @@ -1,1312 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// Generated code, do not edit! Use generator at tools/qtconcurrent/generaterun/ -#ifndef QTCONCURRENT_STOREDFUNCTIONCALL_H -#define QTCONCURRENT_STOREDFUNCTIONCALL_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT -#include <QtCore/qtconcurrentrunbase.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifndef qdoc - -namespace QtConcurrent { -template <typename T, typename FunctionPointer> -struct StoredFunctorCall0: public RunFunctionTask<T> -{ - inline StoredFunctorCall0(FunctionPointer _function) - : function(_function) {} - void runFunctor() { this->result = function(); } - FunctionPointer function; - -}; - -template <typename FunctionPointer> -struct StoredFunctorCall0<void, FunctionPointer>: public RunFunctionTask<void> -{ - inline StoredFunctorCall0(FunctionPointer _function) - : function(_function) {} - void runFunctor() { function(); } - FunctionPointer function; - -}; - -template <typename T, typename FunctionPointer> -struct StoredFunctorPointerCall0: public RunFunctionTask<T> -{ - inline StoredFunctorPointerCall0(FunctionPointer * _function) - : function(_function) {} - void runFunctor() { this->result =(*function)(); } - FunctionPointer * function; - -}; - -template <typename T, typename FunctionPointer> -struct VoidStoredFunctorPointerCall0: public RunFunctionTask<T> -{ - inline VoidStoredFunctorPointerCall0(FunctionPointer * _function) - : function(_function) {} - void runFunctor() {(*function)(); } - FunctionPointer * function; - -}; - -template <typename T, typename FunctionPointer> -struct SelectStoredFunctorPointerCall0 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredFunctorPointerCall0 <T, FunctionPointer>, - VoidStoredFunctorPointerCall0<T, FunctionPointer> >::type type; -}; -template <typename T, typename Class> -class StoredMemberFunctionCall0 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionCall0(T (Class::*_fn)() , const Class &_object) - : fn(_fn), object(_object){ } - - void runFunctor() - { - this->result = (object.*fn)(); - } -private: - T (Class::*fn)(); - Class object; - -}; -template <typename T, typename Class> -class VoidStoredMemberFunctionCall0 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionCall0(T (Class::*_fn)() , const Class &_object) - : fn(_fn), object(_object){ } - - void runFunctor() - { - (object.*fn)(); - } -private: - T (Class::*fn)(); - Class object; - -}; -template <typename T, typename Class> -struct SelectStoredMemberFunctionCall0 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionCall0 <T, Class>, - VoidStoredMemberFunctionCall0<T, Class> >::type type; -}; -template <typename T, typename Class> -class StoredConstMemberFunctionCall0 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionCall0(T (Class::*_fn)() const, const Class &_object) - : fn(_fn), object(_object){ } - - void runFunctor() - { - this->result = (object.*fn)(); - } -private: - T (Class::*fn)()const; - const Class object; - -}; -template <typename T, typename Class> -class VoidStoredConstMemberFunctionCall0 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionCall0(T (Class::*_fn)() const, const Class &_object) - : fn(_fn), object(_object){ } - - void runFunctor() - { - (object.*fn)(); - } -private: - T (Class::*fn)()const; - const Class object; - -}; -template <typename T, typename Class> -struct SelectStoredConstMemberFunctionCall0 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionCall0 <T, Class>, - VoidStoredConstMemberFunctionCall0<T, Class> >::type type; -}; -template <typename T, typename Class> -class StoredMemberFunctionPointerCall0 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionPointerCall0(T (Class::*_fn)() , Class *_object) - : fn(_fn), object(_object){ } - - void runFunctor() - { - this->result = (object->*fn)(); - } -private: - T (Class::*fn)(); - Class *object; - -}; -template <typename T, typename Class> -class VoidStoredMemberFunctionPointerCall0 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionPointerCall0(T (Class::*_fn)() , Class *_object) - : fn(_fn), object(_object){ } - - void runFunctor() - { - (object->*fn)(); - } -private: - T (Class::*fn)(); - Class *object; - -}; -template <typename T, typename Class> -struct SelectStoredMemberFunctionPointerCall0 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionPointerCall0 <T, Class>, - VoidStoredMemberFunctionPointerCall0<T, Class> >::type type; -}; -template <typename T, typename Class> -class StoredConstMemberFunctionPointerCall0 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionPointerCall0(T (Class::*_fn)() const, Class const *_object) - : fn(_fn), object(_object){ } - - void runFunctor() - { - this->result = (object->*fn)(); - } -private: - T (Class::*fn)()const; - Class const *object; - -}; -template <typename T, typename Class> -class VoidStoredConstMemberFunctionPointerCall0 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionPointerCall0(T (Class::*_fn)() const, Class const *_object) - : fn(_fn), object(_object){ } - - void runFunctor() - { - (object->*fn)(); - } -private: - T (Class::*fn)()const; - Class const *object; - -}; -template <typename T, typename Class> -struct SelectStoredConstMemberFunctionPointerCall0 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionPointerCall0 <T, Class>, - VoidStoredConstMemberFunctionPointerCall0<T, Class> >::type type; -}; -template <typename T, typename FunctionPointer, typename Arg1> -struct StoredFunctorCall1: public RunFunctionTask<T> -{ - inline StoredFunctorCall1(FunctionPointer _function, const Arg1 &_arg1) - : function(_function), arg1(_arg1) {} - void runFunctor() { this->result = function(arg1); } - FunctionPointer function; - Arg1 arg1; -}; - -template <typename FunctionPointer, typename Arg1> -struct StoredFunctorCall1<void, FunctionPointer, Arg1>: public RunFunctionTask<void> -{ - inline StoredFunctorCall1(FunctionPointer _function, const Arg1 &_arg1) - : function(_function), arg1(_arg1) {} - void runFunctor() { function(arg1); } - FunctionPointer function; - Arg1 arg1; -}; - -template <typename T, typename FunctionPointer, typename Arg1> -struct StoredFunctorPointerCall1: public RunFunctionTask<T> -{ - inline StoredFunctorPointerCall1(FunctionPointer * _function, const Arg1 &_arg1) - : function(_function), arg1(_arg1) {} - void runFunctor() { this->result =(*function)(arg1); } - FunctionPointer * function; - Arg1 arg1; -}; - -template <typename T, typename FunctionPointer, typename Arg1> -struct VoidStoredFunctorPointerCall1: public RunFunctionTask<T> -{ - inline VoidStoredFunctorPointerCall1(FunctionPointer * _function, const Arg1 &_arg1) - : function(_function), arg1(_arg1) {} - void runFunctor() {(*function)(arg1); } - FunctionPointer * function; - Arg1 arg1; -}; - -template <typename T, typename FunctionPointer, typename Arg1> -struct SelectStoredFunctorPointerCall1 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredFunctorPointerCall1 <T, FunctionPointer, Arg1>, - VoidStoredFunctorPointerCall1<T, FunctionPointer, Arg1> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -class StoredMemberFunctionCall1 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionCall1(T (Class::*_fn)(Param1) , const Class &_object, const Arg1 &_arg1) - : fn(_fn), object(_object), arg1(_arg1){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1); - } -private: - T (Class::*fn)(Param1); - Class object; - Arg1 arg1; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -class VoidStoredMemberFunctionCall1 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionCall1(T (Class::*_fn)(Param1) , const Class &_object, const Arg1 &_arg1) - : fn(_fn), object(_object), arg1(_arg1){ } - - void runFunctor() - { - (object.*fn)(arg1); - } -private: - T (Class::*fn)(Param1); - Class object; - Arg1 arg1; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -struct SelectStoredMemberFunctionCall1 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionCall1 <T, Class, Param1, Arg1>, - VoidStoredMemberFunctionCall1<T, Class, Param1, Arg1> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -class StoredConstMemberFunctionCall1 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionCall1(T (Class::*_fn)(Param1) const, const Class &_object, const Arg1 &_arg1) - : fn(_fn), object(_object), arg1(_arg1){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1); - } -private: - T (Class::*fn)(Param1)const; - const Class object; - Arg1 arg1; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -class VoidStoredConstMemberFunctionCall1 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionCall1(T (Class::*_fn)(Param1) const, const Class &_object, const Arg1 &_arg1) - : fn(_fn), object(_object), arg1(_arg1){ } - - void runFunctor() - { - (object.*fn)(arg1); - } -private: - T (Class::*fn)(Param1)const; - const Class object; - Arg1 arg1; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -struct SelectStoredConstMemberFunctionCall1 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionCall1 <T, Class, Param1, Arg1>, - VoidStoredConstMemberFunctionCall1<T, Class, Param1, Arg1> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -class StoredMemberFunctionPointerCall1 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionPointerCall1(T (Class::*_fn)(Param1) , Class *_object, const Arg1 &_arg1) - : fn(_fn), object(_object), arg1(_arg1){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1); - } -private: - T (Class::*fn)(Param1); - Class *object; - Arg1 arg1; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -class VoidStoredMemberFunctionPointerCall1 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionPointerCall1(T (Class::*_fn)(Param1) , Class *_object, const Arg1 &_arg1) - : fn(_fn), object(_object), arg1(_arg1){ } - - void runFunctor() - { - (object->*fn)(arg1); - } -private: - T (Class::*fn)(Param1); - Class *object; - Arg1 arg1; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -struct SelectStoredMemberFunctionPointerCall1 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionPointerCall1 <T, Class, Param1, Arg1>, - VoidStoredMemberFunctionPointerCall1<T, Class, Param1, Arg1> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -class StoredConstMemberFunctionPointerCall1 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionPointerCall1(T (Class::*_fn)(Param1) const, Class const *_object, const Arg1 &_arg1) - : fn(_fn), object(_object), arg1(_arg1){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1); - } -private: - T (Class::*fn)(Param1)const; - Class const *object; - Arg1 arg1; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -class VoidStoredConstMemberFunctionPointerCall1 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionPointerCall1(T (Class::*_fn)(Param1) const, Class const *_object, const Arg1 &_arg1) - : fn(_fn), object(_object), arg1(_arg1){ } - - void runFunctor() - { - (object->*fn)(arg1); - } -private: - T (Class::*fn)(Param1)const; - Class const *object; - Arg1 arg1; -}; -template <typename T, typename Class, typename Param1, typename Arg1> -struct SelectStoredConstMemberFunctionPointerCall1 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionPointerCall1 <T, Class, Param1, Arg1>, - VoidStoredConstMemberFunctionPointerCall1<T, Class, Param1, Arg1> >::type type; -}; -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2> -struct StoredFunctorCall2: public RunFunctionTask<T> -{ - inline StoredFunctorCall2(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2) - : function(_function), arg1(_arg1), arg2(_arg2) {} - void runFunctor() { this->result = function(arg1, arg2); } - FunctionPointer function; - Arg1 arg1; Arg2 arg2; -}; - -template <typename FunctionPointer, typename Arg1, typename Arg2> -struct StoredFunctorCall2<void, FunctionPointer, Arg1, Arg2>: public RunFunctionTask<void> -{ - inline StoredFunctorCall2(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2) - : function(_function), arg1(_arg1), arg2(_arg2) {} - void runFunctor() { function(arg1, arg2); } - FunctionPointer function; - Arg1 arg1; Arg2 arg2; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2> -struct StoredFunctorPointerCall2: public RunFunctionTask<T> -{ - inline StoredFunctorPointerCall2(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2) - : function(_function), arg1(_arg1), arg2(_arg2) {} - void runFunctor() { this->result =(*function)(arg1, arg2); } - FunctionPointer * function; - Arg1 arg1; Arg2 arg2; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2> -struct VoidStoredFunctorPointerCall2: public RunFunctionTask<T> -{ - inline VoidStoredFunctorPointerCall2(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2) - : function(_function), arg1(_arg1), arg2(_arg2) {} - void runFunctor() {(*function)(arg1, arg2); } - FunctionPointer * function; - Arg1 arg1; Arg2 arg2; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2> -struct SelectStoredFunctorPointerCall2 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredFunctorPointerCall2 <T, FunctionPointer, Arg1, Arg2>, - VoidStoredFunctorPointerCall2<T, FunctionPointer, Arg1, Arg2> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -class StoredMemberFunctionCall2 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionCall2(T (Class::*_fn)(Param1, Param2) , const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1, arg2); - } -private: - T (Class::*fn)(Param1, Param2); - Class object; - Arg1 arg1; Arg2 arg2; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -class VoidStoredMemberFunctionCall2 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionCall2(T (Class::*_fn)(Param1, Param2) , const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2){ } - - void runFunctor() - { - (object.*fn)(arg1, arg2); - } -private: - T (Class::*fn)(Param1, Param2); - Class object; - Arg1 arg1; Arg2 arg2; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -struct SelectStoredMemberFunctionCall2 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionCall2 <T, Class, Param1, Arg1, Param2, Arg2>, - VoidStoredMemberFunctionCall2<T, Class, Param1, Arg1, Param2, Arg2> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -class StoredConstMemberFunctionCall2 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionCall2(T (Class::*_fn)(Param1, Param2) const, const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1, arg2); - } -private: - T (Class::*fn)(Param1, Param2)const; - const Class object; - Arg1 arg1; Arg2 arg2; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -class VoidStoredConstMemberFunctionCall2 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionCall2(T (Class::*_fn)(Param1, Param2) const, const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2){ } - - void runFunctor() - { - (object.*fn)(arg1, arg2); - } -private: - T (Class::*fn)(Param1, Param2)const; - const Class object; - Arg1 arg1; Arg2 arg2; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -struct SelectStoredConstMemberFunctionCall2 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionCall2 <T, Class, Param1, Arg1, Param2, Arg2>, - VoidStoredConstMemberFunctionCall2<T, Class, Param1, Arg1, Param2, Arg2> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -class StoredMemberFunctionPointerCall2 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionPointerCall2(T (Class::*_fn)(Param1, Param2) , Class *_object, const Arg1 &_arg1, const Arg2 &_arg2) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1, arg2); - } -private: - T (Class::*fn)(Param1, Param2); - Class *object; - Arg1 arg1; Arg2 arg2; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -class VoidStoredMemberFunctionPointerCall2 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionPointerCall2(T (Class::*_fn)(Param1, Param2) , Class *_object, const Arg1 &_arg1, const Arg2 &_arg2) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2){ } - - void runFunctor() - { - (object->*fn)(arg1, arg2); - } -private: - T (Class::*fn)(Param1, Param2); - Class *object; - Arg1 arg1; Arg2 arg2; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -struct SelectStoredMemberFunctionPointerCall2 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionPointerCall2 <T, Class, Param1, Arg1, Param2, Arg2>, - VoidStoredMemberFunctionPointerCall2<T, Class, Param1, Arg1, Param2, Arg2> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -class StoredConstMemberFunctionPointerCall2 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionPointerCall2(T (Class::*_fn)(Param1, Param2) const, Class const *_object, const Arg1 &_arg1, const Arg2 &_arg2) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1, arg2); - } -private: - T (Class::*fn)(Param1, Param2)const; - Class const *object; - Arg1 arg1; Arg2 arg2; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -class VoidStoredConstMemberFunctionPointerCall2 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionPointerCall2(T (Class::*_fn)(Param1, Param2) const, Class const *_object, const Arg1 &_arg1, const Arg2 &_arg2) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2){ } - - void runFunctor() - { - (object->*fn)(arg1, arg2); - } -private: - T (Class::*fn)(Param1, Param2)const; - Class const *object; - Arg1 arg1; Arg2 arg2; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2> -struct SelectStoredConstMemberFunctionPointerCall2 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionPointerCall2 <T, Class, Param1, Arg1, Param2, Arg2>, - VoidStoredConstMemberFunctionPointerCall2<T, Class, Param1, Arg1, Param2, Arg2> >::type type; -}; -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3> -struct StoredFunctorCall3: public RunFunctionTask<T> -{ - inline StoredFunctorCall3(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3) {} - void runFunctor() { this->result = function(arg1, arg2, arg3); } - FunctionPointer function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; - -template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3> -struct StoredFunctorCall3<void, FunctionPointer, Arg1, Arg2, Arg3>: public RunFunctionTask<void> -{ - inline StoredFunctorCall3(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3) {} - void runFunctor() { function(arg1, arg2, arg3); } - FunctionPointer function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3> -struct StoredFunctorPointerCall3: public RunFunctionTask<T> -{ - inline StoredFunctorPointerCall3(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3) {} - void runFunctor() { this->result =(*function)(arg1, arg2, arg3); } - FunctionPointer * function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3> -struct VoidStoredFunctorPointerCall3: public RunFunctionTask<T> -{ - inline VoidStoredFunctorPointerCall3(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3) {} - void runFunctor() {(*function)(arg1, arg2, arg3); } - FunctionPointer * function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3> -struct SelectStoredFunctorPointerCall3 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredFunctorPointerCall3 <T, FunctionPointer, Arg1, Arg2, Arg3>, - VoidStoredFunctorPointerCall3<T, FunctionPointer, Arg1, Arg2, Arg3> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -class StoredMemberFunctionCall3 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionCall3(T (Class::*_fn)(Param1, Param2, Param3) , const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1, arg2, arg3); - } -private: - T (Class::*fn)(Param1, Param2, Param3); - Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -class VoidStoredMemberFunctionCall3 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionCall3(T (Class::*_fn)(Param1, Param2, Param3) , const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3){ } - - void runFunctor() - { - (object.*fn)(arg1, arg2, arg3); - } -private: - T (Class::*fn)(Param1, Param2, Param3); - Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -struct SelectStoredMemberFunctionCall3 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionCall3 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>, - VoidStoredMemberFunctionCall3<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -class StoredConstMemberFunctionCall3 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionCall3(T (Class::*_fn)(Param1, Param2, Param3) const, const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1, arg2, arg3); - } -private: - T (Class::*fn)(Param1, Param2, Param3)const; - const Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -class VoidStoredConstMemberFunctionCall3 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionCall3(T (Class::*_fn)(Param1, Param2, Param3) const, const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3){ } - - void runFunctor() - { - (object.*fn)(arg1, arg2, arg3); - } -private: - T (Class::*fn)(Param1, Param2, Param3)const; - const Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -struct SelectStoredConstMemberFunctionCall3 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionCall3 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>, - VoidStoredConstMemberFunctionCall3<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -class StoredMemberFunctionPointerCall3 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionPointerCall3(T (Class::*_fn)(Param1, Param2, Param3) , Class *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1, arg2, arg3); - } -private: - T (Class::*fn)(Param1, Param2, Param3); - Class *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -class VoidStoredMemberFunctionPointerCall3 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionPointerCall3(T (Class::*_fn)(Param1, Param2, Param3) , Class *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3){ } - - void runFunctor() - { - (object->*fn)(arg1, arg2, arg3); - } -private: - T (Class::*fn)(Param1, Param2, Param3); - Class *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -struct SelectStoredMemberFunctionPointerCall3 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionPointerCall3 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>, - VoidStoredMemberFunctionPointerCall3<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -class StoredConstMemberFunctionPointerCall3 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionPointerCall3(T (Class::*_fn)(Param1, Param2, Param3) const, Class const *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1, arg2, arg3); - } -private: - T (Class::*fn)(Param1, Param2, Param3)const; - Class const *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -class VoidStoredConstMemberFunctionPointerCall3 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionPointerCall3(T (Class::*_fn)(Param1, Param2, Param3) const, Class const *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3){ } - - void runFunctor() - { - (object->*fn)(arg1, arg2, arg3); - } -private: - T (Class::*fn)(Param1, Param2, Param3)const; - Class const *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3> -struct SelectStoredConstMemberFunctionPointerCall3 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionPointerCall3 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3>, - VoidStoredConstMemberFunctionPointerCall3<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3> >::type type; -}; -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4> -struct StoredFunctorCall4: public RunFunctionTask<T> -{ - inline StoredFunctorCall4(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4) {} - void runFunctor() { this->result = function(arg1, arg2, arg3, arg4); } - FunctionPointer function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; - -template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4> -struct StoredFunctorCall4<void, FunctionPointer, Arg1, Arg2, Arg3, Arg4>: public RunFunctionTask<void> -{ - inline StoredFunctorCall4(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4) {} - void runFunctor() { function(arg1, arg2, arg3, arg4); } - FunctionPointer function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4> -struct StoredFunctorPointerCall4: public RunFunctionTask<T> -{ - inline StoredFunctorPointerCall4(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4) {} - void runFunctor() { this->result =(*function)(arg1, arg2, arg3, arg4); } - FunctionPointer * function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4> -struct VoidStoredFunctorPointerCall4: public RunFunctionTask<T> -{ - inline VoidStoredFunctorPointerCall4(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4) {} - void runFunctor() {(*function)(arg1, arg2, arg3, arg4); } - FunctionPointer * function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4> -struct SelectStoredFunctorPointerCall4 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredFunctorPointerCall4 <T, FunctionPointer, Arg1, Arg2, Arg3, Arg4>, - VoidStoredFunctorPointerCall4<T, FunctionPointer, Arg1, Arg2, Arg3, Arg4> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -class StoredMemberFunctionCall4 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionCall4(T (Class::*_fn)(Param1, Param2, Param3, Param4) , const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1, arg2, arg3, arg4); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4); - Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -class VoidStoredMemberFunctionCall4 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionCall4(T (Class::*_fn)(Param1, Param2, Param3, Param4) , const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4){ } - - void runFunctor() - { - (object.*fn)(arg1, arg2, arg3, arg4); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4); - Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -struct SelectStoredMemberFunctionCall4 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionCall4 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>, - VoidStoredMemberFunctionCall4<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -class StoredConstMemberFunctionCall4 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionCall4(T (Class::*_fn)(Param1, Param2, Param3, Param4) const, const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1, arg2, arg3, arg4); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4)const; - const Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -class VoidStoredConstMemberFunctionCall4 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionCall4(T (Class::*_fn)(Param1, Param2, Param3, Param4) const, const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4){ } - - void runFunctor() - { - (object.*fn)(arg1, arg2, arg3, arg4); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4)const; - const Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -struct SelectStoredConstMemberFunctionCall4 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionCall4 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>, - VoidStoredConstMemberFunctionCall4<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -class StoredMemberFunctionPointerCall4 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionPointerCall4(T (Class::*_fn)(Param1, Param2, Param3, Param4) , Class *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1, arg2, arg3, arg4); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4); - Class *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -class VoidStoredMemberFunctionPointerCall4 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionPointerCall4(T (Class::*_fn)(Param1, Param2, Param3, Param4) , Class *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4){ } - - void runFunctor() - { - (object->*fn)(arg1, arg2, arg3, arg4); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4); - Class *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -struct SelectStoredMemberFunctionPointerCall4 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionPointerCall4 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>, - VoidStoredMemberFunctionPointerCall4<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -class StoredConstMemberFunctionPointerCall4 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionPointerCall4(T (Class::*_fn)(Param1, Param2, Param3, Param4) const, Class const *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1, arg2, arg3, arg4); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4)const; - Class const *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -class VoidStoredConstMemberFunctionPointerCall4 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionPointerCall4(T (Class::*_fn)(Param1, Param2, Param3, Param4) const, Class const *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4){ } - - void runFunctor() - { - (object->*fn)(arg1, arg2, arg3, arg4); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4)const; - Class const *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4> -struct SelectStoredConstMemberFunctionPointerCall4 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionPointerCall4 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4>, - VoidStoredConstMemberFunctionPointerCall4<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4> >::type type; -}; -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> -struct StoredFunctorCall5: public RunFunctionTask<T> -{ - inline StoredFunctorCall5(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5) {} - void runFunctor() { this->result = function(arg1, arg2, arg3, arg4, arg5); } - FunctionPointer function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; - -template <typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> -struct StoredFunctorCall5<void, FunctionPointer, Arg1, Arg2, Arg3, Arg4, Arg5>: public RunFunctionTask<void> -{ - inline StoredFunctorCall5(FunctionPointer _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5) {} - void runFunctor() { function(arg1, arg2, arg3, arg4, arg5); } - FunctionPointer function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> -struct StoredFunctorPointerCall5: public RunFunctionTask<T> -{ - inline StoredFunctorPointerCall5(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5) {} - void runFunctor() { this->result =(*function)(arg1, arg2, arg3, arg4, arg5); } - FunctionPointer * function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> -struct VoidStoredFunctorPointerCall5: public RunFunctionTask<T> -{ - inline VoidStoredFunctorPointerCall5(FunctionPointer * _function, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : function(_function), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5) {} - void runFunctor() {(*function)(arg1, arg2, arg3, arg4, arg5); } - FunctionPointer * function; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; - -template <typename T, typename FunctionPointer, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5> -struct SelectStoredFunctorPointerCall5 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredFunctorPointerCall5 <T, FunctionPointer, Arg1, Arg2, Arg3, Arg4, Arg5>, - VoidStoredFunctorPointerCall5<T, FunctionPointer, Arg1, Arg2, Arg3, Arg4, Arg5> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -class StoredMemberFunctionCall5 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionCall5(T (Class::*_fn)(Param1, Param2, Param3, Param4, Param5) , const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1, arg2, arg3, arg4, arg5); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4, Param5); - Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -class VoidStoredMemberFunctionCall5 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionCall5(T (Class::*_fn)(Param1, Param2, Param3, Param4, Param5) , const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5){ } - - void runFunctor() - { - (object.*fn)(arg1, arg2, arg3, arg4, arg5); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4, Param5); - Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -struct SelectStoredMemberFunctionCall5 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionCall5 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>, - VoidStoredMemberFunctionCall5<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -class StoredConstMemberFunctionCall5 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionCall5(T (Class::*_fn)(Param1, Param2, Param3, Param4, Param5) const, const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5){ } - - void runFunctor() - { - this->result = (object.*fn)(arg1, arg2, arg3, arg4, arg5); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4, Param5)const; - const Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -class VoidStoredConstMemberFunctionCall5 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionCall5(T (Class::*_fn)(Param1, Param2, Param3, Param4, Param5) const, const Class &_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5){ } - - void runFunctor() - { - (object.*fn)(arg1, arg2, arg3, arg4, arg5); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4, Param5)const; - const Class object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -struct SelectStoredConstMemberFunctionCall5 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionCall5 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>, - VoidStoredConstMemberFunctionCall5<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -class StoredMemberFunctionPointerCall5 : public RunFunctionTask<T> -{ -public: - StoredMemberFunctionPointerCall5(T (Class::*_fn)(Param1, Param2, Param3, Param4, Param5) , Class *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1, arg2, arg3, arg4, arg5); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4, Param5); - Class *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -class VoidStoredMemberFunctionPointerCall5 : public RunFunctionTask<T> -{ -public: - VoidStoredMemberFunctionPointerCall5(T (Class::*_fn)(Param1, Param2, Param3, Param4, Param5) , Class *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5){ } - - void runFunctor() - { - (object->*fn)(arg1, arg2, arg3, arg4, arg5); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4, Param5); - Class *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -struct SelectStoredMemberFunctionPointerCall5 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredMemberFunctionPointerCall5 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>, - VoidStoredMemberFunctionPointerCall5<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5> >::type type; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -class StoredConstMemberFunctionPointerCall5 : public RunFunctionTask<T> -{ -public: - StoredConstMemberFunctionPointerCall5(T (Class::*_fn)(Param1, Param2, Param3, Param4, Param5) const, Class const *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5){ } - - void runFunctor() - { - this->result = (object->*fn)(arg1, arg2, arg3, arg4, arg5); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4, Param5)const; - Class const *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -class VoidStoredConstMemberFunctionPointerCall5 : public RunFunctionTask<T> -{ -public: - VoidStoredConstMemberFunctionPointerCall5(T (Class::*_fn)(Param1, Param2, Param3, Param4, Param5) const, Class const *_object, const Arg1 &_arg1, const Arg2 &_arg2, const Arg3 &_arg3, const Arg4 &_arg4, const Arg5 &_arg5) - : fn(_fn), object(_object), arg1(_arg1), arg2(_arg2), arg3(_arg3), arg4(_arg4), arg5(_arg5){ } - - void runFunctor() - { - (object->*fn)(arg1, arg2, arg3, arg4, arg5); - } -private: - T (Class::*fn)(Param1, Param2, Param3, Param4, Param5)const; - Class const *object; - Arg1 arg1; Arg2 arg2; Arg3 arg3; Arg4 arg4; Arg5 arg5; -}; -template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2, typename Param3, typename Arg3, typename Param4, typename Arg4, typename Param5, typename Arg5> -struct SelectStoredConstMemberFunctionPointerCall5 -{ - typedef typename SelectSpecialization<T>::template - Type<StoredConstMemberFunctionPointerCall5 <T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5>, - VoidStoredConstMemberFunctionPointerCall5<T, Class, Param1, Arg1, Param2, Arg2, Param3, Arg3, Param4, Arg4, Param5, Arg5> >::type type; -}; - -template <typename T, typename Functor> -class StoredFunctorCall : public RunFunctionTask<T> -{ -public: - StoredFunctorCall(const Functor &f) : functor(f) { } - void runFunctor() - { - this->result = functor(); - } -private: - Functor functor; -}; -template <typename Functor> -class StoredFunctorCall<void, Functor> : public RunFunctionTask<void> -{ -public: - StoredFunctorCall(const Functor &f) : functor(f) { } - void runFunctor() - { - functor(); - } -private: - Functor functor; -}; - - -} //namespace QtConcurrent - -#endif // qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/concurrent/qtconcurrentthreadengine.cpp b/src/corelib/concurrent/qtconcurrentthreadengine.cpp deleted file mode 100644 index 774122674f..0000000000 --- a/src/corelib/concurrent/qtconcurrentthreadengine.cpp +++ /dev/null @@ -1,299 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtconcurrentthreadengine.h" - -#ifndef QT_NO_CONCURRENT - -QT_BEGIN_NAMESPACE - -namespace QtConcurrent { - -ThreadEngineBarrier::ThreadEngineBarrier() -:count(0) { } - -void ThreadEngineBarrier::acquire() -{ - forever { - int localCount = count.load(); - if (localCount < 0) { - if (count.testAndSetOrdered(localCount, localCount -1)) - return; - } else { - if (count.testAndSetOrdered(localCount, localCount + 1)) - return; - } - } -} - -int ThreadEngineBarrier::release() -{ - forever { - int localCount = count.load(); - if (localCount == -1) { - if (count.testAndSetOrdered(-1, 0)) { - semaphore.release(); - return 0; - } - } else if (localCount < 0) { - if (count.testAndSetOrdered(localCount, localCount + 1)) - return qAbs(localCount + 1); - } else { - if (count.testAndSetOrdered(localCount, localCount - 1)) - return localCount - 1; - } - } -} - -// Wait until all threads have been released -void ThreadEngineBarrier::wait() -{ - forever { - int localCount = count.load(); - if (localCount == 0) - return; - - Q_ASSERT(localCount > 0); // multiple waiters are not allowed. - if (count.testAndSetOrdered(localCount, -localCount)) { - semaphore.acquire(); - return; - } - } -} - -int ThreadEngineBarrier::currentCount() -{ - return count.load(); -} - -// releases a thread, unless this is the last thread. -// returns true if the thread was released. -bool ThreadEngineBarrier::releaseUnlessLast() -{ - forever { - int localCount = count.load(); - if (qAbs(localCount) == 1) { - return false; - } else if (localCount < 0) { - if (count.testAndSetOrdered(localCount, localCount + 1)) - return true; - } else { - if (count.testAndSetOrdered(localCount, localCount - 1)) - return true; - } - } -} - -ThreadEngineBase::ThreadEngineBase() -:futureInterface(0), threadPool(QThreadPool::globalInstance()) -{ - setAutoDelete(false); -} - -ThreadEngineBase::~ThreadEngineBase() {} - -void ThreadEngineBase::startSingleThreaded() -{ - start(); - while (threadFunction() != ThreadFinished) - ; - finish(); -} - -void ThreadEngineBase::startBlocking() -{ - start(); - barrier.acquire(); - startThreads(); - - bool throttled = false; -#ifndef QT_NO_EXCEPTIONS - try { -#endif - while (threadFunction() == ThrottleThread) { - if (threadThrottleExit()) { - throttled = true; - break; - } - } -#ifndef QT_NO_EXCEPTIONS - } catch (QtConcurrent::Exception &e) { - handleException(e); - } catch (...) { - handleException(QtConcurrent::UnhandledException()); - } -#endif - - if (throttled == false) { - barrier.release(); - } - - barrier.wait(); - finish(); - exceptionStore.throwPossibleException(); -} - -void ThreadEngineBase::startThread() -{ - startThreadInternal(); -} - -void ThreadEngineBase::acquireBarrierSemaphore() -{ - barrier.acquire(); -} - -bool ThreadEngineBase::isCanceled() -{ - if (futureInterface) - return futureInterface->isCanceled(); - else - return false; -} - -void ThreadEngineBase::waitForResume() -{ - if (futureInterface) - futureInterface->waitForResume(); -} - -bool ThreadEngineBase::isProgressReportingEnabled() -{ - // If we don't have a QFuture, there is no-one to report the progress to. - return (futureInterface != 0); -} - -void ThreadEngineBase::setProgressValue(int progress) -{ - if (futureInterface) - futureInterface->setProgressValue(progress); -} - -void ThreadEngineBase::setProgressRange(int minimum, int maximum) -{ - if (futureInterface) - futureInterface->setProgressRange(minimum, maximum); -} - -bool ThreadEngineBase::startThreadInternal() -{ - if (this->isCanceled()) - return false; - - barrier.acquire(); - if (!threadPool->tryStart(this)) { - barrier.release(); - return false; - } - return true; -} - -void ThreadEngineBase::startThreads() -{ - while (shouldStartThread() && startThreadInternal()) - ; -} - -void ThreadEngineBase::threadExit() -{ - const bool asynchronous = futureInterface != 0; - const int lastThread = (barrier.release() == 0); - - if (lastThread && asynchronous) - this->asynchronousFinish(); -} - -// Called by a worker thread that wants to be throttled. If the current number -// of running threads is larger than one the thread is allowed to exit and -// this function returns one. -bool ThreadEngineBase::threadThrottleExit() -{ - return barrier.releaseUnlessLast(); -} - -void ThreadEngineBase::run() // implements QRunnable. -{ - if (this->isCanceled()) { - threadExit(); - return; - } - - startThreads(); - -#ifndef QT_NO_EXCEPTIONS - try { -#endif - while (threadFunction() == ThrottleThread) { - // threadFunction returning ThrottleThread means it that the user - // struct wants to be throttled by making a worker thread exit. - // Respect that request unless this is the only worker thread left - // running, in which case it has to keep going. - if (threadThrottleExit()) - return; - } - -#ifndef QT_NO_EXCEPTIONS - } catch (QtConcurrent::Exception &e) { - handleException(e); - } catch (...) { - handleException(QtConcurrent::UnhandledException()); - } -#endif - threadExit(); -} - -#ifndef QT_NO_EXCEPTIONS - -void ThreadEngineBase::handleException(const QtConcurrent::Exception &exception) -{ - if (futureInterface) - futureInterface->reportException(exception); - else - exceptionStore.setException(exception); -} -#endif - - -} // namepsace QtConcurrent - -QT_END_NAMESPACE - -#endif // QT_NO_CONCURRENT diff --git a/src/corelib/concurrent/qtconcurrentthreadengine.h b/src/corelib/concurrent/qtconcurrentthreadengine.h deleted file mode 100644 index e9c144a3c5..0000000000 --- a/src/corelib/concurrent/qtconcurrentthreadengine.h +++ /dev/null @@ -1,284 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTCONCURRENT_THREADENGINE_H -#define QTCONCURRENT_THREADENGINE_H - -#include <QtCore/qglobal.h> - -#ifndef QT_NO_CONCURRENT - -#include <QtCore/qthreadpool.h> -#include <QtCore/qfuture.h> -#include <QtCore/qdebug.h> -#include <QtCore/qtconcurrentexception.h> -#include <QtCore/qwaitcondition.h> -#include <QtCore/qatomic.h> -#include <QtCore/qsemaphore.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - - -#ifndef qdoc - -namespace QtConcurrent { - -// The ThreadEngineBarrier counts worker threads, and allows one -// thread to wait for all others to finish. Tested for its use in -// QtConcurrent, requires more testing for use as a general class. -class ThreadEngineBarrier -{ -private: - // The thread count is maintained as an integer in the count atomic - // variable. The count can be either positive or negative - a negative - // count signals that a thread is waiting on the barrier. - - // BC note: inlined code from Qt < 4.6 will expect to find the QMutex - // and QAtomicInt here. ### Qt 5: remove. - QMutex mutex; - QAtomicInt count; - - QSemaphore semaphore; -public: - ThreadEngineBarrier(); - void acquire(); - int release(); - void wait(); - int currentCount(); - bool releaseUnlessLast(); -}; - -enum ThreadFunctionResult { ThrottleThread, ThreadFinished }; - -// The ThreadEngine controls the threads used in the computation. -// Can be run in three modes: single threaded, multi-threaded blocking -// and multi-threaded asynchronous. -// The code for the single threaded mode is -class Q_CORE_EXPORT ThreadEngineBase: public QRunnable -{ -public: - // Public API: - ThreadEngineBase(); - virtual ~ThreadEngineBase(); - void startSingleThreaded(); - void startBlocking(); - void startThread(); - bool isCanceled(); - void waitForResume(); - bool isProgressReportingEnabled(); - void setProgressValue(int progress); - void setProgressRange(int minimum, int maximum); - void acquireBarrierSemaphore(); - -protected: // The user overrides these: - virtual void start() {} - virtual void finish() {} - virtual ThreadFunctionResult threadFunction() { return ThreadFinished; } - virtual bool shouldStartThread() { return futureInterface ? !futureInterface->isPaused() : true; } - virtual bool shouldThrottleThread() { return futureInterface ? futureInterface->isPaused() : false; } -private: - bool startThreadInternal(); - void startThreads(); - void threadExit(); - bool threadThrottleExit(); - void run(); - virtual void asynchronousFinish() = 0; -#ifndef QT_NO_EXCEPTIONS - void handleException(const QtConcurrent::Exception &exception); -#endif -protected: - QFutureInterfaceBase *futureInterface; - QThreadPool *threadPool; - ThreadEngineBarrier barrier; - QtConcurrent::internal::ExceptionStore exceptionStore; -}; - - -template <typename T> -class ThreadEngine : public virtual ThreadEngineBase -{ -public: - typedef T ResultType; - - virtual T *result() { return 0; } - - QFutureInterface<T> *futureInterfaceTyped() - { - return static_cast<QFutureInterface<T> *>(futureInterface); - } - - // Runs the user algorithm using a single thread. - T *startSingleThreaded() - { - ThreadEngineBase::startSingleThreaded(); - return result(); - } - - // Runs the user algorithm using multiple threads. - // This function blocks until the algorithm is finished, - // and then returns the result. - T *startBlocking() - { - ThreadEngineBase::startBlocking(); - return result(); - } - - // Runs the user algorithm using multiple threads. - // Does not block, returns a future. - QFuture<T> startAsynchronously() - { - futureInterface = new QFutureInterface<T>(); - - // reportStart() must be called before starting threads, otherwise the - // user algorithm might finish while reportStart() is running, which - // is very bad. - futureInterface->reportStarted(); - QFuture<T> future = QFuture<T>(futureInterfaceTyped()); - start(); - - acquireBarrierSemaphore(); - threadPool->start(this); - return future; - } - - void asynchronousFinish() - { - finish(); - futureInterfaceTyped()->reportFinished(result()); - delete futureInterfaceTyped(); - delete this; - } - - - void reportResult(const T *_result, int index = -1) - { - if (futureInterface) - futureInterfaceTyped()->reportResult(_result, index); - } - - void reportResults(const QVector<T> &_result, int index = -1, int count = -1) - { - if (futureInterface) - futureInterfaceTyped()->reportResults(_result, index, count); - } -}; - -// The ThreadEngineStarter class ecapsulates the return type -// from the thread engine. -// Depending on how the it is used, it will run -// the engine in either blocking mode or asynchronous mode. -template <typename T> -class ThreadEngineStarterBase -{ -public: - ThreadEngineStarterBase(ThreadEngine<T> *_threadEngine) - : threadEngine(_threadEngine) { } - - inline ThreadEngineStarterBase(const ThreadEngineStarterBase &other) - : threadEngine(other.threadEngine) { } - - QFuture<T> startAsynchronously() - { - return threadEngine->startAsynchronously(); - } - - operator QFuture<T>() - { - return startAsynchronously(); - } - -protected: - ThreadEngine<T> *threadEngine; -}; - - -// We need to factor out the code that dereferences the T pointer, -// with a specialization where T is void. (code that dereferences a void * -// won't compile) -template <typename T> -class ThreadEngineStarter : public ThreadEngineStarterBase<T> -{ - typedef ThreadEngineStarterBase<T> Base; - typedef ThreadEngine<T> TypedThreadEngine; -public: - ThreadEngineStarter(TypedThreadEngine *eng) - : Base(eng) { } - - T startBlocking() - { - T t = *this->threadEngine->startBlocking(); - delete this->threadEngine; - return t; - } -}; - -// Full template specialization where T is void. -template <> -class ThreadEngineStarter<void> : public ThreadEngineStarterBase<void> -{ -public: - ThreadEngineStarter<void>(ThreadEngine<void> *_threadEngine) - :ThreadEngineStarterBase<void>(_threadEngine) {} - - void startBlocking() - { - this->threadEngine->startBlocking(); - delete this->threadEngine; - } -}; - -template <typename ThreadEngine> -inline ThreadEngineStarter<typename ThreadEngine::ResultType> startThreadEngine(ThreadEngine *threadEngine) -{ - return ThreadEngineStarter<typename ThreadEngine::ResultType>(threadEngine); -} - -} // namespace QtConcurrent - -#endif //qdoc - -QT_END_NAMESPACE -QT_END_HEADER - -#endif // QT_NO_CONCURRENT - -#endif diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro index de2b1006cf..c8c9b9b8e6 100644 --- a/src/corelib/corelib.pro +++ b/src/corelib/corelib.pro @@ -18,7 +18,6 @@ HEADERS += $$QT_SOURCE_TREE/src/corelib/qtcoreversion.h include(animation/animation.pri) include(arch/arch.pri) -include(concurrent/concurrent.pri) include(global/global.pri) include(thread/thread.pri) include(tools/tools.pri) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 681cd55bb0..c92336f95c 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1326,6 +1326,11 @@ class QDataStream; # define Q_DBUS_EXPORT Q_DECL_IMPORT # endif # define Q_TEMPLATEDLL +# if defined(QT_BUILD_CONCURRENT_LIB) +# define Q_CONCURRENT_EXPORT Q_DECL_EXPORT +# else +# define Q_CONCURRENT_EXPORT Q_DECL_IMPORT +# endif # elif defined(QT_DLL) /* use a Qt DLL library */ # define Q_CORE_EXPORT Q_DECL_IMPORT # define Q_GUI_EXPORT Q_DECL_IMPORT @@ -1347,6 +1352,7 @@ class QDataStream; # define Q_SCRIPTTOOLS_EXPORT Q_DECL_IMPORT # define Q_COMPAT_EXPORT Q_DECL_IMPORT # define Q_DBUS_EXPORT Q_DECL_IMPORT +# define Q_CONCURRENT_EXPORT Q_DECL_IMPORT # define Q_TEMPLATEDLL # endif # define Q_NO_DECLARED_NOT_DEFINED @@ -1380,6 +1386,7 @@ class QDataStream; # define Q_SCRIPTTOOLS_EXPORT Q_DECL_EXPORT # define Q_COMPAT_EXPORT Q_DECL_EXPORT # define Q_DBUS_EXPORT Q_DECL_EXPORT +# define Q_CONCURRENT_EXPORT Q_DECL_EXPORT # else # define Q_CORE_EXPORT # define Q_GUI_EXPORT @@ -1400,6 +1407,7 @@ class QDataStream; # define Q_SCRIPTTOOLS_EXPORT # define Q_COMPAT_EXPORT # define Q_DBUS_EXPORT +# define Q_CONCURRENT_EXPORT # endif #endif diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index a248e18a6a..cf3ae1b7c5 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -593,7 +593,6 @@ QCoreApplication::~QCoreApplication() QCoreApplicationPrivate::is_app_running = false; #if !defined(QT_NO_THREAD) -#if !defined(QT_NO_CONCURRENT) // Synchronize and stop the global thread pool threads. QThreadPool *globalThreadPool = 0; QT_TRY { @@ -603,7 +602,6 @@ QCoreApplication::~QCoreApplication() } if (globalThreadPool) globalThreadPool->waitForDone(); -#endif QThread::cleanup(); #endif diff --git a/src/corelib/concurrent/qrunnable.cpp b/src/corelib/thread/qrunnable.cpp index 933a5b922c..933a5b922c 100644 --- a/src/corelib/concurrent/qrunnable.cpp +++ b/src/corelib/thread/qrunnable.cpp diff --git a/src/corelib/concurrent/qrunnable.h b/src/corelib/thread/qrunnable.h index 11d5c0146e..11d5c0146e 100644 --- a/src/corelib/concurrent/qrunnable.h +++ b/src/corelib/thread/qrunnable.h diff --git a/src/corelib/concurrent/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index af8c99197e..af8c99197e 100644 --- a/src/corelib/concurrent/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp diff --git a/src/corelib/concurrent/qthreadpool.h b/src/corelib/thread/qthreadpool.h index 9fc023c56d..9fc023c56d 100644 --- a/src/corelib/concurrent/qthreadpool.h +++ b/src/corelib/thread/qthreadpool.h diff --git a/src/corelib/concurrent/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h index f4c67b81a7..9a7c09695f 100644 --- a/src/corelib/concurrent/qthreadpool_p.h +++ b/src/corelib/thread/qthreadpool_p.h @@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE class QThreadPoolThread; -class QThreadPoolPrivate : public QObjectPrivate +class Q_CORE_EXPORT QThreadPoolPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QThreadPool) friend class QThreadPoolThread; diff --git a/src/corelib/thread/thread.pri b/src/corelib/thread/thread.pri index ea6f0eb91e..1eefa60d50 100644 --- a/src/corelib/thread/thread.pri +++ b/src/corelib/thread/thread.pri @@ -2,9 +2,11 @@ # public headers HEADERS += thread/qmutex.h \ + thread/qrunnable.h \ thread/qreadwritelock.h \ thread/qsemaphore.h \ thread/qthread.h \ + thread/qthreadpool.h \ thread/qthreadstorage.h \ thread/qwaitcondition.h \ thread/qatomic.h \ @@ -17,14 +19,17 @@ HEADERS += thread/qmutex_p.h \ thread/qmutexpool_p.h \ thread/qorderedmutexlocker_p.h \ thread/qreadwritelock_p.h \ - thread/qthread_p.h + thread/qthread_p.h \ + thread/qthreadpool_p.h SOURCES += thread/qatomic.cpp \ thread/qmutex.cpp \ thread/qreadwritelock.cpp \ + thread/qrunnable.cpp \ thread/qmutexpool.cpp \ thread/qsemaphore.cpp \ thread/qthread.cpp \ + thread/qthreadpool.cpp \ thread/qthreadstorage.cpp unix:SOURCES += thread/qthread_unix.cpp \ |