From a750e4afa7459e5d8f0ca664309372c5a3847225 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 7 Dec 2022 11:01:55 +0100 Subject: [PATCH] event/Loop: move code to GetEarlierTimeout() --- src/event/Loop.cxx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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