diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index a405be240..1f8845124 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -155,6 +155,18 @@ EventLoop::Insert(FineTimerEvent &t) noexcept again = true; } +/** + * Determines which timeout will happen earlier; either one may be + * negative to specify "no timeout at all". + */ +static constexpr Event::Duration +GetEarlierTimeout(Event::Duration a, Event::Duration b) noexcept +{ + return b.count() < 0 || (a.count() >= 0 && a < b) + ? a + : b; +} + inline Event::Duration EventLoop::HandleTimers() noexcept { @@ -163,10 +175,7 @@ EventLoop::HandleTimers() noexcept auto fine_timeout = timers.Run(now); auto coarse_timeout = coarse_timers.Run(now); - return fine_timeout.count() < 0 || - (coarse_timeout.count() >= 0 && coarse_timeout < fine_timeout) - ? coarse_timeout - : fine_timeout; + return GetEarlierTimeout(coarse_timeout, fine_timeout); } void