authorgravatar for ayende@ayende.comAyende Rahien <ayende@ayende.com> 2021-08-14 06:41:18+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-08-13 22:41:18-05:00
log65208a7fa269497e85aab688f4d15f83568075d0
tree26efd3a50a6294a6ae8537321e8a814de0f56bad
parent1373df4c34436b18b570f5b0f1be14da63966557
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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>

1 files changed, 45 insertions(+), 1 deletions(-)

lib/std/os/linux/io_uring.zig+45-1
...@@ -629,13 +629,57 @@ pub const IO_Uring = struct {...@@ -629,13 +629,57 @@ pub const IO_Uring = struct {
629 /// An application need unregister only if it wants to register a new array of file descriptors.629 /// An application need unregister only if it wants to register a new array of file descriptors.
630 pub fn register_files(self: *IO_Uring, fds: []const os.fd_t) !void {630 pub fn register_files(self: *IO_Uring, fds: []const os.fd_t) !void {
631 assert(self.fd >= 0);631 assert(self.fd >= 0);
632 comptime assert(@sizeOf(os.fd_t) == @sizeOf(c_int));
633 const res = linux.io_uring_register(632 const res = linux.io_uring_register(
634 self.fd,633 self.fd,
635 .REGISTER_FILES,634 .REGISTER_FILES,
636 @ptrCast(*const c_void, fds.ptr),635 @ptrCast(*const c_void, fds.ptr),
637 @intCast(u32, fds.len),636 @intCast(u32, fds.len),
638 );637 );
638 try handle_registration_result(res);
639 }
640
641 /// Registers the file descriptor for an eventfd that will be notified of completion events on
642 /// an io_uring instance.
643 /// Only a single a eventfd can be registered at any given point in time.
644 pub fn register_eventfd(self: *IO_Uring, fd: os.fd_t) !void {
645 assert(self.fd >= 0);
646 const res = linux.io_uring_register(
647 self.fd,
648 .REGISTER_EVENTFD,
649 @ptrCast(*const c_void, &fd),
650 1,
651 );
652 try handle_registration_result(res);
653 }
654
655 /// Registers the file descriptor for an eventfd that will be notified of completion events on
656 /// an io_uring instance. Notifications are only posted for events that complete in an async manner.
657 /// This means that events that complete inline while being submitted do not trigger a notification event.
658 /// Only a single eventfd can be registered at any given point in time.
659 pub fn register_eventfd_async(self: *IO_Uring, fd: os.fd_t) !void {
660 assert(self.fd >= 0);
661 const res = linux.io_uring_register(
662 self.fd,
663 .REGISTER_EVENTFD_ASYNC,
664 @ptrCast(*const c_void, &fd),
665 1,
666 );
667 try handle_registration_result(res);
668 }
669
670 /// Unregister the registered eventfd file descriptor.
671 pub fn unregister_eventfd(self: *IO_Uring) !void {
672 assert(self.fd >= 0);
673 const res = linux.io_uring_register(
674 self.fd,
675 .UNREGISTER_EVENTFD,
676 null,
677 0,
678 );
679 try handle_registration_result(res);
680 }
681
682 fn handle_registration_result(res: usize) !void {
639 switch (linux.getErrno(res)) {683 switch (linux.getErrno(res)) {
640 0 => {},684 0 => {},
641 // One or more fds in the array are invalid, or the kernel does not support sparse sets:685 // One or more fds in the array are invalid, or the kernel does not support sparse sets: