summaryrefslogtreecommitdiffstats
path: root/src/concurrent
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2020-07-10 13:07:42 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2020-07-13 19:55:20 +0200
commitb91a5d053d48b90a2cf56429d432cdfcb1098efd (patch)
treecd0188f270b37cdc0194eb647cf6fd92a045347c /src/concurrent
parent974e55bd70648972c6481f1e8ae724b8b9a8f3d4 (diff)
QtConcurrent: Get rid of code repetition for RunFunctionTask::run()
Change-Id: If270982e54d2b11be00c71b9d012af629d181dfe Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/concurrent')
-rw-r--r--src/concurrent/qtconcurrentrunbase.h53
-rw-r--r--src/concurrent/qtconcurrentstoredfunctioncall.h2
2 files changed, 21 insertions, 34 deletions
diff --git a/src/concurrent/qtconcurrentrunbase.h b/src/concurrent/qtconcurrentrunbase.h
index 5e9fa0aa00..176097c04f 100644
--- a/src/concurrent/qtconcurrentrunbase.h
+++ b/src/concurrent/qtconcurrentrunbase.h
@@ -100,14 +100,6 @@ public:
// For backward compatibility
QFuture<T> start(QThreadPool *pool) { return start({pool, 0}); }
- void run() override {}
- virtual void runFunctor() = 0;
-};
-
-template <typename T>
-class RunFunctionTask : public RunFunctionTaskBase<T>
-{
-public:
void run() override
{
if (this->isCanceled()) {
@@ -117,7 +109,7 @@ public:
#ifndef QT_NO_EXCEPTIONS
try {
#endif
- this->runFunctor();
+ runFunctor();
#ifndef QT_NO_EXCEPTIONS
} catch (QException &e) {
QFutureInterface<T>::reportException(e);
@@ -126,41 +118,34 @@ public:
}
#endif
- 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);
+ reportResult();
this->reportFinished();
}
- T result;
+
+protected:
+ virtual void runFunctor() = 0;
+ virtual void reportResult() {}
};
-template <>
-class RunFunctionTask<void> : public RunFunctionTaskBase<void>
+template <typename T>
+class RunFunctionTask : public RunFunctionTaskBase<T>
{
-public:
- void run() override
+protected:
+ void reportResult() override
{
- if (this->isCanceled()) {
- this->reportFinished();
- return;
- }
-#ifndef QT_NO_EXCEPTIONS
- try {
-#endif
- this->runFunctor();
-#ifndef QT_NO_EXCEPTIONS
- } catch (QException &e) {
- QFutureInterface<void>::reportException(e);
- } catch (...) {
- QFutureInterface<void>::reportException(QUnhandledException());
- }
-#endif
- this->reportFinished();
+ 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);
}
+
+ T result;
};
+template <>
+class RunFunctionTask<void> : public RunFunctionTaskBase<void> {};
+
} //namespace QtConcurrent
#endif //Q_QDOC
diff --git a/src/concurrent/qtconcurrentstoredfunctioncall.h b/src/concurrent/qtconcurrentstoredfunctioncall.h
index b879e8af45..f6d47f5119 100644
--- a/src/concurrent/qtconcurrentstoredfunctioncall.h
+++ b/src/concurrent/qtconcurrentstoredfunctioncall.h
@@ -78,6 +78,7 @@ struct StoredFunctionCall : public RunFunctionTask<InvokeResultType<Function, Ar
: data(std::move(_data))
{}
+protected:
void runFunctor() override
{
constexpr auto invoke = &std::invoke<std::decay_t<Function>,
@@ -89,6 +90,7 @@ struct StoredFunctionCall : public RunFunctionTask<InvokeResultType<Function, Ar
this->result = std::apply(invoke, std::move(data));
}
+private:
DecayedTuple<Function, Args...> data;
};