From 7627dc27a7f6ee09b804809374d3d7da2899abe9 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 12 Dec 2018 02:48:56 +0300 Subject: [PATCH] Give different names to MultiPromise actors. GitOrigin-RevId: 4277553637ca342bc80af07ddcdf013eec506221 --- td/telegram/ContactsManager.cpp | 2 +- td/telegram/ContactsManager.h | 4 ++-- td/telegram/InlineQueriesManager.h | 2 +- td/telegram/MessagesManager.cpp | 18 +++++++++--------- td/telegram/MessagesManager.h | 7 ++++--- td/telegram/SecretChatActor.cpp | 2 +- td/telegram/StickersManager.h | 3 +-- td/telegram/TdDb.cpp | 2 +- tdactor/td/actor/MultiPromise.cpp | 3 --- tdactor/td/actor/MultiPromise.h | 17 ++++++----------- tdactor/test/actors_simple.cpp | 4 ++-- 11 files changed, 28 insertions(+), 36 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 92409e08e..1c44e1324 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -9151,7 +9151,7 @@ void ContactsManager::on_load_dialog_administrators_from_database(DialogId dialo LOG(INFO) << "Successfully loaded " << user_ids.size() << " administrators in " << dialog_id << " from database"; - MultiPromiseActorSafe load_users_multipromise; + MultiPromiseActorSafe load_users_multipromise{"LoadUsersMultiPromiseActor"}; load_users_multipromise.add_promise( PromiseCreator::lambda([dialog_id, user_ids, promise = std::move(promise)](Result<> result) mutable { send_closure(G()->contacts_manager(), &ContactsManager::on_load_administrator_users_finished, dialog_id, diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index c0655bb63..52dd11320 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1099,7 +1099,7 @@ class ContactsManager : public Actor { int32 next_contacts_sync_date_ = 0; Hints contacts_hints_; // search contacts by first name, last name and username vector> load_contacts_queries_; - MultiPromiseActor load_contact_users_multipromise_; + MultiPromiseActor load_contact_users_multipromise_{"LoadContactUsersMultiPromiseActor"}; int32 saved_contact_count_ = -1; int32 was_online_local_ = 0; @@ -1107,7 +1107,7 @@ class ContactsManager : public Actor { bool are_imported_contacts_loaded_ = false; vector> load_imported_contacts_queries_; - MultiPromiseActor load_imported_contact_users_multipromise_; + MultiPromiseActor load_imported_contact_users_multipromise_{"LoadImportedContactUsersMultiPromiseActor"}; vector all_imported_contacts_; bool are_imported_contacts_changing_ = false; bool need_clear_imported_contacts_ = false; diff --git a/td/telegram/InlineQueriesManager.h b/td/telegram/InlineQueriesManager.h index b76cd89a6..10b917a10 100644 --- a/td/telegram/InlineQueriesManager.h +++ b/td/telegram/InlineQueriesManager.h @@ -118,7 +118,7 @@ class InlineQueriesManager : public Actor { void tear_down() override; int32 recently_used_bots_loaded_ = 0; // 0 - not loaded, 1 - load request was sent, 2 - loaded - MultiPromiseActor resolve_recent_inline_bots_multipromise_; + MultiPromiseActor resolve_recent_inline_bots_multipromise_{"ResolveRecentInlineBotsMultiPromiseActor"}; vector recently_used_bot_user_ids_; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 4f04258c7..79cc846b1 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -21357,7 +21357,7 @@ void MessagesManager::do_delete_message_logevent(const DeleteMessageLogEvent &lo logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessage, storer); } - MultiPromiseActorSafe mpas; + MultiPromiseActorSafe mpas{"DeleteMessageMultiPromiseActor"}; mpas.add_promise(PromiseCreator::lambda([logevent_id](Result result) { if (result.is_error()) { return; @@ -23799,7 +23799,7 @@ bool MessagesManager::load_recently_found_dialogs(Promise &promise) { } auto found_dialogs = full_split(found_dialogs_str, ','); - if (recently_found_dialogs_loaded_ == 1 && resolve_recent_found_dialogs_multipromise_.promise_count() == 0) { + if (recently_found_dialogs_loaded_ == 1 && resolve_recently_found_dialogs_multipromise_.promise_count() == 0) { // queries was sent and have already been finished auto newly_found_dialogs = std::move(recently_found_dialog_ids_); recently_found_dialog_ids_.clear(); @@ -23830,15 +23830,15 @@ bool MessagesManager::load_recently_found_dialogs(Promise &promise) { return true; } - resolve_recent_found_dialogs_multipromise_.add_promise(std::move(promise)); + resolve_recently_found_dialogs_multipromise_.add_promise(std::move(promise)); if (recently_found_dialogs_loaded_ == 0) { recently_found_dialogs_loaded_ = 1; - resolve_recent_found_dialogs_multipromise_.set_ignore_errors(true); + resolve_recently_found_dialogs_multipromise_.set_ignore_errors(true); for (auto &found_dialog : found_dialogs) { if (found_dialog[0] == '@') { - search_public_dialog(found_dialog, false, resolve_recent_found_dialogs_multipromise_.get_promise()); + search_public_dialog(found_dialog, false, resolve_recently_found_dialogs_multipromise_.get_promise()); } } if (G()->parameters().use_message_db) { @@ -23847,14 +23847,14 @@ bool MessagesManager::load_recently_found_dialogs(Promise &promise) { auto dialog_id = DialogId(to_integer(found_dialog)); CHECK(dialog_id.is_valid()); // TODO use asynchronous load - // get_dialog(dialog_id, resolve_recent_found_dialogs_multipromise_.get_promise()); + // get_dialog(dialog_id, resolve_recently_found_dialogs_multipromise_.get_promise()); get_dialog_force(dialog_id); } } - resolve_recent_found_dialogs_multipromise_.get_promise().set_value(Unit()); + resolve_recently_found_dialogs_multipromise_.get_promise().set_value(Unit()); } else { - get_dialogs(MIN_DIALOG_DATE, MAX_GET_DIALOGS, false, resolve_recent_found_dialogs_multipromise_.get_promise()); - td_->contacts_manager_->search_contacts("", 1, resolve_recent_found_dialogs_multipromise_.get_promise()); + get_dialogs(MIN_DIALOG_DATE, MAX_GET_DIALOGS, false, resolve_recently_found_dialogs_multipromise_.get_promise()); + td_->contacts_manager_->search_contacts("", 1, resolve_recently_found_dialogs_multipromise_.get_promise()); } } return false; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 08e255b3f..f3ee75a63 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1125,7 +1125,7 @@ class MessagesManager : public Actor { struct PendingSecretMessage { MessageInfo message_info; - MultiPromiseActor load_data_multipromise; + MultiPromiseActor load_data_multipromise{"LoadPendingSecretMessageDataMultiPromiseActor"}; Promise<> success_promise; }; @@ -1980,7 +1980,7 @@ class MessagesManager : public Actor { bool is_broadcast_channel(DialogId dialog_id) const; int32 recently_found_dialogs_loaded_ = 0; // 0 - not loaded, 1 - load request was sent, 2 - loaded - MultiPromiseActor resolve_recent_found_dialogs_multipromise_; + MultiPromiseActor resolve_recently_found_dialogs_multipromise_{"ResolveRecentlyFoundDialogsMultiPromiseActor"}; vector recently_found_dialog_ids_; @@ -2171,7 +2171,8 @@ class MessagesManager : public Actor { DialogDate last_loaded_database_dialog_date_ = MIN_DIALOG_DATE; DialogDate last_database_server_dialog_date_ = MIN_DIALOG_DATE; - MultiPromiseActor load_dialog_list_multipromise_; // should be defined before pending_on_get_dialogs_ + MultiPromiseActor load_dialog_list_multipromise_{ + "LoadDialogListMultiPromiseActor"}; // should be defined before pending_on_get_dialogs_ Timeout preload_dialog_list_timeout_; std::unordered_map active_get_channel_differencies_; diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index 627c64a80..6c3f714a3 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -1328,7 +1328,7 @@ Status SecretChatActor::do_inbound_message_decrypted(unique_ptron_read_message(random_ids[0], std::move(save_message_finish)); } else { // probably never happens - MultiPromiseActorSafe mpas; + MultiPromiseActorSafe mpas{"ReadSecretMessagesMultiPromiseActor"}; mpas.add_promise(std::move(save_message_finish)); auto lock = mpas.get_promise(); for (auto random_id : random_ids) { diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index 9ff75584d..c584e9c9a 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -30,7 +30,6 @@ #include namespace td { -class MultiPromiseActor; class Td; } // namespace td @@ -274,7 +273,7 @@ class StickersManager : public Actor { }; struct PendingNewStickerSet { - MultiPromiseActor upload_files_multipromise; + MultiPromiseActor upload_files_multipromise{"UploadNewStickerSetFilesMultiPromiseActor"}; UserId user_id; string title; string short_name; diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index 5bd515150..507ffcd5f 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -193,7 +193,7 @@ void TdDb::close_and_destroy_all(Promise<> on_finished) { do_close(std::move(on_finished), true /*destroy_flag*/); } void TdDb::do_close(Promise<> on_finished, bool destroy_flag) { - MultiPromiseActorSafe mpas; + MultiPromiseActorSafe mpas{"TdDbCloseMultiPromiseActor"}; mpas.add_promise(PromiseCreator::lambda( [promise = std::move(on_finished), sql_connection = std::move(sql_connection_), destroy_flag](Unit) mutable { if (sql_connection) { diff --git a/tdactor/td/actor/MultiPromise.cpp b/tdactor/td/actor/MultiPromise.cpp index 9000cfeca..3335cd3f7 100644 --- a/tdactor/td/actor/MultiPromise.cpp +++ b/tdactor/td/actor/MultiPromise.cpp @@ -13,9 +13,6 @@ void MultiPromiseActor::add_promise(Promise &&promise) { } Promise MultiPromiseActor::get_promise() { - if (empty()) { - register_actor("MultiPromise", this).release(); - } CHECK(!promises_.empty()); PromiseActor promise; diff --git a/tdactor/td/actor/MultiPromise.h b/tdactor/td/actor/MultiPromise.h index d5786c3dd..c73803826 100644 --- a/tdactor/td/actor/MultiPromise.h +++ b/tdactor/td/actor/MultiPromise.h @@ -41,7 +41,6 @@ class MultiPromise : public MultiPromiseInterface { return impl_->get_promise(); } - // deprecated? size_t promise_count() const override { return impl_->promise_count(); } @@ -61,7 +60,9 @@ class MultiPromiseActor final : public Actor , public MultiPromiseInterface { public: - MultiPromiseActor() = default; + MultiPromiseActor(Slice name) { + register_actor(name, this).release(); + } void add_promise(Promise &&promise) override; @@ -95,7 +96,8 @@ class MultiPromiseActorSafe : public MultiPromiseInterface { Promise get_promise() override; void set_ignore_errors(bool ignore_errors) override; size_t promise_count() const override; - MultiPromiseActorSafe() = default; + explicit MultiPromiseActorSafe(Slice name) : multi_promise_(make_unique(name)) { + } MultiPromiseActorSafe(const MultiPromiseActorSafe &other) = delete; MultiPromiseActorSafe &operator=(const MultiPromiseActorSafe &other) = delete; MultiPromiseActorSafe(MultiPromiseActorSafe &&other) = delete; @@ -103,14 +105,7 @@ class MultiPromiseActorSafe : public MultiPromiseInterface { ~MultiPromiseActorSafe() override; private: - unique_ptr multi_promise_ = make_unique(); -}; - -class MultiPromiseCreator { - public: - static MultiPromise create() { - return MultiPromise(make_unique()); - } + unique_ptr multi_promise_; }; } // namespace td diff --git a/tdactor/test/actors_simple.cpp b/tdactor/test/actors_simple.cpp index a43ff3780..d8981c53a 100644 --- a/tdactor/test/actors_simple.cpp +++ b/tdactor/test/actors_simple.cpp @@ -517,7 +517,7 @@ class MultiPromise2 : public Actor { Scheduler::instance()->finish(); }); - MultiPromiseActorSafe multi_promise; + MultiPromiseActorSafe multi_promise{"MultiPromiseActor2"}; multi_promise.add_promise(std::move(promise)); for (int i = 0; i < 10; i++) { create_actor("Sleep", 0.1, multi_promise.get_promise()).release(); @@ -532,7 +532,7 @@ class MultiPromise1 : public Actor { CHECK(result.is_error()); create_actor("B").release(); }); - MultiPromiseActorSafe multi_promise; + MultiPromiseActorSafe multi_promise{"MultiPromiseActor1"}; multi_promise.add_promise(std::move(promise)); } };