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-12 11:53:42-07:00
log4d38f456ea70c350ca4530ecfa01931f2c8c4816
treeaf17636dac00232dbbdc3c2619d925ad49d26113
parent8771ef897a1ef383d4cfdf9f14a0ac0b4148ceac

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 {...@@ -300,9 +300,10 @@ pub const IO_Uring = struct {
300 /// A convenience method for `copy_cqes()` for when you don't need to batch or peek.300 /// A convenience method for `copy_cqes()` for when you don't need to batch or peek.
301 pub fn copy_cqe(ring: *IO_Uring) !io_uring_cqe {301 pub fn copy_cqe(ring: *IO_Uring) !io_uring_cqe {
302 var cqes: [1]io_uring_cqe = undefined;302 var cqes: [1]io_uring_cqe = undefined;
303 const count = try ring.copy_cqes(&cqes, 1);303 while (true) {
304 assert(count == 1);304 const count = try ring.copy_cqes(&cqes, 1);
305 return cqes[0];305 if (count > 0) return cqes[0];
306 }
306 }307 }
307308
308 /// Matches the implementation of cq_ring_needs_flush() in liburing.309 /// Matches the implementation of cq_ring_needs_flush() in liburing.