Skip to content

Commit

Permalink
Move common code to a non-template function.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed May 6, 2024
1 parent 36ace42 commit 44b548c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions tdactor/td/actor/impl/Scheduler-decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions tdactor/td/actor/impl/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_++;
Expand Down
10 changes: 4 additions & 6 deletions tdactor/td/actor/impl/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 44b548c

Please sign in to comment.