From 4cf1e02479f5eb0d2f30cbc39c5397a165c37bce Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 22 Jul 2022 21:21:30 +0300 Subject: [PATCH] Add multiarg version of Scheduler::destroy_on_scheduler. --- td/telegram/ContactsManager.cpp | 47 ++++++-------------------- td/telegram/MessagesManager.cpp | 38 ++++++--------------- td/telegram/PollManager.cpp | 7 ++-- td/telegram/StickersManager.cpp | 16 +++------ td/telegram/VoiceNotesManager.cpp | 5 ++- td/telegram/WebPagesManager.cpp | 7 ++-- td/telegram/files/FileManager.cpp | 11 ++---- tdactor/td/actor/impl/Scheduler-decl.h | 3 ++ tdactor/td/actor/impl/Scheduler.h | 7 ++++ 9 files changed, 43 insertions(+), 98 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 12b14ae82..83fea9a95 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -3398,43 +3398,16 @@ ContactsManager::ContactsManager(Td *td, ActorShared<> parent) : td_(td), parent } ContactsManager::~ContactsManager() { - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), users_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), users_full_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), user_photos_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), unknown_users_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), pending_user_photos_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), user_profile_photo_file_source_ids_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), my_photo_file_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), chats_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), chats_full_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), unknown_chats_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), chat_full_file_source_ids_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), min_channels_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), channels_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), channels_full_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), unknown_channels_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), invalidated_channels_full_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), channel_full_file_source_ids_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), secret_chats_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), unknown_secret_chats_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), secret_chats_with_user_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), invite_link_infos_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), dialog_access_by_invite_link_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), loaded_from_database_users_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), unavailable_user_fulls_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), loaded_from_database_chats_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), unavailable_chat_fulls_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), loaded_from_database_channels_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), unavailable_channel_fulls_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), loaded_from_database_secret_chats_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), dialog_administrators_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), cached_channel_participants_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), resolved_phone_numbers_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), channel_participants_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), all_imported_contacts_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), linked_channel_ids_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), restricted_user_ids_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), restricted_channel_ids_); + Scheduler::instance()->destroy_on_scheduler( + G()->get_gc_scheduler_id(), users_, users_full_, user_photos_, unknown_users_, pending_user_photos_, + user_profile_photo_file_source_ids_, my_photo_file_id_, chats_, chats_full_, unknown_chats_, + chat_full_file_source_ids_, min_channels_, channels_, channels_full_, unknown_channels_, + invalidated_channels_full_, channel_full_file_source_ids_, secret_chats_, unknown_secret_chats_, + secret_chats_with_user_, invite_link_infos_, dialog_access_by_invite_link_, loaded_from_database_users_, + unavailable_user_fulls_, loaded_from_database_chats_, unavailable_chat_fulls_, loaded_from_database_channels_, + unavailable_channel_fulls_, loaded_from_database_secret_chats_, dialog_administrators_, + cached_channel_participants_, resolved_phone_numbers_, channel_participants_, all_imported_contacts_, + linked_channel_ids_, restricted_user_ids_, restricted_channel_ids_); } void ContactsManager::tear_down() { diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 883aa5b8f..410c1895c 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5809,34 +5809,16 @@ MessagesManager::MessagesManager(Td *td, ActorShared<> parent) } MessagesManager::~MessagesManager() { - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), ttl_nodes_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), ttl_heap_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), being_sent_messages_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), update_message_ids_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), update_scheduled_message_ids_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), message_id_to_dialog_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), last_clear_history_message_id_to_dialog_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), dialogs_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), postponed_chat_read_inbox_updates_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), found_public_dialogs_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), found_on_server_dialogs_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), found_common_dialogs_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), message_embedding_codes_[0]); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), message_embedding_codes_[1]); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), replied_by_media_timestamp_messages_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), notification_group_id_to_dialog_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), active_get_channel_differencies_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), get_channel_difference_to_log_event_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), channel_get_difference_retry_timeouts_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), is_channel_difference_finished_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), resolved_usernames_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), inaccessible_resolved_usernames_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), dialog_bot_command_message_ids_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), full_message_id_to_file_source_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), last_outgoing_forwarded_message_date_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), dialog_viewed_messages_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), dialog_online_member_counts_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), previous_repaired_read_inbox_max_message_id_); + Scheduler::instance()->destroy_on_scheduler( + G()->get_gc_scheduler_id(), ttl_nodes_, ttl_heap_, being_sent_messages_, update_message_ids_, + update_scheduled_message_ids_, message_id_to_dialog_id_, last_clear_history_message_id_to_dialog_id_, dialogs_, + postponed_chat_read_inbox_updates_, found_public_dialogs_, found_on_server_dialogs_, found_common_dialogs_, + message_embedding_codes_[0], message_embedding_codes_[1], replied_by_media_timestamp_messages_, + notification_group_id_to_dialog_id_, active_get_channel_differencies_, get_channel_difference_to_log_event_id_, + channel_get_difference_retry_timeouts_, is_channel_difference_finished_, resolved_usernames_, + inaccessible_resolved_usernames_, dialog_bot_command_message_ids_, full_message_id_to_file_source_id_, + last_outgoing_forwarded_message_date_, dialog_viewed_messages_, dialog_online_member_counts_, + previous_repaired_read_inbox_max_message_id_); } void MessagesManager::on_channel_get_difference_timeout_callback(void *messages_manager_ptr, int64 dialog_id_int) { diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index 341d8c613..16875f7b0 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -266,11 +266,8 @@ void PollManager::tear_down() { } PollManager::~PollManager() { - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), polls_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), server_poll_messages_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), other_poll_messages_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), poll_voters_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), loaded_from_database_polls_); + Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), polls_, server_poll_messages_, + other_poll_messages_, poll_voters_, loaded_from_database_polls_); } void PollManager::on_update_poll_timeout_callback(void *poll_manager_ptr, int64 poll_id_int) { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 820e15a74..02b422d0b 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1305,18 +1305,10 @@ StickersManager::StickersManager(Td *td, ActorShared<> parent) : td_(td), parent } StickersManager::~StickersManager() { - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), stickers_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), sticker_sets_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), short_name_to_sticker_set_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), attached_sticker_sets_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), found_stickers_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), found_sticker_sets_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), emoji_language_codes_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), emoji_language_code_versions_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), emoji_language_code_last_difference_times_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), reloaded_emoji_keywords_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), dice_messages_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), emoji_messages_); + Scheduler::instance()->destroy_on_scheduler( + G()->get_gc_scheduler_id(), stickers_, sticker_sets_, short_name_to_sticker_set_id_, attached_sticker_sets_, + found_stickers_, found_sticker_sets_, emoji_language_codes_, emoji_language_code_versions_, + emoji_language_code_last_difference_times_, reloaded_emoji_keywords_, dice_messages_, emoji_messages_); } void StickersManager::start_up() { diff --git a/td/telegram/VoiceNotesManager.cpp b/td/telegram/VoiceNotesManager.cpp index 593e0b3e0..fddd8dd00 100644 --- a/td/telegram/VoiceNotesManager.cpp +++ b/td/telegram/VoiceNotesManager.cpp @@ -101,9 +101,8 @@ VoiceNotesManager::VoiceNotesManager(Td *td, ActorShared<> parent) : td_(td), pa } VoiceNotesManager::~VoiceNotesManager() { - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), voice_notes_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), voice_note_messages_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), message_voice_notes_); + Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), voice_notes_, voice_note_messages_, + message_voice_notes_); } void VoiceNotesManager::tear_down() { diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 28dda3bce..ccaa0885b 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -418,11 +418,8 @@ void WebPagesManager::tear_down() { } WebPagesManager::~WebPagesManager() { - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), web_pages_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), web_page_messages_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), got_web_page_previews_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), url_to_web_page_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), url_to_file_source_id_); + Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), web_pages_, web_page_messages_, + got_web_page_previews_, url_to_web_page_id_, url_to_file_source_id_); } WebPageId WebPagesManager::on_get_web_page(tl_object_ptr &&web_page_ptr, diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index b80146d56..6dcc7cd37 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -840,14 +840,9 @@ void FileManager::init_actor() { } FileManager::~FileManager() { - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), remote_location_info_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), file_hash_to_file_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), local_location_to_file_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), generate_location_to_file_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), pmc_id_to_file_node_id_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), file_id_info_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), empty_file_ids_); - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), file_nodes_); + Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), remote_location_info_, file_hash_to_file_id_, + local_location_to_file_id_, generate_location_to_file_id_, + pmc_id_to_file_node_id_, file_id_info_, empty_file_ids_, file_nodes_); } string FileManager::fix_file_extension(Slice file_name, Slice file_type, Slice file_extension) { diff --git a/tdactor/td/actor/impl/Scheduler-decl.h b/tdactor/td/actor/impl/Scheduler-decl.h index 57f49dbb4..a8ec2aaa9 100644 --- a/tdactor/td/actor/impl/Scheduler-decl.h +++ b/tdactor/td/actor/impl/Scheduler-decl.h @@ -105,6 +105,9 @@ class Scheduler { template void destroy_on_scheduler(int32 sched_id, T &value); + template + void destroy_on_scheduler(int32 sched_id, ArgsT &...values); + template void send_lambda(ActorRef actor_ref, EventT &&lambda); diff --git a/tdactor/td/actor/impl/Scheduler.h b/tdactor/td/actor/impl/Scheduler.h index 182066145..4319dc2c2 100644 --- a/tdactor/td/actor/impl/Scheduler.h +++ b/tdactor/td/actor/impl/Scheduler.h @@ -179,6 +179,13 @@ inline void Scheduler::destroy_on_scheduler(int32 sched_id, T &value) { } } +template +inline void Scheduler::destroy_on_scheduler(int32 sched_id, ArgsT &...values) { + destroy_on_scheduler_impl(sched_id, PromiseCreator::lambda([values = std::make_tuple(std::move(values)...)](Unit) { + // destroy values + })); +} + inline void Scheduler::before_tail_send(const ActorId<> &actor_id) { // TODO }