event/Loop: move code to GetEarlierTimeout()
This commit is contained in:

committed by
Max Kellermann

parent
c122e990a3
commit
a750e4afa7
@@ -155,6 +155,18 @@ EventLoop::Insert(FineTimerEvent &t) noexcept
|
|||||||
again = true;
|
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
|
inline Event::Duration
|
||||||
EventLoop::HandleTimers() noexcept
|
EventLoop::HandleTimers() noexcept
|
||||||
{
|
{
|
||||||
@@ -163,10 +175,7 @@ EventLoop::HandleTimers() noexcept
|
|||||||
auto fine_timeout = timers.Run(now);
|
auto fine_timeout = timers.Run(now);
|
||||||
auto coarse_timeout = coarse_timers.Run(now);
|
auto coarse_timeout = coarse_timers.Run(now);
|
||||||
|
|
||||||
return fine_timeout.count() < 0 ||
|
return GetEarlierTimeout(coarse_timeout, fine_timeout);
|
||||||
(coarse_timeout.count() >= 0 && coarse_timeout < fine_timeout)
|
|
||||||
? coarse_timeout
|
|
||||||
: fine_timeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user