diff options
| author | Ayende Rahien <ayende@ayende.com> | 2021-08-14 06:41:18 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-13 22:41:18 -0500 |
| commit | 65208a7fa269497e85aab688f4d15f83568075d0 (patch) | |
| tree | 26efd3a50a6294a6ae8537321e8a814de0f56bad /lib/std/os | |
| parent | 1373df4c34436b18b570f5b0f1be14da63966557 (diff) | |
| download | zig-65208a7fa269497e85aab688f4d15f83568075d0.tar.gz zig-65208a7fa269497e85aab688f4d15f83568075d0.zip | |
Expose register_eventfd, register_eventfd_async, unregister_eventfd i… (#9449)
* Expose register_eventfd, register_eventfd_async, unregister_eventfd in the IO URing API
* Fixing formatting
* Fixing typo
* Removing unnecessary casts and adding better comments for a single registration of eventfd
* Update lib/std/os/linux/io_uring.zig
Co-authored-by: Joran Dirk Greef <joran@coil.com>
* Update lib/std/os/linux/io_uring.zig
Co-authored-by: Joran Dirk Greef <joran@coil.com>
* Updating util function name
Co-authored-by: Joran Dirk Greef <joran@coil.com>
Diffstat (limited to 'lib/std/os')
| -rw-r--r-- | lib/std/os/linux/io_uring.zig | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig index bb20769dc7..b6bde34b7d 100644 --- a/lib/std/os/linux/io_uring.zig +++ b/lib/std/os/linux/io_uring.zig @@ -629,13 +629,57 @@ pub const IO_Uring = struct { /// An application need unregister only if it wants to register a new array of file descriptors. pub fn register_files(self: *IO_Uring, fds: []const os.fd_t) !void { assert(self.fd >= 0); - comptime assert(@sizeOf(os.fd_t) == @sizeOf(c_int)); const res = linux.io_uring_register( self.fd, .REGISTER_FILES, @ptrCast(*const c_void, fds.ptr), @intCast(u32, fds.len), ); + try handle_registration_result(res); + } + + /// Registers the file descriptor for an eventfd that will be notified of completion events on + /// an io_uring instance. + /// Only a single a eventfd can be registered at any given point in time. + pub fn register_eventfd(self: *IO_Uring, fd: os.fd_t) !void { + assert(self.fd >= 0); + const res = linux.io_uring_register( + self.fd, + .REGISTER_EVENTFD, + @ptrCast(*const c_void, &fd), + 1, + ); + try handle_registration_result(res); + } + + /// Registers the file descriptor for an eventfd that will be notified of completion events on + /// an io_uring instance. Notifications are only posted for events that complete in an async manner. + /// This means that events that complete inline while being submitted do not trigger a notification event. + /// Only a single eventfd can be registered at any given point in time. + pub fn register_eventfd_async(self: *IO_Uring, fd: os.fd_t) !void { + assert(self.fd >= 0); + const res = linux.io_uring_register( + self.fd, + .REGISTER_EVENTFD_ASYNC, + @ptrCast(*const c_void, &fd), + 1, + ); + try handle_registration_result(res); + } + + /// Unregister the registered eventfd file descriptor. + pub fn unregister_eventfd(self: *IO_Uring) !void { + assert(self.fd >= 0); + const res = linux.io_uring_register( + self.fd, + .UNREGISTER_EVENTFD, + null, + 0, + ); + try handle_registration_result(res); + } + + fn handle_registration_result(res: usize) !void { switch (linux.getErrno(res)) { 0 => {}, // One or more fds in the array are invalid, or the kernel does not support sparse sets: |
