Skip to content

Commit

Permalink
kqueue: consolidate the preprocessor directives
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Mar 2, 2024
1 parent 24e3869 commit e9415f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/unix/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
#include <unistd.h>
#include <sched.h> /* sched_yield() */

#if defined(__FreeBSD__) || defined(__NetBSD__)
#include <sys/event.h>
#endif

#ifdef __linux__
#include <sys/eventfd.h>
#endif
Expand Down Expand Up @@ -140,7 +136,7 @@ static void uv__async_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
struct uv__queue* q;
uv_async_t* h;
_Atomic int *pending;
#ifndef EVFILT_USER
#if !UV__KQUEUE_EVFILT_USER
char buf[1024];
ssize_t r;

Expand Down Expand Up @@ -185,7 +181,7 @@ static void uv__async_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {


static void uv__async_send(uv_loop_t* loop) {
#if defined(EVFILT_USER) && defined(NOTE_TRIGGER)
#if UV__KQUEUE_EVFILT_USER
struct kevent ev;
struct timespec timeout = { 0, 0 };
EV_SET(&ev, loop->async_io_watcher.fd, EVFILT_USER, 0, NOTE_TRIGGER, 0, 0);
Expand Down Expand Up @@ -241,7 +237,7 @@ static int uv__async_start(uv_loop_t* loop) {

pipefd[0] = err;
pipefd[1] = -1;
#elif defined(EVFILT_USER) && defined(NOTE_TRIGGER) /* EVFILT_USER is available since FreeBSD 8.1 and NetBSD 10.0 */
#elif UV__KQUEUE_EVFILT_USER
err = uv__open_cloexec("/dev/null", O_RDWR); /* This fd will not be actually used, only for a unique index */
if (err < 0)
return err;
Expand Down
12 changes: 12 additions & 0 deletions src/unix/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#if defined(__FreeBSD__) || defined(__NetBSD__)
#include <sys/event.h>
#endif

#define uv__msan_unpoison(p, n) \
do { \
Expand Down Expand Up @@ -483,3 +486,12 @@ int uv__get_constrained_cpu(uv__cpu_constraint* constraint);
#endif

#endif /* UV_UNIX_INTERNAL_H_ */

/* EVFILT_USER is available since FreeBSD 8.1 and NetBSD 10.0,
* this filter seems to be broken on macOS, so don't apply it on macOS.
*/
#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) && !defined(__APPLE__)
#define UV__KQUEUE_EVFILT_USER 1
#else
#define UV__KQUEUE_EVFILT_USER 0
#endif
4 changes: 2 additions & 2 deletions src/unix/kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
assert(w->fd >= 0);
assert(w->fd < (int) loop->nwatchers);

#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) && !defined(__APPLE__) /* EVFILT_USER seems to be broken on macOS, so don't apply this on macOS */
#if UV__KQUEUE_EVFILT_USER
if (w == &loop->async_io_watcher && (w->pevents & POLLIN) != 0) {
filter = EVFILT_USER;
fflags = 0;
Expand Down Expand Up @@ -364,7 +364,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {

revents = 0;

#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) && !defined(__APPLE__)
#if UV__KQUEUE_EVFILT_USER
if (ev->filter == EVFILT_READ || ev->filter == EVFILT_USER) {
#else
if (ev->filter == EVFILT_READ) {
Expand Down

0 comments on commit e9415f8

Please sign in to comment.