From ae0d60fcd8976a0d3e682f4cdd12ae2e41d5721c Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 10 Aug 2022 13:02:23 +1000 Subject: [PATCH] Timer: Spin for last 1ms on non-windows too --- src/common/timer.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common/timer.cpp b/src/common/timer.cpp index 931d28dd8..113a0a2fa 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -186,8 +186,21 @@ void Timer::SleepUntil(Value value, bool exact) { if (exact) { - while (GetCurrentValue() < value) - SleepUntil(value, false); + for (;;) + { + Value current = GetCurrentValue(); + if (current >= value) + break; + + static constexpr Value min_sleep_time = 1 * 1000000; + + // spin for the last 1ms + if ((value - current) > min_sleep_time) + { + SleepUntil(value, false); + continue; + } + } } else {