| ... | ... | @@ -24,16 +24,14 @@ pub const Condition = @import("Thread/Condition.zig"); |
| 24 | 24 | pub const spinLoopHint = @compileError("deprecated: use std.atomic.spinLoopHint"); |
| 25 | 25 | |
| 26 | 26 | test "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; |
| 37 | 35 | } |
| 38 | 36 | |
| 39 | 37 | pub const use_pthreads = target.os.tag != .windows and std.builtin.link_libc; |
| ... | ... | @@ -114,17 +112,13 @@ pub const SpawnError = error { |
| 114 | 112 | /// `config` can be used as hints to the platform for now to spawn and execute the `function`. |
| 115 | 113 | /// The caller must eventually either call `join()` to wait for the thread to finish and free its resources |
| 116 | 114 | /// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`. |
| 117 | | pub fn spawn( |
| 118 | | config: SpawnConfig, |
| 119 | | comptime function: anytype, |
| 120 | | args: std.meta.ArgsTuple(function), |
| 121 | | ) SpawnError!Thread { |
| 115 | pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread { |
| 122 | 116 | if (std.builtin.single_threaded) { |
| 123 | 117 | @compileError("cannot spawn thread when building in single-threaded mode"); |
| 124 | 118 | } |
| 125 | 119 | |
| 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 }; |
| 128 | 122 | } |
| 129 | 123 | |
| 130 | 124 | /// Represents a kernel thread handle. |
| ... | ... | @@ -438,7 +432,7 @@ const LinuxThreadImpl = struct { |
| 438 | 432 | |
| 439 | 433 | fn getCurrentId() Id { |
| 440 | 434 | return tls_thread_id orelse { |
| 441 | | const tid = linux.gettid(); |
| 435 | const tid = @bitCast(u32, linux.gettid()); |
| 442 | 436 | tls_thread_id = tid; |
| 443 | 437 | return tid; |
| 444 | 438 | }; |
| ... | ... | @@ -550,7 +544,7 @@ const LinuxThreadImpl = struct { |
| 550 | 544 | const instance = @ptrCast(*Instance, @alignCast(@alignOf(Instance), &mapped[instance_offset])); |
| 551 | 545 | instance.* = .{ |
| 552 | 546 | .fn_args = args, |
| 553 | | .thread = .{ .mapped = .mapped }, |
| 547 | .thread = .{ .mapped = mapped }, |
| 554 | 548 | }; |
| 555 | 549 | |
| 556 | 550 | const flags: u32 = os.CLONE_VM | os.CLONE_FS | os.CLONE_FILES | |
| ... | ... | @@ -591,7 +585,7 @@ const LinuxThreadImpl = struct { |
| 591 | 585 | } |
| 592 | 586 | |
| 593 | 587 | fn join(self: Impl) void { |
| 594 | | defer self.thread.free(); |
| 588 | defer os.munmap(self.thread.mapped); |
| 595 | 589 | |
| 596 | 590 | var spin: u8 = 10; |
| 597 | 591 | while (true) { |