Make send_later_impl non-template.

This commit is contained in:
levlam 2024-05-06 20:31:30 +03:00
parent 2181783bee
commit a6bfa6327b
3 changed files with 22 additions and 36 deletions

View File

@ -207,13 +207,10 @@ class Scheduler {
void get_actor_sched_id_to_send_immediately(const ActorInfo *actor_info, int32 &actor_sched_id, void get_actor_sched_id_to_send_immediately(const ActorInfo *actor_info, int32 &actor_sched_id,
bool &on_current_sched, bool &can_send_immediately); 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> template <class RunFuncT, class EventFuncT>
void send_immediately_impl(const ActorId<> &actor_id, const RunFuncT &run_func, const EventFuncT &event_func); 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, Event &&event);
void send_later_impl(const ActorId<> &actor_id, const EventFuncT &event_func);
Timestamp run_timeout(); Timestamp run_timeout();
void run_mailbox(); void run_mailbox();

View File

@ -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(); 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, void Scheduler::send_later_impl(const ActorId<> &actor_id, Event &&event) {
bool &on_current_sched) { ActorInfo *actor_info = actor_id.get_actor_info();
if (unlikely(actor_info == nullptr || close_flag_)) {
return;
}
int32 actor_sched_id;
bool is_migrating; bool is_migrating;
std::tie(actor_sched_id, is_migrating) = actor_info->migrate_dest_flag_atomic(); 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); 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) { void Scheduler::register_migrated_actor(ActorInfo *actor_info) {

View File

@ -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> template <class EventT>
void Scheduler::send_lambda_immediately(ActorRef actor_ref, EventT &&func) { void Scheduler::send_lambda_immediately(ActorRef actor_ref, EventT &&func) {
return send_immediately_impl( return send_immediately_impl(
@ -238,11 +220,9 @@ void Scheduler::send_lambda_immediately(ActorRef actor_ref, EventT &&func) {
template <class EventT> template <class EventT>
void Scheduler::send_lambda_later(ActorRef actor_ref, EventT &&func) { 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));
auto event = Event::from_lambda(std::forward<EventT>(func)); event.set_link_token(actor_ref.token());
event.set_link_token(actor_ref.token()); return send_later_impl(actor_ref.get(), std::move(event));
return event;
});
} }
template <class EventT> template <class EventT>
@ -262,11 +242,9 @@ void Scheduler::send_closure_immediately(ActorRef actor_ref, EventT &&closure) {
template <class EventT> template <class EventT>
void Scheduler::send_closure_later(ActorRef actor_ref, EventT &&closure) { 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));
auto event = Event::immediate_closure(std::forward<EventT>(closure)); event.set_link_token(actor_ref.token());
event.set_link_token(actor_ref.token()); return send_later_impl(actor_ref.get(), std::move(event));
return event;
});
} }
inline void Scheduler::send_immediately(ActorRef actor_ref, Event &&event) { inline void Scheduler::send_immediately(ActorRef actor_ref, Event &&event) {
@ -278,7 +256,7 @@ inline void Scheduler::send_immediately(ActorRef actor_ref, Event &&event) {
inline void Scheduler::send_later(ActorRef actor_ref, Event &&event) { inline void Scheduler::send_later(ActorRef actor_ref, Event &&event) {
event.set_link_token(actor_ref.token()); 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) { inline void Scheduler::subscribe(PollableFd fd, PollFlags flags) {