zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 6630a5ede5ee2e31386aab59761660952cca2e0e (tree)
parent 76fd6fc36505a203fba77e2103db12be59514532
Author: Vincent Rischmann <vincent@rischmann.fr>
Date:   Sat,  1 Jan 2022 01:23:26 +0100

io_uring: improve IO_Uring.copy_cqe

copy_cqes() is not guaranteed to return as many CQEs as provided in the
`wait_nr` argument, meaning the assert in `copy_cqe` can trigger.

Instead, loop until we do get at least one CQE returned.

This mimics the behaviour of liburing's _io_uring_get_cqe.

Diffstat:
Mlib/std/os/linux/io_uring.zig | 7++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/std/os/linux/io_uring.zig b/lib/std/os/linux/io_uring.zig @@ -300,9 +300,10 @@ pub const IO_Uring = struct { /// A convenience method for `copy_cqes()` for when you don't need to batch or peek. pub fn copy_cqe(ring: *IO_Uring) !io_uring_cqe { var cqes: [1]io_uring_cqe = undefined; - const count = try ring.copy_cqes(&cqes, 1); - assert(count == 1); - return cqes[0]; + while (true) { + const count = try ring.copy_cqes(&cqes, 1); + if (count > 0) return cqes[0]; + } } /// Matches the implementation of cq_ring_needs_flush() in liburing.