libxev is a cross-platform, high-performance event loop that provides abstractions for non-blocking IO, timers, events, and more and works on Linux (io_uring or epoll), macOS (kqueue), and Wasm + WASI. Available as both a Zig and C API.
MIT License
2.16k
stars
76
forks
source link
Allow watchers to generate completions without adding them to the loop. #123
This is a general design request. I think it would be nice to all the various watchers to fill out completions without adding them to a loop. I am working on a multithreaded system, where the main loop is behind lock. As such, I don't want threads to always lock due to calling loop.add. Instead it would be preferable to just create a completion. Later, the lock can be grabbed and loop.add called.
That said, it may be nicer to fully split out the api and make two different calls. One that just fills out the completion and one that actually adds to the loop.
This is a general design request. I think it would be nice to all the various watchers to fill out completions without adding them to a loop. I am working on a multithreaded system, where the main loop is behind lock. As such, I don't want threads to always lock due to calling
loop.add
. Instead it would be preferable to just create a completion. Later, the lock can be grabbed andloop.add
called.As such, it would be nice to have a version of the watcher functions that doesn't call
loop.add
. The simplest solution would be to changeloop: *xev.Loop
to aloop: ?*xev.Loop
. If the loop is null, no add function is called. where be a modification here and in other equivalent functions: https://github.com/mitchellh/libxev/blob/b8d1d93e5c899b27abbaa7df23b496c3e6a178c7/src/watcher/tcp.zig#L130 to something like:That said, it may be nicer to fully split out the api and make two different calls. One that just fills out the completion and one that actually adds to the loop.
Thoughts?