authorgravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-20 09:56:30-05:00
committergravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-30 21:49:00-05:00
logca1e61b851351ec66ee3f1937586a2f9d02bbafc
treeafc244dca5bbb1089e52ef55d22bb7eacfbd0dde
parent6ff64895cf0c8f331959d34dec5f4fa84e7c6365

std.Thread: fix some typos


2 files changed, 15 insertions(+), 21 deletions(-)

lib/std/Thread.zig+14-20
......@@ -24,16 +24,14 @@ pub const Condition = @import("Thread/Condition.zig");
2424pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint");
2525
2626test "std.Thread" {
27 if (!builtin.single_threaded) {
28 // Doesn't use testing.refAllDecls() since that would pull in the compileError spinLoopHint.
29 _ = AutoResetEvent;
30 _ = Futex;
31 _ = ResetEvent;
32 _ = StaticResetEvent;
33 _ = Mutex;
34 _ = Semaphore;
35 _ = Condition;
36 }
27 // Doesn't use testing.refAllDecls() since that would pull in the compileError spinLoopHint.
28 _ = AutoResetEvent;
29 _ = Futex;
30 _ = ResetEvent;
31 _ = StaticResetEvent;
32 _ = Mutex;
33 _ = Semaphore;
34 _ = Condition;
3735}
3836
3937pub const use_pthreads = target.os.tag != .windows and std.builtin.link_libc;
......@@ -114,17 +112,13 @@ pub const SpawnError = error {
114112/// `config` can be used as hints to the platform for now to spawn and execute the `function`.
115113/// The caller must eventually either call `join()` to wait for the thread to finish and free its resources
116114/// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`.
117pub fn spawn(
118 config: SpawnConfig,
119 comptime function: anytype,
120 args: std.meta.ArgsTuple(function),
121) SpawnError!Thread {
115pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread {
122116 if (std.builtin.single_threaded) {
123117 @compileError("cannot spawn thread when building in single-threaded mode");
124118 }
125119
126 const impl = try Thread.spawn(config, function, args);
127 return .{ .impl = impl };
120 const impl = try Impl.spawn(config, function, args);
121 return Thread{ .impl = impl };
128122}
129123
130124/// Represents a kernel thread handle.
......@@ -438,7 +432,7 @@ const LinuxThreadImpl = struct {
438432
439433 fn getCurrentId() Id {
440434 return tls_thread_id orelse {
441 const tid = linux.gettid();
435 const tid = @bitCast(u32, linux.gettid());
442436 tls_thread_id = tid;
443437 return tid;
444438 };
......@@ -550,7 +544,7 @@ const LinuxThreadImpl = struct {
550544 const instance = @ptrCast(*Instance, @alignCast(@alignOf(Instance), &mapped[instance_offset]));
551545 instance.* = .{
552546 .fn_args = args,
553 .thread = .{ .mapped = .mapped },
547 .thread = .{ .mapped = mapped },
554548 };
555549
556550 const flags: u32 = os.CLONE_VM | os.CLONE_FS | os.CLONE_FILES |
......@@ -591,7 +585,7 @@ const LinuxThreadImpl = struct {
591585 }
592586
593587 fn join(self: Impl) void {
594 defer self.thread.free();
588 defer os.munmap(self.thread.mapped);
595589
596590 var spin: u8 = 10;
597591 while (true) {
lib/std/Thread/Futex.zig+1-1
......@@ -544,7 +544,7 @@ test "Futex - Chain" {
544544
545545 for (self.threads) |*entry, index| {
546546 entry.signal = .{};
547 entry.thread = try std.Thread.spawn(.{}, runThread .{&self, index});
547 entry.thread = try std.Thread.spawn(.{}, runThread, .{&self, index});
548548 }
549549
550550 self.threads[0].signal.notify();