Remove legacy parameters in Scheduler::flush_mailbox.

This commit is contained in:
levlam 2024-02-17 21:42:51 +03:00
parent b6b5b1b9ed
commit 516e2e8a07
3 changed files with 14 additions and 23 deletions

View File

@ -194,8 +194,7 @@ class Scheduler {
void add_to_mailbox(ActorInfo *actor_info, Event &&event); void add_to_mailbox(ActorInfo *actor_info, Event &&event);
void clear_mailbox(ActorInfo *actor_info); void clear_mailbox(ActorInfo *actor_info);
template <class RunFuncT, class EventFuncT> void flush_mailbox(ActorInfo *actor_info);
void flush_mailbox(ActorInfo *actor_info, const RunFuncT &run_func, const EventFuncT &event_func);
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

@ -493,6 +493,18 @@ void Scheduler::run_poll(Timestamp timeout) {
#endif #endif
} }
void Scheduler::flush_mailbox(ActorInfo *actor_info) {
auto &mailbox = actor_info->mailbox_;
size_t mailbox_size = mailbox.size();
CHECK(mailbox_size != 0);
EventGuard guard(this, actor_info);
size_t i = 0;
for (; i < mailbox_size && guard.can_run(); i++) {
do_event(actor_info, std::move(mailbox[i]));
}
mailbox.erase(mailbox.begin(), mailbox.begin() + i);
}
void Scheduler::run_mailbox() { void Scheduler::run_mailbox() {
VLOG(actor) << "Run mailbox : begin"; VLOG(actor) << "Run mailbox : begin";
ListNode actors_list = std::move(ready_actors_list_); ListNode actors_list = std::move(ready_actors_list_);
@ -500,7 +512,7 @@ void Scheduler::run_mailbox() {
ListNode *node = actors_list.get(); ListNode *node = actors_list.get();
CHECK(node); CHECK(node);
auto actor_info = ActorInfo::from_list_node(node); auto actor_info = ActorInfo::from_list_node(node);
flush_mailbox(actor_info, static_cast<void (*)(ActorInfo *)>(nullptr), static_cast<Event (*)()>(nullptr)); flush_mailbox(actor_info);
} }
VLOG(actor) << "Run mailbox : finish " << actor_count_; VLOG(actor) << "Run mailbox : finish " << actor_count_;

View File

@ -140,26 +140,6 @@ inline void Scheduler::destroy_actor(ActorInfo *actor_info) {
CHECK(actor_count_ >= 0); CHECK(actor_count_ >= 0);
} }
template <class RunFuncT, class EventFuncT>
void Scheduler::flush_mailbox(ActorInfo *actor_info, const RunFuncT &run_func, const EventFuncT &event_func) {
auto &mailbox = actor_info->mailbox_;
size_t mailbox_size = mailbox.size();
CHECK(mailbox_size != 0);
EventGuard guard(this, actor_info);
size_t i = 0;
for (; i < mailbox_size && guard.can_run(); i++) {
do_event(actor_info, std::move(mailbox[i]));
}
if (run_func) {
if (guard.can_run()) {
(*run_func)(actor_info);
} else {
mailbox.insert(mailbox.begin() + i, (*event_func)());
}
}
mailbox.erase(mailbox.begin(), mailbox.begin() + i);
}
inline void Scheduler::send_to_scheduler(int32 sched_id, const ActorId<Actor> &actor_id, Event &&event) { inline void Scheduler::send_to_scheduler(int32 sched_id, const ActorId<Actor> &actor_id, Event &&event) {
if (sched_id == sched_id_) { if (sched_id == sched_id_) {
ActorInfo *actor_info = actor_id.get_actor_info(); ActorInfo *actor_info = actor_id.get_actor_info();