Skip to content

Commit

Permalink
chore: rename executors
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Sep 12, 2024
1 parent b47e09a commit 251d0ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ll/api/thread/InplaceExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ std::shared_ptr<data::CancellableCallback> InplaceExecutor::executeAfter(std::fu
}

InplaceExecutor const& InplaceExecutor::getDefault() {
static InplaceExecutor ins("default_inplace");
static InplaceExecutor ins("ll_default_inplace");
return ins;
}
} // namespace ll::thread
4 changes: 2 additions & 2 deletions src/ll/api/thread/ServerThreadExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -104,7 +104,7 @@ ServerThreadExecutor::executeAfter(std::function<void()> 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
14 changes: 6 additions & 8 deletions src/ll/api/thread/ThreadPoolExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Clock::duration> frontTime{};

Expand Down Expand Up @@ -69,20 +69,18 @@ struct ThreadPoolExecutor::Impl {
ConcurrentQueue<std::function<void()>> tasks;
std::counting_semaphore<> taskCount{0};
std::optional<ScheduledWorker> 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<void()> task;
Expand All @@ -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());
}
}
Expand Down Expand Up @@ -138,7 +136,7 @@ ThreadPoolExecutor::executeAfter(std::function<void()> 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

0 comments on commit 251d0ae

Please sign in to comment.