diff --git a/src/aio.zig b/src/aio.zig index c1d9496..92509fd 100644 --- a/src/aio.zig +++ b/src/aio.zig @@ -138,6 +138,29 @@ pub const ChildExit = ops.ChildExit; pub const Socket = ops.Socket; pub const CloseSocket = ops.CloseSocket; +test "shared outputs" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var f = try tmp.dir.createFile("test", .{}); + defer f.close(); + var id1: Id = @enumFromInt(69); + var id2: Id = undefined; + var id3: Id = undefined; + var counter1: u16 = 0; + var counter2: u16 = 2; + try multi(.{ + Fsync{ .file = f, .out_id = &id1, .counter = .{ .inc = &counter1 } }, + Fsync{ .file = f, .out_id = &id2, .counter = .{ .inc = &counter1 } }, + Fsync{ .file = f, .out_id = &id3, .counter = .{ .dec = &counter2 } }, + }); + try std.testing.expect(id1 != @as(Id, @enumFromInt(69))); + try std.testing.expect(id1 != id2); + try std.testing.expect(id1 != id3); + try std.testing.expect(id2 != id3); + try std.testing.expect(counter1 == 2); + try std.testing.expect(counter2 == 1); +} + test "Fsync" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/src/aio/linux.zig b/src/aio/linux.zig index fdd9f74..b482527 100644 --- a/src/aio/linux.zig +++ b/src/aio/linux.zig @@ -63,7 +63,7 @@ pub fn complete(self: *@This(), mode: aio.Dynamic.CompletionMode) aio.Completion } pub fn immediate(comptime len: u16, work: anytype) aio.ImmediateError!aio.CompletionResult { - var io = try uring_init(len); + var io = try uring_init(try std.math.ceilPowerOfTwo(u16, len)); defer io.deinit(); inline for (&work.ops, 0..) |*op, idx| try uring_queue(&io, op, idx); var num = try uring_submit(&io);