Commit 9902b4eb authored by Dominik Charousset's avatar Dominik Charousset

Break loop on high-throughput actions

parent c6fc49c0
...@@ -807,6 +807,10 @@ private: ...@@ -807,6 +807,10 @@ private:
/// message. /// message.
std::vector<action> actions_; std::vector<action> actions_;
/// Flag that tells delay() to push actions to the mailbox if we are already
/// in run_actions.
bool running_actions_ = false;
/// Stores resources that block the actor from terminating. /// Stores resources that block the actor from terminating.
std::vector<disposable> watched_disposables_; std::vector<disposable> watched_disposables_;
}; };
......
...@@ -606,7 +606,12 @@ void scheduled_actor::schedule(action what) { ...@@ -606,7 +606,12 @@ void scheduled_actor::schedule(action what) {
} }
void scheduled_actor::delay(action what) { void scheduled_actor::delay(action what) {
actions_.emplace_back(std::move(what)); // If we are already in run_actions, we force the action through the mailbox
// in order to break hot loops that would otherwise starve any other activity.
if (!running_actions_)
actions_.emplace_back(std::move(what));
else
schedule(std::move(what));
} }
disposable scheduled_actor::delay_until(steady_time_point abs_time, disposable scheduled_actor::delay_until(steady_time_point abs_time,
...@@ -1242,6 +1247,8 @@ void scheduled_actor::watch(disposable obj) { ...@@ -1242,6 +1247,8 @@ void scheduled_actor::watch(disposable obj) {
} }
void scheduled_actor::run_actions() { void scheduled_actor::run_actions() {
running_actions_ = true;
auto guard = detail::make_scope_guard([this] { running_actions_ = false; });
if (!actions_.empty()) { if (!actions_.empty()) {
// Note: can't use iterators here since actions may add to the vector. // Note: can't use iterators here since actions may add to the vector.
for (auto index = size_t{0}; index < actions_.size(); ++index) { for (auto index = size_t{0}; index < actions_.size(); ++index) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment