Remove now unneeded wait_generation.

This commit is contained in:
levlam 2023-01-11 12:49:04 +03:00
parent 3b6874818a
commit 62720bde3c
5 changed files with 4 additions and 23 deletions

View File

@ -108,15 +108,13 @@ class ActorInfo final
bool need_context() const; bool need_context() const;
bool need_start_up() const; bool need_start_up() const;
void set_wait_generation(uint32 wait_generation); bool must_wait() const;
bool must_wait(uint32 wait_generation) const;
private: private:
Deleter deleter_ = Deleter::None; Deleter deleter_ = Deleter::None;
bool need_context_ = true; bool need_context_ = true;
bool need_start_up_ = true; bool need_start_up_ = true;
bool is_running_ = false; bool is_running_ = false;
uint32 wait_generation_{0};
std::atomic<int32> sched_id_{0}; std::atomic<int32> sched_id_{0};
Actor *actor_ = nullptr; Actor *actor_ = nullptr;

View File

@ -50,7 +50,6 @@ inline void ActorInfo::init(int32 sched_id, Slice name, ObjectPool<ActorInfo>::O
need_context_ = need_context; need_context_ = need_context;
need_start_up_ = need_start_up; need_start_up_ = need_start_up;
is_running_ = false; is_running_ = false;
wait_generation_ = 0;
} }
inline bool ActorInfo::need_context() const { inline bool ActorInfo::need_context() const {
@ -61,12 +60,8 @@ inline bool ActorInfo::need_start_up() const {
return need_start_up_; return need_start_up_;
} }
inline void ActorInfo::set_wait_generation(uint32 wait_generation) { inline bool ActorInfo::must_wait() const {
wait_generation_ = wait_generation; return !mailbox_.empty();
}
inline bool ActorInfo::must_wait(uint32 wait_generation) const {
return wait_generation_ == wait_generation || !mailbox_.empty();
} }
inline void ActorInfo::on_actor_moved(Actor *actor_new_ptr) { inline void ActorInfo::on_actor_moved(Actor *actor_new_ptr) {

View File

@ -200,8 +200,6 @@ class Scheduler {
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);
void inc_wait_generation();
Timestamp run_timeout(); Timestamp run_timeout();
void run_mailbox(); void run_mailbox();
Timestamp run_events(Timestamp timeout); Timestamp run_events(Timestamp timeout);
@ -231,7 +229,6 @@ class Scheduler {
bool has_guard_ = false; bool has_guard_ = false;
bool close_flag_ = false; bool close_flag_ = false;
uint32 wait_generation_ = 1;
int32 sched_id_ = 0; int32 sched_id_ = 0;
int32 sched_n_ = 0; int32 sched_n_ = 0;
std::shared_ptr<MpscPollableQueue<EventFull>> inbound_queue_; std::shared_ptr<MpscPollableQueue<EventFull>> inbound_queue_;

View File

@ -497,7 +497,6 @@ 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);
inc_wait_generation();
flush_mailbox(actor_info, static_cast<void (*)(ActorInfo *)>(nullptr), static_cast<Event (*)()>(nullptr)); flush_mailbox(actor_info, static_cast<void (*)(ActorInfo *)>(nullptr), static_cast<Event (*)()>(nullptr));
} }
VLOG(actor) << "Run mailbox : finish " << actor_count_; VLOG(actor) << "Run mailbox : finish " << actor_count_;
@ -526,7 +525,6 @@ Timestamp Scheduler::run_timeout() {
while (!timeout_queue_.empty() && timeout_queue_.top_key() < now) { while (!timeout_queue_.empty() && timeout_queue_.top_key() < now) {
HeapNode *node = timeout_queue_.pop(); HeapNode *node = timeout_queue_.pop();
ActorInfo *actor_info = ActorInfo::from_heap_node(node); ActorInfo *actor_info = ActorInfo::from_heap_node(node);
inc_wait_generation();
send<ActorSendType::Immediate>(actor_info->actor_id(), Event::timeout()); send<ActorSendType::Immediate>(actor_info->actor_id(), Event::timeout());
} }
return get_timeout(); return get_timeout();

View File

@ -191,10 +191,6 @@ inline void Scheduler::before_tail_send(const ActorId<> &actor_id) {
// TODO // TODO
} }
inline void Scheduler::inc_wait_generation() {
wait_generation_ += 2;
}
template <ActorSendType send_type, class RunFuncT, class EventFuncT> template <ActorSendType send_type, class RunFuncT, class EventFuncT>
void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, const EventFuncT &event_func) { void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, const EventFuncT &event_func) {
ActorInfo *actor_info = actor_id.get_actor_info(); ActorInfo *actor_info = actor_id.get_actor_info();
@ -210,7 +206,7 @@ void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, c
CHECK(has_guard_ || !on_current_sched); CHECK(has_guard_ || !on_current_sched);
if (likely(send_type == ActorSendType::Immediate && on_current_sched && !actor_info->is_running() && if (likely(send_type == ActorSendType::Immediate && on_current_sched && !actor_info->is_running() &&
!actor_info->must_wait(wait_generation_))) { // run immediately !actor_info->must_wait())) { // run immediately
if (likely(actor_info->mailbox_.empty())) { if (likely(actor_info->mailbox_.empty())) {
EventGuard guard(this, actor_info); EventGuard guard(this, actor_info);
run_func(actor_info); run_func(actor_info);
@ -220,9 +216,6 @@ void Scheduler::send_impl(const ActorId<> &actor_id, const RunFuncT &run_func, c
} else { } else {
if (on_current_sched) { if (on_current_sched) {
add_to_mailbox(actor_info, event_func()); add_to_mailbox(actor_info, event_func());
if (send_type == ActorSendType::Later) {
actor_info->set_wait_generation(wait_generation_);
}
} else { } else {
send_to_scheduler(actor_sched_id, actor_id, event_func()); send_to_scheduler(actor_sched_id, actor_id, event_func());
} }