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.

get_sqe

Returns a pointer to a vacant SQE, or an error if the submission queue is full. We follow the implementation (and atomics) of liburing's io_uring_get_sqe() exactly. However, instead of a null we return an error to force safe handling. Any situation where the submission queue is full tends more towards a control flow error, and the null return in liburing is more a C idiom than anything else, for lack of a better alternative. In Zig, we have first-class error handling... so let's use it. Matches the implementation of io_uring_get_sqe() in liburing.

IoUring.get_sqe
pub fn get_sqe(self: *IoUring) !*linux.io_uring_sqe

File

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

Code

pub fn get_sqe(self: *IoUring) !*linux.io_uring_sqe {
    const head = @atomicLoad(u32, self.sq.head, .acquire);
    // Remember that these head and tail offsets wrap around every four billion operations.
    // We must therefore use wrapping addition and subtraction to avoid a runtime crash.
    const next = self.sq.sqe_tail +% 1;
    if (next -% head > self.sq.sqes.len) return error.SubmissionQueueFull;
    const sqe = &self.sq.sqes[self.sq.sqe_tail & self.sq.mask];
    self.sq.sqe_tail = next;
    return sqe;
}