aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/function/gpg/GpgCommandExecutor.cpp2
-rw-r--r--src/core/module/GlobalModuleContext.cpp20
-rw-r--r--src/core/thread/Task.cpp4
-rw-r--r--src/core/thread/TaskRunner.cpp66
-rw-r--r--src/core/thread/TaskRunner.h4
-rw-r--r--src/core/utils/AsyncUtils.cpp2
6 files changed, 24 insertions, 74 deletions
diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp
index fa4b7dbd..fd6d6099 100644
--- a/src/core/function/gpg/GpgCommandExecutor.cpp
+++ b/src/core/function/gpg/GpgCommandExecutor.cpp
@@ -234,7 +234,7 @@ void GpgCommandExecutor::ExecuteConcurrentlySync(ExecuteContexts contexts) {
for (auto &context : contexts) {
const auto &cmd = context.cmd;
- GF_CORE_LOG_DEBUG("gpg concurrently called cmd {}", cmd);
+ GF_CORE_LOG_DEBUG("gpg concurrently called cmd: {}", cmd);
Thread::Task *task = BuildTaskFromExecCtx(context);
diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp
index 6222a97d..a86879ab 100644
--- a/src/core/module/GlobalModuleContext.cpp
+++ b/src/core/module/GlobalModuleContext.cpp
@@ -254,18 +254,18 @@ class GlobalModuleContext::Impl {
// Check if the module is activated
if (!module_info->activate) continue;
- Thread::Task::TaskRunnable exec_runnerable =
+ Thread::Task::TaskRunnable const exec_runnerable =
[module, event](DataObjectPtr) -> int { return module->Exec(event); };
- Thread::Task::TaskCallback exec_callback = [listener_module_id, event_id](
- int code, DataObjectPtr) {
- if (code < 0) {
- // Log an error if the module execution fails
- GF_CORE_LOG_ERROR(
- "module {} execution failed of event {}: exec return code {}",
- listener_module_id, event_id, code);
- }
- };
+ Thread::Task::TaskCallback const exec_callback =
+ [listener_module_id, event_id](int code, DataObjectPtr) {
+ if (code < 0) {
+ // Log an error if the module execution fails
+ GF_CORE_LOG_ERROR(
+ "module {} execution failed of event {}: exec return code {}",
+ listener_module_id, event_id, code);
+ }
+ };
Thread::TaskRunnerGetter::GetInstance()
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Module)
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
diff --git a/src/core/utils/AsyncUtils.cpp b/src/core/utils/AsyncUtils.cpp
index 385a8d56..c22ffd6d 100644
--- a/src/core/utils/AsyncUtils.cpp
+++ b/src/core/utils/AsyncUtils.cpp
@@ -52,6 +52,7 @@ void RunGpgOperaAsync(GpgOperaRunnable runnable, GpgOperationCallback callback,
Thread::TaskRunnerGetter::GetInstance()
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_GPG)
->PostTask(
+ operation,
[=](const DataObjectPtr& data_object) -> int {
auto custom_data_object = TransferParams();
GpgError err = runnable(custom_data_object);
@@ -71,6 +72,7 @@ void RunIOOperaAsync(OperaRunnable runnable, OperationCallback callback,
Thread::TaskRunnerGetter::GetInstance()
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_IO)
->PostTask(
+ operation,
[=](const DataObjectPtr& data_object) -> int {
auto custom_data_object = TransferParams();
GpgError err = runnable(custom_data_object);