From 251d0ae8d05c204676e2320d6082c29b69cdd7fa Mon Sep 17 00:00:00 2001 From: OEOTYAN Date: Thu, 12 Sep 2024 19:48:25 +0800 Subject: [PATCH] chore: rename executors --- src/ll/api/thread/InplaceExecutor.cpp | 2 +- src/ll/api/thread/ServerThreadExecutor.cpp | 4 ++-- src/ll/api/thread/ThreadPoolExecutor.cpp | 14 ++++++-------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ll/api/thread/InplaceExecutor.cpp b/src/ll/api/thread/InplaceExecutor.cpp index 98529d4ee5..03b6179f45 100644 --- a/src/ll/api/thread/InplaceExecutor.cpp +++ b/src/ll/api/thread/InplaceExecutor.cpp @@ -17,7 +17,7 @@ std::shared_ptr InplaceExecutor::executeAfter(std::fu } InplaceExecutor const& InplaceExecutor::getDefault() { - static InplaceExecutor ins("default_inplace"); + static InplaceExecutor ins("ll_default_inplace"); return ins; } } // namespace ll::thread diff --git a/src/ll/api/thread/ServerThreadExecutor.cpp b/src/ll/api/thread/ServerThreadExecutor.cpp index 0f648a6fc4..b0f393be21 100644 --- a/src/ll/api/thread/ServerThreadExecutor.cpp +++ b/src/ll/api/thread/ServerThreadExecutor.cpp @@ -73,7 +73,7 @@ ServerThreadExecutor::ServerThreadExecutor(std::string name, Duration maxOnceDur try { f(); } catch (...) { - getLogger().error("Error in ServerThreadExecutor({}):", name); + getLogger().error("Error in {}:", name); error_utils::printCurrentException(getLogger()); } if (i % checkPack == 0 && Clock::now() - begin > maxOnceDuration) { @@ -104,7 +104,7 @@ ServerThreadExecutor::executeAfter(std::function f, Duration dur) const } ServerThreadExecutor const& ServerThreadExecutor::getDefault() { - static ServerThreadExecutor ins("default_server_thread", std::chrono::milliseconds{30}, 16); + static ServerThreadExecutor ins("ll_default_server_thread", std::chrono::milliseconds{30}, 16); return ins; } } // namespace ll::thread diff --git a/src/ll/api/thread/ThreadPoolExecutor.cpp b/src/ll/api/thread/ThreadPoolExecutor.cpp index b7376d3786..7542776ac7 100644 --- a/src/ll/api/thread/ThreadPoolExecutor.cpp +++ b/src/ll/api/thread/ThreadPoolExecutor.cpp @@ -31,7 +31,7 @@ struct ThreadPoolExecutor::Impl { ScheduledWorker(Executor const& e) { schtrd = std::thread{[this, &e]() { ll::error_utils::initExceptionTranslator(); - setThreadName(fmt::format("ll::ThreadPoolExecutor({})[sch]", e.getName())); + setThreadName(fmt::format("{}[sch]", e.getName())); while (working) { std::optional frontTime{}; @@ -69,20 +69,18 @@ struct ThreadPoolExecutor::Impl { ConcurrentQueue> tasks; std::counting_semaphore<> taskCount{0}; std::optional scheduledWorker; - std::atomic_bool hasSchWorker{false}; + std::once_flag hasSchWorker; std::atomic_bool stop{false}; ScheduledWorker& getScheduledWorker(Executor const& e) { - if (!hasSchWorker.exchange(true)) { - scheduledWorker.emplace(e); - } + std::call_once(hasSchWorker, [&]() { scheduledWorker.emplace(e); }); return *scheduledWorker; } Impl(Executor& self, size_t nThreads) { for (size_t i = 0; i < nThreads; ++i) { workers.emplace_back([this, &self, i] { ll::error_utils::initExceptionTranslator(); - setThreadName(fmt::format("ll::ThreadPoolExecutor({})[{}]", self.getName(), i)); + setThreadName(fmt::format("{}[{}]", self.getName(), i)); decltype(tasks)::consumer_token_t token{tasks}; for (;;) { std::function task; @@ -95,7 +93,7 @@ struct ThreadPoolExecutor::Impl { try { task(); } catch (...) { - getLogger().error("Error in ThreadPoolExecutor({})[{}]:", self.getName(), i); + getLogger().error("Error in {}[{}]:", self.getName(), i); error_utils::printCurrentException(getLogger()); } } @@ -138,7 +136,7 @@ ThreadPoolExecutor::executeAfter(std::function f, Duration dur) const { } } ThreadPoolExecutor const& ThreadPoolExecutor::getDefault() { - static ThreadPoolExecutor ins("default_thread_pool", std::max((int)std::thread::hardware_concurrency() - 2, 2)); + static ThreadPoolExecutor ins("ll_default_thread_pool", std::max((int)std::thread::hardware_concurrency() - 2, 2)); return ins; } } // namespace ll::thread