Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

copy_cqes

Copies as many CQEs as are ready, and that can fit into the destination cqes slice. If none are available, enters into the kernel to wait for at most wait_nr CQEs. Returns the number of CQEs copied, advancing the CQ ring. Provides all the wait/peek methods found in liburing, but with batching and a single method. The rationale for copying CQEs rather than copying pointers is that pointers are 8 bytes whereas CQEs are not much more at only 16 bytes, and this provides a safer faster interface. Safer, because you no longer need to call cqe_seen(), avoiding idempotency bugs. Faster, because we can now amortize the atomic store release to cq.head across the batch. See https://github.com/axboe/liburing/issues/103#issuecomment-686665007. Matches the implementation of io_uring_peek_batch_cqe() in liburing, but supports waiting.

IoUring.copy_cqes
pub fn copy_cqes(self: *IoUring, cqes: []linux.io_uring_cqe, wait_nr: u32) !u32

File

lib/std/os/linux/IoUring.zig:279

Code

pub fn copy_cqes(self: *IoUring, cqes: []linux.io_uring_cqe, wait_nr: u32) !u32 {
    const count = self.copy_cqes_ready(cqes);
    if (count > 0) return count;
    if (self.cq_ring_needs_flush() or wait_nr > 0) {
        _ = try self.enter(0, wait_nr, linux.IORING_ENTER_GETEVENTS);
        return self.copy_cqes_ready(cqes);
    }
    return 0;
}