Skip to content

Commit 62fb6db

Browse files
committed
IoUring: Fix merge conflicts
use flags in Threaded change futex signature to expect *const atomic.Value(u32) fix IoUring timeout test Signed-off-by: Bernard Assan <mega.alpha100@gmail.com>
1 parent 0db6c94 commit 62fb6db

7 files changed

Lines changed: 74 additions & 58 deletions

File tree

lib/std/Io/Threaded.zig

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,8 +1289,7 @@ fn dirStatPathLinux(
12891289
var path_buffer: [posix.PATH_MAX]u8 = undefined;
12901290
const sub_path_posix = try pathToPosix(sub_path, &path_buffer);
12911291

1292-
const flags: u32 = linux.AT.NO_AUTOMOUNT |
1293-
@as(u32, if (!options.follow_symlinks) linux.AT.SYMLINK_NOFOLLOW else 0);
1292+
const flags: linux.At = .{ .no_automount = true, .symlink_nofollow = if (!options.follow_symlinks) true else false };
12941293

12951294
while (true) {
12961295
try t.checkCancel();
@@ -1299,7 +1298,15 @@ fn dirStatPathLinux(
12991298
dir.handle,
13001299
sub_path_posix,
13011300
flags,
1302-
linux.STATX_INO | linux.STATX_SIZE | linux.STATX_TYPE | linux.STATX_MODE | linux.STATX_ATIME | linux.STATX_MTIME | linux.STATX_CTIME,
1301+
.{
1302+
.ino = true,
1303+
.size = true,
1304+
.type = true,
1305+
.mode = true,
1306+
.atime = true,
1307+
.mtime = true,
1308+
.ctime = true,
1309+
},
13031310
&statx,
13041311
);
13051312
switch (linux.errno(rc)) {
@@ -1445,8 +1452,16 @@ fn fileStatLinux(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File
14451452
const rc = linux.statx(
14461453
file.handle,
14471454
"",
1448-
linux.AT.EMPTY_PATH,
1449-
linux.STATX_INO | linux.STATX_SIZE | linux.STATX_TYPE | linux.STATX_MODE | linux.STATX_ATIME | linux.STATX_MTIME | linux.STATX_CTIME,
1455+
.{ .empty_path = true },
1456+
.{
1457+
.ino = true,
1458+
.size = true,
1459+
.type = true,
1460+
.mode = true,
1461+
.atime = true,
1462+
.mtime = true,
1463+
.ctime = true,
1464+
},
14501465
&statx,
14511466
);
14521467
switch (linux.errno(rc)) {
@@ -5862,7 +5877,7 @@ pub fn futexWake(ptr: *const std.atomic.Value(u32), max_waiters: u32) void {
58625877
.linux => {
58635878
const linux = std.os.linux;
58645879
switch (linux.errno(linux.futex_3arg(
5865-
&ptr.raw,
5880+
ptr,
58665881
.{ .cmd = .WAKE, .private = true },
58675882
@min(max_waiters, std.math.maxInt(i32)),
58685883
))) {

lib/std/Thread.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,8 @@ const LinuxThreadImpl = struct {
12161216
thread: *ThreadCompletion,
12171217

12181218
const ThreadCompletion = struct {
1219-
completion: Completion = Completion.init(.running),
1220-
child_tid: std.atomic.Value(i32) = std.atomic.Value(i32).init(1),
1219+
completion: Completion = .init(.running),
1220+
child_tid: std.atomic.Value(i32) = .init(1),
12211221
parent_tid: i32 = undefined,
12221222
mapped: []align(std.heap.page_size_min) u8,
12231223

@@ -1662,7 +1662,7 @@ const LinuxThreadImpl = struct {
16621662
if (tid == 0) break;
16631663

16641664
switch (linux.errno(linux.futex_4arg(
1665-
@ptrCast(&self.thread.child_tid.raw),
1665+
@ptrCast(&self.thread.child_tid),
16661666
.{ .cmd = .WAIT, .private = false },
16671667
@bitCast(tid),
16681668
null,

lib/std/Thread/Futex.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ const LinuxImpl = struct {
263263
}
264264

265265
const rc = linux.futex_4arg(
266-
&ptr.raw,
266+
ptr,
267267
.{ .cmd = .WAIT, .private = true },
268268
expect,
269269
if (timeout != null) &ts else null,
@@ -285,7 +285,7 @@ const LinuxImpl = struct {
285285

286286
fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
287287
const rc = linux.futex_3arg(
288-
&ptr.raw,
288+
ptr,
289289
.{ .cmd = .WAKE, .private = true },
290290
@min(max_waiters, std.math.maxInt(i32)),
291291
);

lib/std/os/linux.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! * Implement all the syscalls in the same way that libc functions will
55
//! provide `rename` when only the `renameat` syscall exists.
66
const std = @import("../std.zig");
7+
const atomic = std.atomic;
78
const builtin = @import("builtin");
89
const assert = std.debug.assert;
910
const maxInt = std.math.maxInt;
@@ -754,7 +755,7 @@ pub const futex_param4 = extern union {
754755
/// The futex_op parameter is a sub-command and flags. The sub-command
755756
/// defines which of the subsequent paramters are relevant.
756757
pub fn futex(
757-
uaddr: *const u32,
758+
uaddr: *const atomic.Value(u32),
758759
futex_op: FUTEX_OP,
759760
val: u32,
760761
val2timeout: futex_param4,
@@ -774,7 +775,7 @@ pub fn futex(
774775

775776
/// Three-argument variation of the v1 futex call. Only suitable for a
776777
/// futex_op that ignores the remaining arguments (e.g., FUTUX_OP.WAKE).
777-
pub fn futex_3arg(uaddr: *const u32, futex_op: FUTEX_OP, val: u32) usize {
778+
pub fn futex_3arg(uaddr: *const atomic.Value(u32), futex_op: FUTEX_OP, val: u32) usize {
778779
return syscall3(
779780
if (@hasField(SYS, "futex") and native_arch != .hexagon) .futex else .futex_time64,
780781
@intFromPtr(uaddr),
@@ -785,7 +786,7 @@ pub fn futex_3arg(uaddr: *const u32, futex_op: FUTEX_OP, val: u32) usize {
785786

786787
/// Four-argument variation on the v1 futex call. Only suitable for
787788
/// futex_op that ignores the remaining arguments (e.g., FUTEX_OP.WAIT).
788-
pub fn futex_4arg(uaddr: *const u32, futex_op: FUTEX_OP, val: u32, timeout: ?*const timespec) usize {
789+
pub fn futex_4arg(uaddr: *const atomic.Value(u32), futex_op: FUTEX_OP, val: u32, timeout: ?*const timespec) usize {
789790
return syscall4(
790791
if (@hasField(SYS, "futex") and native_arch != .hexagon) .futex else .futex_time64,
791792
@intFromPtr(uaddr),
@@ -838,7 +839,7 @@ pub fn futex2_waitv(
838839
/// Requires at least kernel v6.7.
839840
pub fn futex2_wait(
840841
/// Address of the futex to wait on.
841-
uaddr: *const u32,
842+
uaddr: *const atomic.Value(u32),
842843
/// Value of `uaddr`.
843844
val: usize,
844845
/// Bitmask to match against incoming wakeup masks. Must not be zero.
@@ -867,7 +868,7 @@ pub fn futex2_wait(
867868
/// Requires at least kernel v6.7.
868869
pub fn futex2_wake(
869870
/// Futex to wake
870-
uaddr: *const u32,
871+
uaddr: *const atomic.Value(u32),
871872
/// Bitmask to match against waiters.
872873
mask: Futex2.Bitset,
873874
/// Maximum number of waiters on the futex to wake.

lib/std/os/linux/IoUring.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ pub fn socket(
16941694
domain: linux.Af,
16951695
socket_type: linux.Sock,
16961696
protocol: linux.IpProto,
1697-
/// flags is unused
1697+
/// flags are currently unused
16981698
flags: u32,
16991699
) !*Sqe {
17001700
const sqe = try self.get_sqe();
@@ -1711,7 +1711,7 @@ pub fn socket_direct(
17111711
domain: linux.Af,
17121712
socket_type: linux.Sock,
17131713
protocol: linux.IpProto,
1714-
/// flags is unused
1714+
/// flags are currently unused
17151715
flags: u32,
17161716
file_index: u32,
17171717
) !*Sqe {
@@ -1731,7 +1731,7 @@ pub fn socket_direct_alloc(
17311731
domain: linux.Af,
17321732
socket_type: linux.Sock,
17331733
protocol: linux.IpProto,
1734-
/// flags unused
1734+
/// flags are currently unused
17351735
flags: u32,
17361736
) !*Sqe {
17371737
const sqe = try self.get_sqe();
@@ -5377,8 +5377,8 @@ test "timeout (after a relative time)" {
53775377
};
53785378
defer ring.deinit();
53795379

5380-
const ms = 10;
5381-
const ts: linux.kernel_timespec = .{ .sec = 0, .nsec = ms * 1000000 };
5380+
const ms = 5;
5381+
const ts: linux.kernel_timespec = .{ .sec = 0, .nsec = ms * 1_000_000 };
53825382

53835383
const started = try std.Io.Clock.awake.now(io);
53845384
const sqe = try ring.timeout(0x55555555, &ts, 0, .{});
@@ -5394,9 +5394,9 @@ test "timeout (after a relative time)" {
53945394
}, cqe);
53955395

53965396
// Tests should not depend on timings: skip test if outside margin.
5397-
const margin = 5;
5397+
const ms_margin = 5;
53985398
const ms_elapsed = started.durationTo(stopped).toMilliseconds();
5399-
if (ms_elapsed > margin) return error.SkipZigTest;
5399+
if (ms_elapsed > ms_margin) return error.SkipZigTest;
54005400
}
54015401

54025402
test "timeout (after a number of completions)" {
@@ -5802,7 +5802,7 @@ test "shutdown" {
58025802
// Socket bound, expect shutdown to work
58035803
{
58045804
// TODO: update posix later to use Typed Flags
5805-
const server = try posix.socket(address.any.family, @as(u32, @bitCast(linux.Sock{ .type = .stream, .flags = .{ .cloexec = true } })), 0);
5805+
const server = try posix.socket(address.family, @as(u32, @bitCast(linux.Sock{ .type = .stream, .flags = .{ .cloexec = true } })), 0);
58065806
defer posix.close(server);
58075807
try posix.setsockopt(server, posix.SOL.SOCKET, posix.SO.REUSEADDR, &mem.toBytes(@as(u32, 1)));
58085808
try posix.bind(server, addrAny(&address), @sizeOf(linux.sockaddr.in));
@@ -7460,7 +7460,7 @@ test "bind/listen/connect" {
74607460

74617461
const listen_fd = brk: {
74627462
// Create socket
7463-
_ = try ring.socket(1, @enumFromInt(addr.any.family), .{ .type = .stream, .flags = .{ .cloexec = true } }, @enumFromInt(proto), 0);
7463+
_ = try ring.socket(1, @enumFromInt(addr.family), .{ .type = .stream, .flags = .{ .cloexec = true } }, @enumFromInt(proto), 0);
74647464
try testing.expectEqual(1, try ring.submit());
74657465
var cqe = try ring.copy_cqe();
74667466
try testing.expectEqual(1, cqe.user_data);
@@ -7472,7 +7472,7 @@ test "bind/listen/connect" {
74727472
var optval: u32 = 1;
74737473
(try ring.setsockopt(2, listen_fd, .socket, .reuseaddr, mem.asBytes(&optval))).link_next();
74747474
(try ring.setsockopt(3, listen_fd, .socket, .reuseport, mem.asBytes(&optval))).link_next();
7475-
(try ring.bind(4, listen_fd, addrAny(&addr), @sizeOf(linux.sockaddr.in), 0)).link_next();
7475+
(try ring.bind(4, listen_fd, addrAny(&addr), @sizeOf(linux.sockaddr.in))).link_next();
74767476
_ = try ring.listen(5, listen_fd, 1);
74777477
// Submit 4 operations
74787478
try testing.expectEqual(4, try ring.submit());

0 commit comments

Comments
 (0)