Skip to content

Commit

Permalink
io_uring: remove NOP queue on nonblocking mode
Browse files Browse the repository at this point in the history
This is not needed, and the reason it was there was probably related to
the earlier commit.
  • Loading branch information
Cloudef committed Jun 28, 2024
1 parent 81dd499 commit 350564e
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/aio/IoUring.zig
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,15 @@ pub fn queue(self: *@This(), comptime len: u16, work: anytype, cb: ?aio.Dynamic.
self.pending += len;
}

pub const NOP = std.math.maxInt(u64);

/// TODO: give options perhaps? More customization?
pub fn complete(self: *@This(), mode: aio.Dynamic.CompletionMode, cb: ?aio.Dynamic.CompletionCallback) aio.Error!aio.CompletionResult {
if (self.pending == 0) return .{};

if (mode == .nonblocking) {
var last = &self.io.sq.sqes[self.io.sq.sqe_tail & self.io.sq.mask];
_ = try self.io.nop(NOP);
// it is error to have these on the last operation
last.flags &= ~@as(u8, std.os.linux.IOSQE_IO_LINK | std.os.linux.IOSQE_IO_HARDLINK);
self.pending += 1;
}

_ = try uring_submit(&self.io);

var result: aio.CompletionResult = .{};
const n = try uring_copy_cqes(&self.io, self.cqes, 1);
const n = try uring_copy_cqes(&self.io, self.cqes, if (mode == .nonblocking) 0 else 1);
for (self.cqes[0..n]) |*cqe| {
if (cqe.user_data == NOP) continue;
const uop = self.ops.get(@intCast(cqe.user_data)).*;
var failed: bool = false;
switch (uop) {
Expand All @@ -139,7 +128,7 @@ pub fn complete(self: *@This(), mode: aio.Dynamic.CompletionMode, cb: ?aio.Dynam
}

self.pending -= n;
result.num_completed = n - @intFromBool(mode == .nonblocking);
result.num_completed = n;
return result;
}

Expand Down

0 comments on commit 350564e

Please sign in to comment.