diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-11-22 18:49:18 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-11-22 19:08:55 -0700 |
| commit | 70931dbdea96d92feb60406c827e39e566317863 (patch) | |
| tree | ee569fab186e848d73de1e4dbc272ff5f9f6b7c1 /lib/std/Thread.zig | |
| parent | edb2f72988cd180c5d87b03481fa1c20b3325968 (diff) | |
| download | zig-70931dbdea96d92feb60406c827e39e566317863.tar.gz zig-70931dbdea96d92feb60406c827e39e566317863.zip | |
rework std.atomic
* move std.atomic.Atomic to std.atomic.Value
* fix incorrect argument order passed to testing.expectEqual
* make the functions be a thin wrapper over the atomic builtins and
stick to the naming conventions.
* remove pointless functions loadUnchecked and storeUnchecked. Instead,
name the field `raw` instead of `value` (which is redundant with the
type name).
* simplify the tests by not passing every possible combination. Many
cases were iterating over every possible combinations but then not
even using the for loop element value!
* remove the redundant compile errors which are already implemented by
the language itself.
* remove dead x86 inline assembly. this should be implemented in the
language if at all.
Diffstat (limited to 'lib/std/Thread.zig')
| -rw-r--r-- | lib/std/Thread.zig | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index d3ace9e46a..36a02bab6b 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -8,7 +8,6 @@ const math = std.math; const os = std.os; const assert = std.debug.assert; const target = builtin.target; -const Atomic = std.atomic.Atomic; pub const Futex = @import("Thread/Futex.zig"); pub const ResetEvent = @import("Thread/ResetEvent.zig"); @@ -388,7 +387,7 @@ pub fn yield() YieldError!void { } /// State to synchronize detachment of spawner thread to spawned thread -const Completion = Atomic(enum(u8) { +const Completion = std.atomic.Value(enum(u8) { running, detached, completed, @@ -746,7 +745,7 @@ const WasiThreadImpl = struct { const WasiThread = struct { /// Thread ID - tid: Atomic(i32) = Atomic(i32).init(0), + tid: std.atomic.Value(i32) = std.atomic.Value(i32).init(0), /// Contains all memory which was allocated to bootstrap this thread, including: /// - Guard page /// - Stack @@ -784,7 +783,7 @@ const WasiThreadImpl = struct { original_stack_pointer: [*]u8, }; - const State = Atomic(enum(u8) { running, completed, detached }); + const State = std.atomic.Value(enum(u8) { running, completed, detached }); fn getCurrentId() Id { return tls_thread_id; @@ -1048,7 +1047,7 @@ const LinuxThreadImpl = struct { const ThreadCompletion = struct { completion: Completion = Completion.init(.running), - child_tid: Atomic(i32) = Atomic(i32).init(1), + child_tid: std.atomic.Value(i32) = std.atomic.Value(i32).init(1), parent_tid: i32 = undefined, mapped: []align(std.mem.page_size) u8, @@ -1304,7 +1303,7 @@ const LinuxThreadImpl = struct { @intFromPtr(instance), &instance.thread.parent_tid, tls_ptr, - &instance.thread.child_tid.value, + &instance.thread.child_tid.raw, ))) { .SUCCESS => return Impl{ .thread = &instance.thread }, .AGAIN => return error.ThreadQuotaExceeded, @@ -1346,7 +1345,7 @@ const LinuxThreadImpl = struct { } switch (linux.getErrno(linux.futex_wait( - &self.thread.child_tid.value, + &self.thread.child_tid.raw, linux.FUTEX.WAIT, tid, null, @@ -1387,7 +1386,7 @@ test "setName, getName" { test_done_event: ResetEvent = .{}, thread_done_event: ResetEvent = .{}, - done: std.atomic.Atomic(bool) = std.atomic.Atomic(bool).init(false), + done: std.atomic.Value(bool) = std.atomic.Value(bool).init(false), thread: Thread = undefined, pub fn run(ctx: *@This()) !void { |
