Browse Source

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

topo_upd
Evgeny 2 months ago
parent
commit
6a35fc4b45
  1. 15
      lib/u_async.c

15
lib/u_async.c

@ -1453,7 +1453,7 @@ struct UASYNC* uasync_create(void) {
InitializeCriticalSection(&ua->posted_lock); InitializeCriticalSection(&ua->posted_lock);
#else #else
// POSIX: use eventfd for reliable cross-thread wakeup #ifdef __linux__
ua->wakeup_pipe[0] = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); ua->wakeup_pipe[0] = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
if (ua->wakeup_pipe[0] < 0) { if (ua->wakeup_pipe[0] < 0) {
DEBUG_ERROR(DEBUG_CATEGORY_UASYNC, "eventfd() failed: %s", strerror(errno)); DEBUG_ERROR(DEBUG_CATEGORY_UASYNC, "eventfd() failed: %s", strerror(errno));
@ -1461,6 +1461,19 @@ struct UASYNC* uasync_create(void) {
return NULL; return NULL;
} }
ua->wakeup_pipe[1] = ua->wakeup_pipe[0]; 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; ua->wakeup_initialized = 1;
#if HAS_EPOLL #if HAS_EPOLL

Loading…
Cancel
Save