aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdactor
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2024-05-06 14:20:35 +0300
committerlevlam <levlam@telegram.org>2024-05-06 14:20:35 +0300
commit44b548c3075818af24409f561bd0390a84d3a727 (patch)
tree5fb2dc6982614e11dcb50f546395da41fc45b626 /tdactor
parent36ace421b8fbce852935b6c44b3a62a8f0c3824c (diff)
Move common code to a non-template function.
Diffstat (limited to 'tdactor')
-rw-r--r--tdactor/td/actor/impl/Scheduler-decl.h3
-rw-r--r--tdactor/td/actor/impl/Scheduler.cpp9
-rw-r--r--tdactor/td/actor/impl/Scheduler.h10
3 files changed, 16 insertions, 6 deletions
diff --git a/tdactor/td/actor/impl/Scheduler-decl.h b/tdactor/td/actor/impl/Scheduler-decl.h
index a91dd00cf..1f0479c08 100644
--- a/tdactor/td/actor/impl/Scheduler-decl.h
+++ b/tdactor/td/actor/impl/Scheduler-decl.h
@@ -199,6 +199,9 @@ class Scheduler {
void flush_mailbox(ActorInfo *actor_info);
+ void get_actor_sched_id(const ActorInfo *actor_info, int32 &actor_sched_id, bool &on_current_sched,
+ bool &can_send_immediately);
+
template <ActorSendType send_type, class RunFuncT, class EventFuncT>
void send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, const EventFuncT &event_func);
diff --git a/tdactor/td/actor/impl/Scheduler.cpp b/tdactor/td/actor/impl/Scheduler.cpp
index 7a4f944c8..0c821295d 100644
--- a/tdactor/td/actor/impl/Scheduler.cpp
+++ b/tdactor/td/actor/impl/Scheduler.cpp
@@ -301,6 +301,15 @@ void Scheduler::do_event(ActorInfo *actor_info, Event &&event) {
// can't clear event here. It may be already destroyed during destroy_actor
}
+void Scheduler::get_actor_sched_id(const ActorInfo *actor_info, int32 &actor_sched_id, bool &on_current_sched,
+ bool &can_send_immediately) {
+ 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;
+ CHECK(has_guard_ || !on_current_sched);
+ can_send_immediately = on_current_sched && !actor_info->is_running() && actor_info->mailbox_.empty();
+}
+
void Scheduler::register_migrated_actor(ActorInfo *actor_info) {
VLOG(actor) << "Register migrated actor " << *actor_info << ", " << tag("actor_count", actor_count_);
actor_count_++;
diff --git a/tdactor/td/actor/impl/Scheduler.h b/tdactor/td/actor/impl/Scheduler.h
index a5d551432..f85fdca64 100644
--- a/tdactor/td/actor/impl/Scheduler.h
+++ b/tdactor/td/actor/impl/Scheduler.h
@@ -186,13 +186,11 @@ void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, c
}
int32 actor_sched_id;
- bool is_migrating;
- std::tie(actor_sched_id, is_migrating) = actor_info->migrate_dest_flag_atomic();
- bool on_current_sched = !is_migrating && sched_id_ == actor_sched_id;
- CHECK(has_guard_ || !on_current_sched);
+ bool on_current_sched;
+ bool can_send_immediately;
+ get_actor_sched_id(actor_info, actor_sched_id, on_current_sched, can_send_immediately);
- if (likely(send_type == ActorSendType::Immediate && on_current_sched && !actor_info->is_running() &&
- actor_info->mailbox_.empty())) { // run immediately
+ if (likely(send_type == ActorSendType::Immediate && can_send_immediately)) { // run immediately
EventGuard guard(this, actor_info);
run_func(actor_info);
} else {