event/Loop: move code to GetEarlierTimeout()

This commit is contained in:
Max Kellermann 2022-12-07 11:01:55 +01:00 committed by Max Kellermann
parent c122e990a3
commit a750e4afa7
1 changed files with 13 additions and 4 deletions

View File

@ -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