authorgravatar for vincent@rischmann.frVincent Rischmann <vincent@rischmann.fr> 2022-01-01 01:23:26+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-04 02:13:41-05:00
log6630a5ede5ee2e31386aab59761660952cca2e0e
treeba1007ac4a5c6a043e0fec978d71ebf23b872df2
parent76fd6fc36505a203fba77e2103db12be59514532

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.

1 files changed, 4 insertions(+), 3 deletions(-)

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