Commit e140966f authored by Dominik Charousset's avatar Dominik Charousset

Fix test_multiplexer::flush_runnables

parent 3627cdb7
...@@ -243,10 +243,7 @@ void test_multiplexer::accept_connection(accept_handle hdl) { ...@@ -243,10 +243,7 @@ void test_multiplexer::accept_connection(accept_handle hdl) {
} }
void test_multiplexer::read_data(connection_handle hdl) { void test_multiplexer::read_data(connection_handle hdl) {
// flush any pending runnables flush_runnables();
while (try_exec_runnable()) {
// nop
}
scribe_data& sd = scribe_data_[hdl]; scribe_data& sd = scribe_data_[hdl];
switch (sd.recv_conf.first) { switch (sd.recv_conf.first) {
case receive_policy_flag::exactly: case receive_policy_flag::exactly:
...@@ -313,15 +310,25 @@ bool test_multiplexer::try_exec_runnable() { ...@@ -313,15 +310,25 @@ bool test_multiplexer::try_exec_runnable() {
} }
void test_multiplexer::flush_runnables() { void test_multiplexer::flush_runnables() {
// execute runnables in bursts, pick a small size to
// minimize time in the critical section
constexpr size_t max_runnable_count = 8;
std::vector<runnable_ptr> runnables; std::vector<runnable_ptr> runnables;
runnables.reserve(256); runnables.reserve(max_runnable_count);
{ // critical section // runnables can create new runnables, so we need to double-check
guard_type guard{mx_}; // that `runnables_` is empty after each burst
while (! runnables_.empty()) do {
runnables.emplace_back(std::move(runnables_.front())); runnables.clear();
} { // critical section
for (auto& ptr : runnables) guard_type guard{mx_};
ptr->run(); while (! runnables_.empty() && runnables.size() < max_runnable_count) {
runnables.emplace_back(std::move(runnables_.front()));
runnables_.pop_front();
}
}
for (auto& ptr : runnables)
ptr->run();
} while (! runnables.empty());
} }
void test_multiplexer::dispatch_runnable(runnable_ptr ptr) { void test_multiplexer::dispatch_runnable(runnable_ptr ptr) {
......
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