Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions main/poll/poll_backend_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

#include <sys/epoll.h>

#ifdef HAVE_EPOLL_PWAIT2
/* Cleared when the running kernel returns ENOSYS */
static zend_atomic_bool epoll_pwait2_available = ZEND_ATOMIC_BOOL_INITIALIZER(true);
#endif

typedef struct epoll_backend_data {
int epoll_fd;
struct epoll_event *events;
Expand Down Expand Up @@ -182,11 +187,19 @@ static int epoll_backend_wait(

int nfds;
#ifdef HAVE_EPOLL_PWAIT2
nfds = epoll_pwait2(backend_data->epoll_fd, backend_data->events, max_events, timeout, NULL);
#else
int timeout_ms = php_poll_timespec_to_ms(timeout);
nfds = epoll_wait(backend_data->epoll_fd, backend_data->events, max_events, timeout_ms);
if (EXPECTED(zend_atomic_bool_load_ex(&epoll_pwait2_available))) {
nfds = epoll_pwait2(
backend_data->epoll_fd, backend_data->events, max_events, timeout, NULL);
if (UNEXPECTED(nfds < 0 && (errno == ENOSYS || errno == ENOTSUP))) {
zend_atomic_bool_store_ex(&epoll_pwait2_available, false);
}
}
if (UNEXPECTED(!zend_atomic_bool_load_ex(&epoll_pwait2_available)))
#endif
{
int timeout_ms = php_poll_timespec_to_ms(timeout);
nfds = epoll_wait(backend_data->epoll_fd, backend_data->events, max_events, timeout_ms);
}

if (nfds > 0) {

@devnexen devnexen Sep 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I get 'ndfs' may be unitialized [-Wmaybe-uninitialized].

for (int i = 0; i < nfds; i++) {
Expand Down
Loading