From ff44a673035aeb97b061b40dd95398547ed2582a Mon Sep 17 00:00:00 2001 From: royna2544 Date: Fri, 15 Nov 2024 20:33:46 +0900 Subject: [PATCH] api: Async: Make it take a name --- src/api/components/Async.cpp | 6 +++--- src/api/components/ModuleManagement.cpp | 2 +- src/api/components/OnCallbackQuery.cpp | 2 +- src/include/api/components/Async.hpp | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/api/components/Async.cpp b/src/api/components/Async.cpp index 6885e8b0..21f3b027 100644 --- a/src/api/components/Async.cpp +++ b/src/api/components/Async.cpp @@ -8,15 +8,15 @@ void TgBotApiImpl::Async::emplaceTask(std::string command, condVariable.notify_one(); } -TgBotApiImpl::Async::Async(const int count) { - DLOG(INFO) << "Starting AsyncThreads, count: " << count; +TgBotApiImpl::Async::Async(std::string name, const int count) : _name(std::move(name)) { + DLOG(INFO) << fmt::format("Starting AsyncThreads '{}', count: {}", _name, count); for (int i = 0; i < count; ++i) { threads.emplace_back([this]() { threadFunction(); }); } } TgBotApiImpl::Async::~Async() { - DLOG(INFO) << "Stopping AsyncThreads"; + DLOG(INFO) << fmt::format("Stopping AsyncThreads '{}'", _name); stopWorker = true; condVariable.notify_all(); for (auto& thread : threads) { diff --git a/src/api/components/ModuleManagement.cpp b/src/api/components/ModuleManagement.cpp index 451a7678..458de203 100644 --- a/src/api/components/ModuleManagement.cpp +++ b/src/api/components/ModuleManagement.cpp @@ -126,7 +126,7 @@ bool TgBotApiImpl::ModulesManagement::loadFrom( TgBotApiImpl::ModulesManagement::ModulesManagement( TgBotApiImpl::Ptr api, const std::filesystem::path& modules_dir) - : _api(api), commandAsync(2) { + : _api(api), commandAsync("commands", 2) { loadFrom(modules_dir); } diff --git a/src/api/components/OnCallbackQuery.cpp b/src/api/components/OnCallbackQuery.cpp index bdad94f6..2f70e55d 100644 --- a/src/api/components/OnCallbackQuery.cpp +++ b/src/api/components/OnCallbackQuery.cpp @@ -20,7 +20,7 @@ void TgBotApiImpl::OnCallbackQueryImpl::onCallbackQuery( } TgBotApiImpl::OnCallbackQueryImpl::OnCallbackQueryImpl(TgBotApiImpl::Ptr api) - : _api(api), queryAsync(2) { + : _api(api), queryAsync("callbackquery", 2) { _api->getEvents().onCallbackQuery([this](TgBot::CallbackQuery::Ptr query) { onCallbackQueryFunction(std::move(query)); }); diff --git a/src/include/api/components/Async.hpp b/src/include/api/components/Async.hpp index 98510ba6..bea32b2f 100644 --- a/src/include/api/components/Async.hpp +++ b/src/include/api/components/Async.hpp @@ -22,11 +22,13 @@ class TgBotApiImpl::Async { std::condition_variable condVariable; // worker thread(s) to consume command queue std::vector threads; + // name, for logging purposes + std::string _name; void threadFunction(); public: - explicit Async(const int count); + explicit Async(std::string name, const int count); ~Async(); NO_COPY_CTOR(Async);