summaryrefslogtreecommitdiffstats
path: root/src/concurrent/qtconcurrentrunbase.h
diff options
context:
space:
mode:
authorVitaly Fanaskov <[email protected]>2020-03-11 18:07:03 +0100
committerVitaly Fanaskov <[email protected]>2020-03-29 20:44:32 +0100
commit5a0d4f3313157d2fe48e9d159968bed6883eb5f8 (patch)
treed7366ac16fdbe83ff4e8006577f9987404ae2742 /src/concurrent/qtconcurrentrunbase.h
parentd975ad4ed728553b765c61f38c1e0df899187cf5 (diff)
QtConcurrent: add fluent interface to configure a task before run
Task-number: QTBUG-82950 Change-Id: I449da938b6b501a7646b3425edde5c880d6ca87e Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Paul Wicking <[email protected]> Reviewed-by: Mikhail Svetkin <[email protected]>
Diffstat (limited to 'src/concurrent/qtconcurrentrunbase.h')
-rw-r--r--src/concurrent/qtconcurrentrunbase.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/concurrent/qtconcurrentrunbase.h b/src/concurrent/qtconcurrentrunbase.h
index aaa1245856b..e84c0cdb670 100644
--- a/src/concurrent/qtconcurrentrunbase.h
+++ b/src/concurrent/qtconcurrentrunbase.h
@@ -69,25 +69,34 @@ struct SelectSpecialization<void>
struct Type { typedef Void type; };
};
+struct TaskStartParameters
+{
+ QThreadPool *threadPool = QThreadPool::globalInstance();
+ int priority = 0;
+};
+
template <typename T>
class RunFunctionTaskBase : public QFutureInterface<T> , public QRunnable
{
public:
QFuture<T> start()
{
- return start(QThreadPool::globalInstance());
+ return start(TaskStartParameters());
}
- QFuture<T> start(QThreadPool *pool)
+ QFuture<T> start(const TaskStartParameters &parameters)
{
- this->setThreadPool(pool);
+ this->setThreadPool(parameters.threadPool);
this->setRunnable(this);
this->reportStarted();
QFuture<T> theFuture = this->future();
- pool->start(this, /*m_priority*/ 0);
+ parameters.threadPool->start(this, parameters.priority);
return theFuture;
}
+ // For backward compatibility
+ QFuture<T> start(QThreadPool *pool) { return start({pool, 0}); }
+
void run() override {}
virtual void runFunctor() = 0;
};