event/Loop: use std::chrono::ceil()

Thanks to C++17, we don't need our custom implementation anymore.
This commit is contained in:
Max Kellermann 2024-10-29 13:29:21 +01:00 committed by Max Kellermann
parent b745d1f226
commit f807345022
1 changed files with 1 additions and 13 deletions

View File

@ -224,18 +224,6 @@ EventLoop::RunOneIdle() noexcept
return true; return true;
} }
template<class ToDuration, class Rep, class Period>
static constexpr ToDuration
duration_cast_round_up(std::chrono::duration<Rep, Period> d) noexcept
{
using FromDuration = decltype(d);
constexpr auto one = std::chrono::duration_cast<FromDuration>(ToDuration(1));
constexpr auto round_add = one > one.zero()
? one - FromDuration(1)
: one.zero();
return std::chrono::duration_cast<ToDuration>(d + round_add);
}
/** /**
* Convert the given timeout specification to a milliseconds integer, * Convert the given timeout specification to a milliseconds integer,
* to be used by functions like poll() and epoll_wait(). Any negative * to be used by functions like poll() and epoll_wait(). Any negative
@ -245,7 +233,7 @@ static constexpr int
ExportTimeoutMS(Event::Duration timeout) noexcept ExportTimeoutMS(Event::Duration timeout) noexcept
{ {
return timeout >= timeout.zero() return timeout >= timeout.zero()
? int(duration_cast_round_up<std::chrono::milliseconds>(timeout).count()) ? static_cast<int>(std::chrono::ceil<std::chrono::milliseconds>(timeout).count())
: -1; : -1;
} }