aboutsummaryrefslogtreecommitdiffstats
path: root/lang/qt/src/threadedjobmixin.h
diff options
context:
space:
mode:
Diffstat (limited to 'lang/qt/src/threadedjobmixin.h')
-rw-r--r--lang/qt/src/threadedjobmixin.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/lang/qt/src/threadedjobmixin.h b/lang/qt/src/threadedjobmixin.h
index ef30ab36..f50ac43d 100644
--- a/lang/qt/src/threadedjobmixin.h
+++ b/lang/qt/src/threadedjobmixin.h
@@ -103,6 +103,12 @@ public:
m_function = function;
}
+ bool hasFunction()
+ {
+ const QMutexLocker locker(&m_mutex);
+ return static_cast<bool>(m_function);
+ }
+
T_result result() const
{
const QMutexLocker locker(&m_mutex);
@@ -127,6 +133,12 @@ public:
typedef ThreadedJobMixin<T_base, T_result> mixin_type;
typedef T_result result_type;
+ void run()
+ {
+ Q_ASSERT(m_thread.hasFunction() && "Call setWorkerFunction() before run()");
+ m_thread.start();
+ }
+
protected:
static_assert(std::tuple_size<T_result>::value > 2,
"Result tuple too small");
@@ -167,6 +179,12 @@ protected:
}
template <typename T_binder>
+ void setWorkerFunction(const T_binder &func)
+ {
+ m_thread.setFunction([this, func]() { return func(this->context()); });
+ }
+
+ template <typename T_binder>
void run(const T_binder &func)
{
m_thread.setFunction(std::bind(func, this->context()));