summaryrefslogtreecommitdiffstats
path: root/src/concurrent/qtconcurrentrunbase.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/concurrent/qtconcurrentrunbase.h')
-rw-r--r--src/concurrent/qtconcurrentrunbase.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/concurrent/qtconcurrentrunbase.h b/src/concurrent/qtconcurrentrunbase.h
index aaa1245856..5e9fa0aa00 100644
--- a/src/concurrent/qtconcurrentrunbase.h
+++ b/src/concurrent/qtconcurrentrunbase.h
@@ -48,6 +48,9 @@
#include <QtCore/qrunnable.h>
#include <QtCore/qthreadpool.h>
+#include <type_traits>
+#include <utility>
+
QT_BEGIN_NAMESPACE
@@ -69,25 +72,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;
};
@@ -114,7 +126,11 @@ public:
}
#endif
- this->reportResult(result);
+ if constexpr (std::is_move_constructible_v<T>)
+ this->reportAndMoveResult(std::move(result));
+ else if constexpr (std::is_copy_constructible_v<T>)
+ this->reportResult(result);
+
this->reportFinished();
}
T result;