]> go.fuhry.dev Git - fsnotify.git/commit
kqueue: remove timeout from unix.Kevent() (#480)
authorMartin Tournoij <martin@arp242.net>
Sat, 6 Aug 2022 16:17:18 +0000 (18:17 +0200)
committerGitHub <noreply@github.com>
Sat, 6 Aug 2022 16:17:18 +0000 (18:17 +0200)
commit4b43fadabe139cc8987266635f8e5fe45feea710
tree0e61664460c54b49450e2d176bae1b55ab0151a6
parenta24f78c84014c1fc5bc55b50ddc5b2f9d0797d0f
kqueue: remove timeout from unix.Kevent() (#480)

The timeout for unix.Kevent() is causing issues; every 100ms it will do a new
unix.Kevent() syscall, which isn't too efficient: even if you have just one
change an hour, you will still keep calling kevent() ten times per second,
resulting in a needlessly high CPU usage.

Without a timeout, kevent() will block indefinitely until there are some events,
which is much more efficient. We can't just remove the timout however, since we
can't interrupt the kevent() call on FreeBSD and NetBSD, and it will hang
forever. This issue is described in more detail here:
https://github.com/fsnotify/fsnotify/pull/262#issuecomment-1201655890

To solve this we register a new kevent() with the file descriptor set to the
closepipe; when this pipe is closed an event is sent and kevent() will stop
blocking.

This is a rebased version of #124.

Fixes #89
Fixes #237
Fixes #333
Supersedes and closes #124
Supersedes and closes #262
Supersedes and closes #334

Co-authored-by: Felix Lange <fjl@twurst.com>
kqueue.go