Skip to content

Commit

Permalink
Make send_later_impl non-template.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed May 6, 2024
1 parent 2181783 commit a6bfa63
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
5 changes: 1 addition & 4 deletions tdactor/td/actor/impl/Scheduler-decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class RunFuncT, class EventFuncT>
void send_immediately_impl(const ActorId<> &actor_id, const RunFuncT &run_func, const EventFuncT &event_func);

template <class EventFuncT>
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();
Expand Down
17 changes: 14 additions & 3 deletions tdactor/td/actor/impl/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
36 changes: 7 additions & 29 deletions tdactor/td/actor/impl/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,24 +203,6 @@ void Scheduler::send_immediately_impl(const ActorId<> &actor_id, const RunFuncT
}
}

template <class EventFuncT>
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 <class EventT>
void Scheduler::send_lambda_immediately(ActorRef actor_ref, EventT &&func) {
return send_immediately_impl(
Expand All @@ -238,11 +220,9 @@ void Scheduler::send_lambda_immediately(ActorRef actor_ref, EventT &&func) {

template <class EventT>
void Scheduler::send_lambda_later(ActorRef actor_ref, EventT &&func) {
return send_later_impl(actor_ref.get(), [&] {
auto event = Event::from_lambda(std::forward<EventT>(func));
event.set_link_token(actor_ref.token());
return event;
});
auto event = Event::from_lambda(std::forward<EventT>(func));
event.set_link_token(actor_ref.token());
return send_later_impl(actor_ref.get(), std::move(event));
}

template <class EventT>
Expand All @@ -262,11 +242,9 @@ void Scheduler::send_closure_immediately(ActorRef actor_ref, EventT &&closure) {

template <class EventT>
void Scheduler::send_closure_later(ActorRef actor_ref, EventT &&closure) {
return send_later_impl(actor_ref.get(), [&] {
auto event = Event::immediate_closure(std::forward<EventT>(closure));
event.set_link_token(actor_ref.token());
return event;
});
auto event = Event::immediate_closure(std::forward<EventT>(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) {
Expand All @@ -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) {
Expand Down

0 comments on commit a6bfa63

Please sign in to comment.