event/TimerWheel: optimized container for CoarseTimerEvent

This commit is contained in:
Max Kellermann
2021-02-04 23:01:17 +01:00
committed by Max Kellermann
parent d1957b83c8
commit 5a16e3ffa3
7 changed files with 409 additions and 4 deletions

View File

@@ -142,6 +142,13 @@ EventLoop::AbandonFD(SocketEvent &event) noexcept
return poll_backend.Abandon(event.GetSocket().Get());
}
void
EventLoop::Insert(CoarseTimerEvent &t) noexcept
{
coarse_timers.Insert(t);
again = true;
}
void
EventLoop::Insert(FineTimerEvent &t) noexcept
{
@@ -154,7 +161,15 @@ EventLoop::Insert(FineTimerEvent &t) noexcept
inline Event::Duration
EventLoop::HandleTimers() noexcept
{
return timers.Run(SteadyNow());
const auto now = SteadyNow();
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;
}
void