u_async: add pipe() fallback for non-Linux POSIX wakeup (FreeBSD)

This commit is contained in:
Evgeny committed 2026-08-04 15:01:36 +03:00
1 parent de9e467b39
commit 6a35fc4b45
1 file changed
+14 -1
+14 -1
View File
@@ -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