diff --git a/td/telegram/Global.cpp b/td/telegram/Global.cpp index 6ea02ded..348073cd 100644 --- a/td/telegram/Global.cpp +++ b/td/telegram/Global.cpp @@ -61,16 +61,16 @@ void Global::set_mtproto_header(unique_ptr mtproto_header) { mtproto_header_ = std::move(mtproto_header); } -Status Global::init(const TdParameters ¶meters, ActorId td, unique_ptr td_db) { +Status Global::init(const TdParameters ¶meters, ActorId td, unique_ptr td_db_ptr) { parameters_ = parameters; 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); td_ = td; - td_db_ = std::move(td_db); + td_db_ = std::move(td_db_ptr); - string save_diff_str = this->td_db()->get_binlog_pmc()->get("server_time_difference"); + string save_diff_str = td_db()->get_binlog_pmc()->get("server_time_difference"); if (save_diff_str.empty()) { server_time_difference_ = Clocks::system() - Time::now(); server_time_difference_was_updated_ = false; diff --git a/td/telegram/Global.h b/td/telegram/Global.h index 5314f06f..6a6dbab1 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -19,6 +19,7 @@ #include "td/net/NetStats.h" #include "td/utils/common.h" +#include "td/utils/logging.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/Time.h" @@ -67,14 +68,15 @@ class Global : public ActorContext { Global(Global &&other) = delete; Global &operator=(Global &&other) = delete; - TdDb *td_db() { - CHECK(td_db_); +#define td_db() get_td_db_impl(__FILE__, __LINE__) + TdDb *get_td_db_impl(const char *file, int line) { + LOG_CHECK(td_db_) << close_flag() << " " << file << " " << line; return td_db_.get(); } void close_all(Promise<> on_finished); void close_and_destroy_all(Promise<> on_finished); - Status init(const TdParameters ¶meters, ActorId td, unique_ptr td_db) TD_WARN_UNUSED_RESULT; + Status init(const TdParameters ¶meters, ActorId td, unique_ptr td_db_ptr) TD_WARN_UNUSED_RESULT; Slice get_dir() const { return parameters_.database_directory;