Skip to content

Commit

Permalink
linux: remove epoll_pwait() emulation code path (libuv#3936)
Browse files Browse the repository at this point in the history
This was removed before in 2018 but then reinstated again in 2019 to
fix building with old Android SDKs. Well, time marches on; this time
it's gone for good.

Refs: libuv#1372
Refs: libuv#2358
  • Loading branch information
bnoordhuis authored Mar 28, 2023
1 parent 7b84d5b commit 0c8eccc
Showing 1 changed file with 8 additions and 50 deletions.
58 changes: 8 additions & 50 deletions src/unix/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,14 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
* that being the largest value I have seen in the wild (and only once.)
*/
static const int max_safe_timeout = 1789569;
static int no_epoll_pwait_cached;
static int no_epoll_wait_cached;
int no_epoll_pwait;
int no_epoll_wait;
struct epoll_event events[1024];
struct epoll_event* pe;
struct epoll_event e;
int real_timeout;
QUEUE* q;
uv__io_t* w;
sigset_t* sigmask;
sigset_t sigset;
uint64_t sigmask;
uint64_t base;
int have_signals;
int nevents;
Expand Down Expand Up @@ -372,11 +368,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
w->events = w->pevents;
}

sigmask = 0;
sigmask = NULL;
if (loop->flags & UV_LOOP_BLOCK_SIGPROF) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGPROF);
sigmask |= 1 << (SIGPROF - 1);
sigmask = &sigset;
}

assert(timeout >= -1);
Expand All @@ -393,15 +389,6 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
user_timeout = 0;
}

/* You could argue there is a dependency between these two but
* ultimately we don't care about their ordering with respect
* to one another. Worst case, we make a few system calls that
* could have been avoided because another thread already knows
* they fail with ENOSYS. Hardly the end of the world.
*/
no_epoll_pwait = uv__load_relaxed(&no_epoll_pwait_cached);
no_epoll_wait = uv__load_relaxed(&no_epoll_wait_cached);

for (;;) {
/* Only need to set the provider_entry_time if timeout != 0. The function
* will return early if the loop isn't configured with UV_METRICS_IDLE_TIME.
Expand All @@ -415,34 +402,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (sizeof(int32_t) == sizeof(long) && timeout >= max_safe_timeout)
timeout = max_safe_timeout;

if (sigmask != 0 && no_epoll_pwait != 0)
if (pthread_sigmask(SIG_BLOCK, &sigset, NULL))
abort();

if (no_epoll_wait != 0 || (sigmask != 0 && no_epoll_pwait == 0)) {
nfds = epoll_pwait(loop->backend_fd,
events,
ARRAY_SIZE(events),
timeout,
&sigset);
if (nfds == -1 && errno == ENOSYS) {
uv__store_relaxed(&no_epoll_pwait_cached, 1);
no_epoll_pwait = 1;
}
} else {
nfds = epoll_wait(loop->backend_fd,
events,
ARRAY_SIZE(events),
timeout);
if (nfds == -1 && errno == ENOSYS) {
uv__store_relaxed(&no_epoll_wait_cached, 1);
no_epoll_wait = 1;
}
}

if (sigmask != 0 && no_epoll_pwait != 0)
if (pthread_sigmask(SIG_UNBLOCK, &sigset, NULL))
abort();
nfds = epoll_pwait(loop->backend_fd,
events,
ARRAY_SIZE(events),
timeout,
sigmask);

/* Update loop->time unconditionally. It's tempting to skip the update when
* timeout == 0 (i.e. non-blocking poll) but there is no guarantee that the
Expand Down Expand Up @@ -471,12 +435,6 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
}

if (nfds == -1) {
if (errno == ENOSYS) {
/* epoll_wait() or epoll_pwait() failed, try the other system call. */
assert(no_epoll_wait == 0 || no_epoll_pwait == 0);
continue;
}

if (errno != EINTR)
abort();

Expand Down

0 comments on commit 0c8eccc

Please sign in to comment.