Skip to content

Commit 3fee8e5

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 <[email protected]>
1 parent b98f990 commit 3fee8e5

File tree

7 files changed

+70
-58
lines changed

7 files changed

+70
-58
lines changed

lib/std/Io/Threaded.zig

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,7 @@ fn dirStatPathLinux(
12661266
var path_buffer: [posix.PATH_MAX]u8 = undefined;
12671267
const sub_path_posix = try pathToPosix(sub_path, &path_buffer);
12681268

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

12721271
while (true) {
12731272
try t.checkCancel();
@@ -1276,7 +1275,13 @@ fn dirStatPathLinux(
12761275
dir.handle,
12771276
sub_path_posix,
12781277
flags,
1279-
linux.STATX_TYPE | linux.STATX_MODE | linux.STATX_ATIME | linux.STATX_MTIME | linux.STATX_CTIME,
1278+
.{
1279+
.type = true,
1280+
.mode = true,
1281+
.atime = true,
1282+
.mtime = true,
1283+
.ctime = true,
1284+
},
12801285
&statx,
12811286
);
12821287
switch (linux.E.init(rc)) {
@@ -1422,8 +1427,14 @@ fn fileStatLinux(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File
14221427
const rc = linux.statx(
14231428
file.handle,
14241429
"",
1425-
linux.AT.EMPTY_PATH,
1426-
linux.STATX_TYPE | linux.STATX_MODE | linux.STATX_ATIME | linux.STATX_MTIME | linux.STATX_CTIME,
1430+
.{ .empty_path = true },
1431+
.{
1432+
.type = true,
1433+
.mode = true,
1434+
.atime = true,
1435+
.mtime = true,
1436+
.ctime = true,
1437+
},
14271438
&statx,
14281439
);
14291440
switch (linux.E.init(rc)) {
@@ -5838,7 +5849,7 @@ pub fn futexWake(ptr: *const std.atomic.Value(u32), max_waiters: u32) void {
58385849
.linux => {
58395850
const linux = std.os.linux;
58405851
switch (linux.E.init(linux.futex_3arg(
5841-
&ptr.raw,
5852+
ptr,
58425853
.{ .cmd = .WAKE, .private = true },
58435854
@min(max_waiters, std.math.maxInt(i32)),
58445855
))) {

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.E.init(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;
@@ -755,7 +756,7 @@ pub const futex_param4 = extern union {
755756
/// The futex_op parameter is a sub-command and flags. The sub-command
756757
/// defines which of the subsequent paramters are relevant.
757758
pub fn futex(
758-
uaddr: *const u32,
759+
uaddr: *const atomic.Value(u32),
759760
futex_op: FUTEX_OP,
760761
val: u32,
761762
val2timeout: futex_param4,
@@ -775,7 +776,7 @@ pub fn futex(
775776

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

787788
/// Four-argument variation on the v1 futex call. Only suitable for
788789
/// futex_op that ignores the remaining arguments (e.g., FUTEX_OP.WAIT).
789-
pub fn futex_4arg(uaddr: *const u32, futex_op: FUTEX_OP, val: u32, timeout: ?*const timespec) usize {
790+
pub fn futex_4arg(uaddr: *const atomic.Value(u32), futex_op: FUTEX_OP, val: u32, timeout: ?*const timespec) usize {
790791
return syscall4(
791792
if (@hasField(SYS, "futex") and native_arch != .hexagon) .futex else .futex_time64,
792793
@intFromPtr(uaddr),
@@ -839,7 +840,7 @@ pub fn futex2_waitv(
839840
/// Requires at least kernel v6.7.
840841
pub fn futex2_wait(
841842
/// Address of the futex to wait on.
842-
uaddr: *const u32,
843+
uaddr: *const atomic.Value(u32),
843844
/// Value of `uaddr`.
844845
val: usize,
845846
/// Bitmask to match against incoming wakeup masks. Must not be zero.
@@ -868,7 +869,7 @@ pub fn futex2_wait(
868869
/// Requires at least kernel v6.7.
869870
pub fn futex2_wake(
870871
/// Futex to wake
871-
uaddr: *const u32,
872+
uaddr: *const atomic.Value(u32),
872873
/// Bitmask to match against waiters.
873874
mask: Futex2.Bitset,
874875
/// 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));
@@ -7458,7 +7458,7 @@ test "bind/listen/connect" {
74587458

74597459
const listen_fd = brk: {
74607460
// Create socket
7461-
_ = try ring.socket(1, @enumFromInt(addr.any.family), .{ .type = .stream, .flags = .{ .cloexec = true } }, @enumFromInt(proto), 0);
7461+
_ = try ring.socket(1, @enumFromInt(addr.family), .{ .type = .stream, .flags = .{ .cloexec = true } }, @enumFromInt(proto), 0);
74627462
try testing.expectEqual(1, try ring.submit());
74637463
var cqe = try ring.copy_cqe();
74647464
try testing.expectEqual(1, cqe.user_data);
@@ -7470,7 +7470,7 @@ test "bind/listen/connect" {
74707470
var optval: u32 = 1;
74717471
(try ring.setsockopt(2, listen_fd, .socket, .reuseaddr, mem.asBytes(&optval))).link_next();
74727472
(try ring.setsockopt(3, listen_fd, .socket, .reuseport, mem.asBytes(&optval))).link_next();
7473-
(try ring.bind(4, listen_fd, addrAny(&addr), @sizeOf(linux.sockaddr.in), 0)).link_next();
7473+
(try ring.bind(4, listen_fd, addrAny(&addr), @sizeOf(linux.sockaddr.in))).link_next();
74747474
_ = try ring.listen(5, listen_fd, 1);
74757475
// Submit 4 operations
74767476
try testing.expectEqual(4, try ring.submit());

0 commit comments

Comments
 (0)