fix(wave11): resolve adversarial review findings in EventBus, IO, and Runtime

This commit is contained in:
faumaray committed 2026-12-01 22:03:35 +03:00
1 parent 7bea7df46d
commit c6de7842f7
10 files changed
+871 -134

No files matched your search

+17 -3
View File
@@ -187,12 +187,16 @@ public:
};
std::size_t total = 0;
std::size_t consecutive_fast_zero = 0;
while (!stop.stop_requested() && !shutdown_complete()) {
const auto poll_start = std::chrono::steady_clock::now();
auto res = poll_once(max_wait);
const auto poll_elapsed = std::chrono::steady_clock::now() - poll_start;
if (!res.has_value()) {
if (res.error().code().domain == Void::Result::kIoErrorDomain &&
res.error().code().value ==
static_cast<std::int32_t>(IoErrorCode::busy)) {
consecutive_fast_zero = 0;
const auto busy_slice =
max_wait > std::chrono::nanoseconds{0}
? std::min(max_wait,
@@ -206,9 +210,19 @@ public:
return std::unexpected{std::move(res.error())};
}
total += *res;
if (*res == 0 && active_backend() == BackendPreference::mock &&
max_wait > std::chrono::nanoseconds{0}) {
wait_stop_aware(max_wait);
if (*res == 0 && max_wait > std::chrono::nanoseconds{0} &&
poll_elapsed < max_wait) {
const auto remain = std::chrono::duration_cast<std::chrono::nanoseconds>(
max_wait - poll_elapsed);
if (active_backend() == BackendPreference::mock) {
wait_stop_aware(remain);
} else if (++consecutive_fast_zero >= 2) {
wait_stop_aware(std::min(
remain,
std::chrono::nanoseconds{std::chrono::milliseconds{1}}));
}
} else {
consecutive_fast_zero = 0;
}
}
return total;
+15 -3
View File
@@ -102,7 +102,9 @@ template <class Done>
wait = std::chrono::nanoseconds{0};
}
const auto poll_start = std::chrono::steady_clock::now();
auto poll_res = driver.poll_once(wait);
const auto poll_elapsed = std::chrono::steady_clock::now() - poll_start;
if (!poll_res.has_value()) {
if (poll_res.error().code().domain == Void::Result::kIoErrorDomain &&
poll_res.error().code().value ==
@@ -119,12 +121,13 @@ template <class Done>
}
return std::unexpected{std::move(poll_res.error())};
}
total_work += *poll_res;
std::size_t turn_work = *poll_res;
if (options.timers != nullptr) {
total_work += options.timers->poll_expired();
turn_work += options.timers->poll_expired();
}
total_work += manual.drain();
turn_work += manual.drain();
total_work += turn_work;
if (done()) {
return total_work;
@@ -132,6 +135,15 @@ template <class Done>
if (driver.shutdown_complete()) {
return total_work;
}
if (turn_work == 0 && manual.empty() &&
wait > std::chrono::nanoseconds{0} && poll_elapsed < wait) {
const auto remain = std::chrono::duration_cast<std::chrono::nanoseconds>(
wait - poll_elapsed);
const auto slice = std::min(
remain,
std::chrono::nanoseconds{std::chrono::milliseconds{1}});
wait_stop_aware(slice);
}
}
}