From bbae7be409a230c546f4a8367771c0cb9e747412 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 6 Oct 2021 17:16:23 +0300 Subject: [PATCH] Respect timeout in run_events. --- tdactor/td/actor/impl/Scheduler-decl.h | 2 +- tdactor/td/actor/impl/Scheduler.cpp | 15 +++++++++++++-- tdactor/td/actor/impl/Scheduler.h | 11 ----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tdactor/td/actor/impl/Scheduler-decl.h b/tdactor/td/actor/impl/Scheduler-decl.h index 24393a801..0e3fa3b03 100644 --- a/tdactor/td/actor/impl/Scheduler-decl.h +++ b/tdactor/td/actor/impl/Scheduler-decl.h @@ -196,7 +196,7 @@ class Scheduler { Timestamp run_timeout(); void run_mailbox(); - Timestamp run_events(); + Timestamp run_events(Timestamp timeout); void run_poll(Timestamp timeout); template diff --git a/tdactor/td/actor/impl/Scheduler.cpp b/tdactor/td/actor/impl/Scheduler.cpp index 3ae5a2468..4e32cb33a 100644 --- a/tdactor/td/actor/impl/Scheduler.cpp +++ b/tdactor/td/actor/impl/Scheduler.cpp @@ -487,18 +487,29 @@ Timestamp Scheduler::run_timeout() { return get_timeout(); } +Timestamp Scheduler::run_events(Timestamp timeout) { + Timestamp res; + VLOG(actor) << "Run events " << sched_id_ << " " << tag("pending", pending_events_.size()) + << tag("actors", actor_count_); + do { + run_mailbox(); + res = run_timeout(); + } while (!ready_actors_list_.empty() && !timeout.is_in_past()); + return res; +} + void Scheduler::run_no_guard(Timestamp timeout) { CHECK(has_guard_); SCOPE_EXIT { yield_flag_ = false; }; - timeout.relax(run_events()); + timeout.relax(run_events(timeout)); if (yield_flag_) { return; } run_poll(timeout); - run_events(); + run_events(timeout); } Timestamp Scheduler::get_timeout() { diff --git a/tdactor/td/actor/impl/Scheduler.h b/tdactor/td/actor/impl/Scheduler.h index 1212509c0..2356f6d1c 100644 --- a/tdactor/td/actor/impl/Scheduler.h +++ b/tdactor/td/actor/impl/Scheduler.h @@ -345,17 +345,6 @@ inline void Scheduler::wakeup() { #endif } -inline Timestamp Scheduler::run_events() { - Timestamp res; - VLOG(actor) << "Run events " << sched_id_ << " " << tag("pending", pending_events_.size()) - << tag("actors", actor_count_); - do { - run_mailbox(); - res = run_timeout(); - } while (!ready_actors_list_.empty()); - return res; -} - inline void Scheduler::run(Timestamp timeout) { auto guard = get_guard(); run_no_guard(timeout);