authorgravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-26 13:00:54-05:00
committergravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-30 21:49:00-05:00
log7b323f84ca876c86bbe06f132d5a5d3775def3a2
treeaa136c9710efbc131c138d658a9bb000475de5b9
parentc6fb968a3d702fbf8067164052ccf562f5e362ef

std.Thread: more fixes


2 files changed, 58 insertions(+), 7 deletions(-)

lib/std/Thread.zig+38-2
......@@ -45,7 +45,7 @@ else if (use_pthreads)
4545else if (target.os.tag == .linux)
4646 LinuxThreadImpl
4747else
48 @compileLog("Unsupported operating system", target.os.tag);
48 UnsupportedImpl;
4949
5050impl: Impl,
5151
......@@ -200,6 +200,40 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
200200 }
201201}
202202
203const UnsupportedImpl = struct {
204 pub const ThreadHandle = void;
205
206 fn getCurrentId() u64 {
207 return unsupported({});
208 }
209
210 fn getCpuCount() !usize {
211 return unsupported({});
212 }
213
214 fn spawn(config: SpawnConfig, comptime f: anytype, args: anytype) !Impl {
215 return unsupported(.{config, f, args});
216 }
217
218 fn getHandle(self: Impl) ThreadHandle {
219 return unsupported(self);
220 }
221
222 fn detach(self: Impl) void {
223 return unsupported(self);
224 }
225
226 fn join(self: Impl) void {
227 return unsupported(self);
228 }
229
230 fn unsupported(unusued: anytype) noreturn {
231 @compileLog("Unsupported operating system", target.os.tag);
232 _ = unusued;
233 unreachable;
234 }
235};
236
203237const WindowsThreadImpl = struct {
204238 const windows = os.windows;
205239
......@@ -725,7 +759,9 @@ const LinuxThreadImpl = struct {
725759 \\ li a7, 93
726760 \\ ecall
727761 ),
728 else => @compileError("Platform not supported"),
762 else => |cpu_arch| {
763 @compileLog("linux arch", cpu_arch, "is not supported");
764 },
729765 });
730766 }
731767 }
lib/std/Thread/Futex.zig+20-5
......@@ -64,10 +64,9 @@ pub fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut}
6464/// Unblocks at most `num_waiters` callers blocked in a `wait()` call on `ptr`.
6565/// `num_waiters` of 1 unblocks at most one `wait(ptr, ...)` and `maxInt(u32)` unblocks effectively all `wait(ptr, ...)`.
6666pub fn wake(ptr: *const Atomic(u32), num_waiters: u32) void {
67 if (num_waiters == 0 or single_threaded) {
68 return;
69 }
70
67 if (single_threaded) return;
68 if (num_waiters == 0) return;
69
7170 return OsFutex.wake(ptr, num_waiters);
7271}
7372
......@@ -80,7 +79,23 @@ else if (target.isDarwin())
8079else if (std.builtin.link_libc)
8180 PosixFutex
8281else
83 @compileError("Operating System unsupported");
82 UnsupportedFutex;
83
84const UnsupportedFutex = struct {
85 fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut}!void {
86 return unsupported(.{ptr, expect, timeout});
87 }
88
89 fn wake(ptr: *const Atomic(u32), num_waiters: u32) void {
90 return unsupported(.{ptr, num_waiters});
91 }
92
93 fn unsupported(unused: anytype) noreturn {
94 @compileLog("Unsupported operating system", target.os.tag);
95 _ = unused;
96 unreachable;
97 }
98};
8499
85100const WindowsFutex = struct {
86101 const windows = std.os.windows;