From 6a35fc4b454eb24c8ad411676483460c817279d4 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 4 Aug 2026 15:01:36 +0300 Subject: [PATCH] u_async: add pipe() fallback for non-Linux POSIX wakeup (FreeBSD) --- lib/u_async.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/u_async.c b/lib/u_async.c index ecb4d095..7f88d199 100644 --- a/lib/u_async.c +++ b/lib/u_async.c @@ -1453,7 +1453,7 @@ struct UASYNC* uasync_create(void) { InitializeCriticalSection(&ua->posted_lock); #else - // POSIX: use eventfd for reliable cross-thread wakeup +#ifdef __linux__ ua->wakeup_pipe[0] = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (ua->wakeup_pipe[0] < 0) { DEBUG_ERROR(DEBUG_CATEGORY_UASYNC, "eventfd() failed: %s", strerror(errno)); @@ -1461,6 +1461,19 @@ struct UASYNC* uasync_create(void) { return NULL; } ua->wakeup_pipe[1] = ua->wakeup_pipe[0]; +#else + if (pipe(ua->wakeup_pipe) < 0) { + DEBUG_ERROR(DEBUG_CATEGORY_UASYNC, "pipe() failed: %s", strerror(errno)); + u_free(ua); + return NULL; + } + if (fcntl(ua->wakeup_pipe[0], F_SETFL, O_NONBLOCK) < 0) { + DEBUG_ERROR(DEBUG_CATEGORY_UASYNC, "fcntl(wakeup_pipe[0], O_NONBLOCK) failed: %s", strerror(errno)); + } + if (fcntl(ua->wakeup_pipe[1], F_SETFL, O_NONBLOCK) < 0) { + DEBUG_ERROR(DEBUG_CATEGORY_UASYNC, "fcntl(wakeup_pipe[1], O_NONBLOCK) failed: %s", strerror(errno)); + } +#endif ua->wakeup_initialized = 1; #if HAS_EPOLL