Move common code to a non-template function.

This commit is contained in:
levlam 2024-05-06 14:20:35 +03:00
parent 36ace421b8
commit 44b548c307
3 changed files with 16 additions and 6 deletions

View File

@ -199,6 +199,9 @@ class Scheduler {
void flush_mailbox(ActorInfo *actor_info); 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> template <ActorSendType send_type, class RunFuncT, class EventFuncT>
void send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, const EventFuncT &event_func); void send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, const EventFuncT &event_func);

View File

@ -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 // 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) { void Scheduler::register_migrated_actor(ActorInfo *actor_info) {
VLOG(actor) << "Register migrated actor " << *actor_info << ", " << tag("actor_count", actor_count_); VLOG(actor) << "Register migrated actor " << *actor_info << ", " << tag("actor_count", actor_count_);
actor_count_++; actor_count_++;

View File

@ -186,13 +186,11 @@ void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, c
} }
int32 actor_sched_id; int32 actor_sched_id;
bool is_migrating; bool on_current_sched;
std::tie(actor_sched_id, is_migrating) = actor_info->migrate_dest_flag_atomic(); bool can_send_immediately;
bool on_current_sched = !is_migrating && sched_id_ == actor_sched_id; get_actor_sched_id(actor_info, actor_sched_id, on_current_sched, can_send_immediately);
CHECK(has_guard_ || !on_current_sched);
if (likely(send_type == ActorSendType::Immediate && on_current_sched && !actor_info->is_running() && if (likely(send_type == ActorSendType::Immediate && can_send_immediately)) { // run immediately
actor_info->mailbox_.empty())) { // run immediately
EventGuard guard(this, actor_info); EventGuard guard(this, actor_info);
run_func(actor_info); run_func(actor_info);
} else { } else {