diff options
Diffstat (limited to 'src/core/thread')
-rw-r--r-- | src/core/thread/Task.cpp | 4 | ||||
-rw-r--r-- | src/core/thread/TaskRunner.cpp | 66 | ||||
-rw-r--r-- | src/core/thread/TaskRunner.h | 4 |
3 files changed, 11 insertions, 63 deletions
diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp index 86799b9f..848f9cfc 100644 --- a/src/core/thread/Task.cpp +++ b/src/core/thread/Task.cpp @@ -130,10 +130,10 @@ class Task::Impl { HoldOnLifeCycle(false); // - connect(parent_, &Task::SignalRun, [=]() { inner_run(); }); + connect(parent_, &Task::SignalRun, parent_, [=]() { inner_run(); }); // - connect(parent_, &Task::SignalTaskShouldEnd, + connect(parent_, &Task::SignalTaskShouldEnd, parent_, [=](int rtn) { slot_task_should_end(rtn); }); // diff --git a/src/core/thread/TaskRunner.cpp b/src/core/thread/TaskRunner.cpp index 0e9c9098..dbd14225 100644 --- a/src/core/thread/TaskRunner.cpp +++ b/src/core/thread/TaskRunner.cpp @@ -56,62 +56,9 @@ class TaskRunner::Impl : public QThread { task->SafelyRun(); } - static void PostTask(const Task::TaskRunnable& runner, - const Task::TaskCallback& cb, DataObjectPtr p_obj) { - auto* callback_thread = QThread::currentThread(); - auto data_object = std::move(p_obj); - const auto task_uuid = generate_uuid(); - - QtConcurrent::run(runner, data_object).then([=](int rtn) { - if (!cb) { - GF_CORE_LOG_TRACE("task {} doesn't have a callback function", - task_uuid); - return; - } - - if (callback_thread == QThread::currentThread()) { - GF_CORE_LOG_TRACE( - "for task {}, the callback thread is the same thread: {}", - task_uuid, static_cast<void*>(callback_thread)); - - cb(rtn, data_object); - - // raise signal, announcing this task comes to an end - GF_CORE_LOG_TRACE( - "for task {}, its life comes to an end in the same thread " - "after its callback executed.", - task_uuid); - } else { - GF_CORE_LOG_TRACE( - "for task {}, callback thread is a different thread: {}", task_uuid, - static_cast<void*>(callback_thread)); - if (!QMetaObject::invokeMethod(callback_thread, [=]() { - GF_CORE_LOG_TRACE("calling callback of task {}", task_uuid); - try { - cb(rtn, data_object); - } catch (...) { - GF_CORE_LOG_ERROR( - "unknown exception was caught when execute " - "callback of task {}", - task_uuid); - } - // raise signal, announcing this task comes to an end - GF_CORE_LOG_TRACE( - "for task {}, its life comes to an end whether its " - "callback function fails or not.", - task_uuid); - })) { - GF_CORE_LOG_ERROR( - "task {} had failed to invoke the callback function to " - "target thread", - task_uuid); - GF_CORE_LOG_TRACE( - "for task {}, its life must come to an end now, although it " - "has something not done yet.", - task_uuid); - } - } - }); + void PostTask(const std::string& name, const Task::TaskRunnable& runnerable, + const Task::TaskCallback& cb, DataObjectPtr params) { + PostTask(new Task(runnerable, name, std::move(params), cb)); } void PostConcurrentTask(Task* task) { @@ -157,9 +104,10 @@ TaskRunner::~TaskRunner() { void TaskRunner::PostTask(Task* task) { p_->PostTask(task); } -void TaskRunner::PostTask(const Task::TaskRunnable& runner, - const Task::TaskCallback& cb, DataObjectPtr p_obj) { - p_->PostTask(runner, cb, p_obj); +void TaskRunner::PostTask(const std::string& name, + const Task::TaskRunnable& runner, + const Task::TaskCallback& cb, DataObjectPtr params) { + p_->PostTask(name, runner, cb, std::move(params)); } void TaskRunner::PostConcurrentTask(Task* task) { diff --git a/src/core/thread/TaskRunner.h b/src/core/thread/TaskRunner.h index 9b06057b..26eba61f 100644 --- a/src/core/thread/TaskRunner.h +++ b/src/core/thread/TaskRunner.h @@ -91,8 +91,8 @@ class GPGFRONTEND_CORE_EXPORT TaskRunner : public QObject { * @param runner * @param cb */ - void PostTask(const Task::TaskRunnable& runner, const Task::TaskCallback& cb, - DataObjectPtr p_obj); + void PostTask(const std::string&, const Task::TaskRunnable&, + const Task::TaskCallback&, DataObjectPtr); /** * @brief |