diff options
author | saturneric <[email protected]> | 2023-12-15 13:14:17 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2023-12-15 13:14:17 +0000 |
commit | f9a49043c35e73fc2d4ffb3ed9b39c33849c43b3 (patch) | |
tree | 7e03b0b62119ff5d5dcd732ec1ccb7d2296df86d /src/core/thread/TaskRunnerGetter.cpp | |
parent | fix: slove some issues on memory and intilizations (diff) | |
download | GpgFrontend-f9a49043c35e73fc2d4ffb3ed9b39c33849c43b3.tar.gz GpgFrontend-f9a49043c35e73fc2d4ffb3ed9b39c33849c43b3.zip |
fix: slove threading and memory issues
Diffstat (limited to 'src/core/thread/TaskRunnerGetter.cpp')
-rw-r--r-- | src/core/thread/TaskRunnerGetter.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/core/thread/TaskRunnerGetter.cpp b/src/core/thread/TaskRunnerGetter.cpp index 639a142c..bdcd89d0 100644 --- a/src/core/thread/TaskRunnerGetter.cpp +++ b/src/core/thread/TaskRunnerGetter.cpp @@ -28,25 +28,37 @@ #include "core/thread/TaskRunnerGetter.h" -#include "thread/TaskRunner.h" +#include <mutex> + +#include "core/GpgConstants.h" +#include "core/thread/TaskRunner.h" namespace GpgFrontend::Thread { -TaskRunnerGetter::TaskRunnerGetter(int channel) - : SingletonFunctionObject<TaskRunnerGetter>(channel) {} +TaskRunnerGetter::TaskRunnerGetter(int) + : SingletonFunctionObject<TaskRunnerGetter>(kGpgFrontendDefaultChannel) {} -TaskRunnerPtr GpgFrontend::Thread::TaskRunnerGetter::GetTaskRunner( - TaskRunnerType runner_type) { +auto TaskRunnerGetter::GetTaskRunner(TaskRunnerType runner_type) + -> TaskRunnerPtr { + std::lock_guard<std::mutex> lock_guard(task_runners_map_lock_); while (true) { auto it = task_runners_.find(runner_type); if (it != task_runners_.end()) { return it->second; - } else { - auto runner = GpgFrontend::SecureCreateSharedObject<TaskRunner>(); - task_runners_[runner_type] = runner; - runner->Start(); - continue; } + + auto runner = GpgFrontend::SecureCreateSharedObject<TaskRunner>(); + task_runners_[runner_type] = runner; + runner->Start(); } } + +void TaskRunnerGetter::StopAllTeakRunner() { + for (const auto& [key, value] : task_runners_) { + if (value->IsRunning()) { + value->Stop(); + } + } +} + } // namespace GpgFrontend::Thread
\ No newline at end of file |