aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Thread
diff options
context:
space:
mode:
authorPat Tullmann <pat.github@tullmann.org>2025-04-02 16:14:50 -0700
committerPat Tullmann <pat.github@tullmann.org>2025-06-17 22:06:39 -0700
commitcfe5defd025b79ade5f9243a7d6ebaad176cb6ad (patch)
tree7f85cd11d09dac313910d64610a8ceae649360bc /lib/std/Thread
parent850655f06b7dd8dc6e637d4980e6b7f9ac1b43d9 (diff)
downloadzig-cfe5defd025b79ade5f9243a7d6ebaad176cb6ad.tar.gz
zig-cfe5defd025b79ade5f9243a7d6ebaad176cb6ad.zip
linux: futex v1 API cleanup
* Use `packed struct` for flags arguments. So, instead of `linux.FUTEX.WAIT` use `.{ .cmd = .WAIT, .private = true }` * rename `futex_wait` and `futex_wake` which didn't actually specify wait/wake, as `futex_3arg` and `futex_4arg` (as its the number of parameters that is different, the `op` is whatever is specified. * expose the full six-arg flavor of the syscall (for some of the advanced ops), and add packed structs for their arguments. * Use a `packed union` to support the 4th parameter which is sometimes a `timespec` pointer, and sometimes a `u32`. * Add tests that make sure the structure layout is correct and that the basic argument passing is working (no actual futexes are contended).
Diffstat (limited to 'lib/std/Thread')
-rw-r--r--lib/std/Thread/Futex.zig16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/std/Thread/Futex.zig b/lib/std/Thread/Futex.zig
index 5e942924c3..aecf646424 100644
--- a/lib/std/Thread/Futex.zig
+++ b/lib/std/Thread/Futex.zig
@@ -262,10 +262,10 @@ const LinuxImpl = struct {
ts.nsec = @as(@TypeOf(ts.nsec), @intCast(timeout_ns % std.time.ns_per_s));
}
- const rc = linux.futex_wait(
- @as(*const i32, @ptrCast(&ptr.raw)),
- linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT,
- @as(i32, @bitCast(expect)),
+ const rc = linux.futex_4arg(
+ &ptr.raw,
+ .{ .cmd = .WAIT, .private = true },
+ expect,
if (timeout != null) &ts else null,
);
@@ -284,10 +284,10 @@ const LinuxImpl = struct {
}
fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
- const rc = linux.futex_wake(
- @as(*const i32, @ptrCast(&ptr.raw)),
- linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
- std.math.cast(i32, max_waiters) orelse std.math.maxInt(i32),
+ const rc = linux.futex_3arg(
+ &ptr.raw,
+ .{ .cmd = .WAKE, .private = true },
+ @min(max_waiters, std.math.maxInt(i32)),
);
switch (linux.E.init(rc)) {