diff --git a/telegram-bot-api/ClientParameters.h b/telegram-bot-api/ClientParameters.h index b22031d..b8558f9 100644 --- a/telegram-bot-api/ClientParameters.h +++ b/telegram-bot-api/ClientParameters.h @@ -93,9 +93,14 @@ struct SharedData { return 10; } - static td::int32 get_thread_count() { + static td::int32 get_statistics_thread_id() { + // the thread for CPU usage updating return 11; } + + static td::int32 get_thread_count() { + return 12; + } }; struct ClientParameters { diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 08bafb8..a942534 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -556,7 +556,9 @@ int main(int argc, char *argv[]) { next_cron_time = now; } next_cron_time += 1.0; - ServerCpuStat::update(now); + auto guard = sched.get_main_guard(); + td::Scheduler::instance()->run_on_scheduler(SharedData::get_statistics_thread_id(), + [](td::Unit) { ServerCpuStat::update(td::Time::now()); }); } if (now >= start_time + 600) {