Skip to content

Commit 44b548c

Browse files
committed
Move common code to a non-template function.
1 parent 36ace42 commit 44b548c

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

tdactor/td/actor/impl/Scheduler-decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ class Scheduler {
199199

200200
void flush_mailbox(ActorInfo *actor_info);
201201

202+
void get_actor_sched_id(const ActorInfo *actor_info, int32 &actor_sched_id, bool &on_current_sched,
203+
bool &can_send_immediately);
204+
202205
template <ActorSendType send_type, class RunFuncT, class EventFuncT>
203206
void send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, const EventFuncT &event_func);
204207

tdactor/td/actor/impl/Scheduler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ void Scheduler::do_event(ActorInfo *actor_info, Event &&event) {
301301
// can't clear event here. It may be already destroyed during destroy_actor
302302
}
303303

304+
void Scheduler::get_actor_sched_id(const ActorInfo *actor_info, int32 &actor_sched_id, bool &on_current_sched,
305+
bool &can_send_immediately) {
306+
bool is_migrating;
307+
std::tie(actor_sched_id, is_migrating) = actor_info->migrate_dest_flag_atomic();
308+
on_current_sched = !is_migrating && sched_id_ == actor_sched_id;
309+
CHECK(has_guard_ || !on_current_sched);
310+
can_send_immediately = on_current_sched && !actor_info->is_running() && actor_info->mailbox_.empty();
311+
}
312+
304313
void Scheduler::register_migrated_actor(ActorInfo *actor_info) {
305314
VLOG(actor) << "Register migrated actor " << *actor_info << ", " << tag("actor_count", actor_count_);
306315
actor_count_++;

tdactor/td/actor/impl/Scheduler.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,11 @@ void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, c
186186
}
187187

188188
int32 actor_sched_id;
189-
bool is_migrating;
190-
std::tie(actor_sched_id, is_migrating) = actor_info->migrate_dest_flag_atomic();
191-
bool on_current_sched = !is_migrating && sched_id_ == actor_sched_id;
192-
CHECK(has_guard_ || !on_current_sched);
189+
bool on_current_sched;
190+
bool can_send_immediately;
191+
get_actor_sched_id(actor_info, actor_sched_id, on_current_sched, can_send_immediately);
193192

194-
if (likely(send_type == ActorSendType::Immediate && on_current_sched && !actor_info->is_running() &&
195-
actor_info->mailbox_.empty())) { // run immediately
193+
if (likely(send_type == ActorSendType::Immediate && can_send_immediately)) { // run immediately
196194
EventGuard guard(this, actor_info);
197195
run_func(actor_info);
198196
} else {

0 commit comments

Comments
 (0)