From 06731d965d7815f87a6bb707f3262e84fee66ed6 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 26 Jul 2023 13:05:34 +0300 Subject: [PATCH] Move get_database_scheduler_id to Global. --- td/telegram/Global.cpp | 7 +++++-- td/telegram/Global.h | 5 +++++ td/telegram/Td.cpp | 8 +------- td/telegram/Td.h | 2 -- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/td/telegram/Global.cpp b/td/telegram/Global.cpp index dacaaef86..05dc8acec 100644 --- a/td/telegram/Global.cpp +++ b/td/telegram/Global.cpp @@ -86,8 +86,11 @@ struct ServerTimeDiff { }; Status Global::init(ActorId td, unique_ptr td_db_ptr) { - gc_scheduler_id_ = min(Scheduler::instance()->sched_id() + 2, Scheduler::instance()->sched_count() - 1); - slow_net_scheduler_id_ = min(Scheduler::instance()->sched_id() + 3, Scheduler::instance()->sched_count() - 1); + auto current_scheduler_id = Scheduler::instance()->sched_id(); + auto max_scheduler_id = Scheduler::instance()->sched_count() - 1; + database_scheduler_id_ = min(current_scheduler_id + 1, max_scheduler_id); + gc_scheduler_id_ = min(current_scheduler_id + 2, max_scheduler_id); + slow_net_scheduler_id_ = min(current_scheduler_id + 3, max_scheduler_id); td_ = td; td_db_ = std::move(td_db_ptr); diff --git a/td/telegram/Global.h b/td/telegram/Global.h index 912cd0922..d0e2f67ff 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -418,6 +418,10 @@ class Global final : public ActorContext { return use_file_database(); } + int32 get_database_scheduler_id() { + return database_scheduler_id_; + } + int32 get_gc_scheduler_id() const { return gc_scheduler_id_; } @@ -542,6 +546,7 @@ class Global final : public ActorContext { OptionManager *option_manager_ = nullptr; + int32 database_scheduler_id_ = 0; int32 gc_scheduler_id_ = 0; int32 slow_net_scheduler_id_ = 0; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index e5d40a3d1..80afe0acf 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2985,7 +2985,7 @@ void Td::run_request(uint64 id, tl_object_ptr function) { Result r_opened_database) mutable { send_closure(actor_id, &Td::init, std::move(parameters), std::move(r_opened_database)); }); - return TdDb::open(get_database_scheduler_id(), std::move(parameters.second), std::move(promise)); + return TdDb::open(G()->get_database_scheduler_id(), std::move(parameters.second), std::move(promise)); } default: if (is_preinitialization_request(function_id)) { @@ -3549,12 +3549,6 @@ void Td::complete_pending_preauthentication_requests(const T &func) { } } -int32 Td::get_database_scheduler_id() { - auto current_scheduler_id = Scheduler::instance()->sched_id(); - auto scheduler_count = Scheduler::instance()->sched_count(); - return min(current_scheduler_id + 1, scheduler_count - 1); -} - void Td::finish_set_parameters() { CHECK(set_parameters_request_id_ != 0); set_parameters_request_id_ = 0; diff --git a/td/telegram/Td.h b/td/telegram/Td.h index ec6bcac0a..3afd1b8c8 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1692,8 +1692,6 @@ class Td final : public Actor { static DbKey as_db_key(string key); - static int32 get_database_scheduler_id(); - struct Parameters { int32 api_id_ = 0; string api_hash_;