Add config option to determine whether timerfd is used.

Add a new configuration option "reactor" / "use_timerfd" that is used by
the epoll_reactor. When true (the default), the reactor uses a timerfd
descriptor to manage timeouts. When false, the duration until the next
timeout is computed and passed as a timeout to epoll_wait.
This commit is contained in:
Christopher Kohlhoff
2025-11-05 19:11:05 +11:00
parent 6ca87cc9c2
commit fb037cfc73
2 changed files with 19 additions and 3 deletions

View File

@@ -43,7 +43,8 @@ epoll_reactor::epoll_reactor(asio::execution_context& ctx)
config(ctx).get("reactor", "registration_locking_spin_count", 0)),
interrupter_(),
epoll_fd_(do_epoll_create()),
timer_fd_(do_timerfd_create()),
timer_fd_(config(ctx).get("reactor", "use_timerfd", true)
? do_timerfd_create() : -1),
shutdown_(false),
io_locking_(config(ctx).get("reactor", "io_locking", true)),
io_locking_spin_count_(
@@ -109,9 +110,11 @@ void epoll_reactor::notify_fork(
epoll_fd_ = do_epoll_create();
if (timer_fd_ != -1)
{
::close(timer_fd_);
timer_fd_ = -1;
timer_fd_ = do_timerfd_create();
timer_fd_ = -1;
timer_fd_ = do_timerfd_create();
}
interrupter_.recreate();

View File

@@ -177,6 +177,19 @@ below.
fails with `EAGAIN`.
]
]
[
[`reactor`]
[`use_timerfd`]
[`bool`]
[`true`]
[
Linux [^epoll] backend only.
When `true`, the reactor uses a [^timerfd] descriptor to manage timeouts.
When `false`, the duration until the next timeout is computed and passed
as a timeout to [^epoll_wait].
]
]
[
[`timer`]
[`heap_reserve`]