From a6bfa6327b499c326ca03af96dcdca9735746fe0 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 6 May 2024 20:31:30 +0300 Subject: [PATCH] Make send_later_impl non-template. --- tdactor/td/actor/impl/Scheduler-decl.h | 5 +--- tdactor/td/actor/impl/Scheduler.cpp | 17 +++++++++--- tdactor/td/actor/impl/Scheduler.h | 36 +++++--------------------- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/tdactor/td/actor/impl/Scheduler-decl.h b/tdactor/td/actor/impl/Scheduler-decl.h index b9cfe507212d..3aa9f8c3a823 100644 --- a/tdactor/td/actor/impl/Scheduler-decl.h +++ b/tdactor/td/actor/impl/Scheduler-decl.h @@ -207,13 +207,10 @@ class Scheduler { void get_actor_sched_id_to_send_immediately(const ActorInfo *actor_info, int32 &actor_sched_id, bool &on_current_sched, bool &can_send_immediately); - void get_actor_sched_id_to_send_later(const ActorInfo *actor_info, int32 &actor_sched_id, bool &on_current_sched); - template void send_immediately_impl(const ActorId<> &actor_id, const RunFuncT &run_func, const EventFuncT &event_func); - template - void send_later_impl(const ActorId<> &actor_id, const EventFuncT &event_func); + void send_later_impl(const ActorId<> &actor_id, Event &&event); Timestamp run_timeout(); void run_mailbox(); diff --git a/tdactor/td/actor/impl/Scheduler.cpp b/tdactor/td/actor/impl/Scheduler.cpp index 07057f365388..f107602fd79c 100644 --- a/tdactor/td/actor/impl/Scheduler.cpp +++ b/tdactor/td/actor/impl/Scheduler.cpp @@ -310,12 +310,23 @@ void Scheduler::get_actor_sched_id_to_send_immediately(const ActorInfo *actor_in can_send_immediately = on_current_sched && !actor_info->is_running() && actor_info->mailbox_.empty(); } -void Scheduler::get_actor_sched_id_to_send_later(const ActorInfo *actor_info, int32 &actor_sched_id, - bool &on_current_sched) { +void Scheduler::send_later_impl(const ActorId<> &actor_id, Event &&event) { + ActorInfo *actor_info = actor_id.get_actor_info(); + if (unlikely(actor_info == nullptr || close_flag_)) { + return; + } + + int32 actor_sched_id; bool is_migrating; std::tie(actor_sched_id, is_migrating) = actor_info->migrate_dest_flag_atomic(); - on_current_sched = !is_migrating && sched_id_ == actor_sched_id; + bool on_current_sched = !is_migrating && sched_id_ == actor_sched_id; CHECK(has_guard_ || !on_current_sched); + + if (on_current_sched) { + add_to_mailbox(actor_info, std::move(event)); + } else { + send_to_scheduler(actor_sched_id, actor_id, std::move(event)); + } } void Scheduler::register_migrated_actor(ActorInfo *actor_info) { diff --git a/tdactor/td/actor/impl/Scheduler.h b/tdactor/td/actor/impl/Scheduler.h index 55ed5a2d37ed..075adbaacedb 100644 --- a/tdactor/td/actor/impl/Scheduler.h +++ b/tdactor/td/actor/impl/Scheduler.h @@ -203,24 +203,6 @@ void Scheduler::send_immediately_impl(const ActorId<> &actor_id, const RunFuncT } } -template -void Scheduler::send_later_impl(const ActorId<> &actor_id, const EventFuncT &event_func) { - ActorInfo *actor_info = actor_id.get_actor_info(); - if (unlikely(actor_info == nullptr || close_flag_)) { - return; - } - - int32 actor_sched_id; - bool on_current_sched; - get_actor_sched_id_to_send_later(actor_info, actor_sched_id, on_current_sched); - - if (on_current_sched) { - add_to_mailbox(actor_info, event_func()); - } else { - send_to_scheduler(actor_sched_id, actor_id, event_func()); - } -} - template void Scheduler::send_lambda_immediately(ActorRef actor_ref, EventT &&func) { return send_immediately_impl( @@ -238,11 +220,9 @@ void Scheduler::send_lambda_immediately(ActorRef actor_ref, EventT &&func) { template void Scheduler::send_lambda_later(ActorRef actor_ref, EventT &&func) { - return send_later_impl(actor_ref.get(), [&] { - auto event = Event::from_lambda(std::forward(func)); - event.set_link_token(actor_ref.token()); - return event; - }); + auto event = Event::from_lambda(std::forward(func)); + event.set_link_token(actor_ref.token()); + return send_later_impl(actor_ref.get(), std::move(event)); } template @@ -262,11 +242,9 @@ void Scheduler::send_closure_immediately(ActorRef actor_ref, EventT &&closure) { template void Scheduler::send_closure_later(ActorRef actor_ref, EventT &&closure) { - return send_later_impl(actor_ref.get(), [&] { - auto event = Event::immediate_closure(std::forward(closure)); - event.set_link_token(actor_ref.token()); - return event; - }); + auto event = Event::immediate_closure(std::forward(closure)); + event.set_link_token(actor_ref.token()); + return send_later_impl(actor_ref.get(), std::move(event)); } inline void Scheduler::send_immediately(ActorRef actor_ref, Event &&event) { @@ -278,7 +256,7 @@ inline void Scheduler::send_immediately(ActorRef actor_ref, Event &&event) { inline void Scheduler::send_later(ActorRef actor_ref, Event &&event) { event.set_link_token(actor_ref.token()); - return send_later_impl(actor_ref.get(), [&] { return std::move(event); }); + return send_later_impl(actor_ref.get(), std::move(event)); } inline void Scheduler::subscribe(PollableFd fd, PollFlags flags) {