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)...@@ -45,7 +45,7 @@ else if (use_pthreads)
45else if (target.os.tag == .linux)45else if (target.os.tag == .linux)
46 LinuxThreadImpl46 LinuxThreadImpl
47else47else
48 @compileLog("Unsupported operating system", target.os.tag);48 UnsupportedImpl;
4949
50impl: Impl,50impl: Impl,
5151
...@@ -200,6 +200,40 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {...@@ -200,6 +200,40 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
200 }200 }
201}201}
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
203const WindowsThreadImpl = struct {237const WindowsThreadImpl = struct {
204 const windows = os.windows;238 const windows = os.windows;
205239
...@@ -725,7 +759,9 @@ const LinuxThreadImpl = struct {...@@ -725,7 +759,9 @@ const LinuxThreadImpl = struct {
725 \\ li a7, 93759 \\ li a7, 93
726 \\ ecall760 \\ ecall
727 ),761 ),
728 else => @compileError("Platform not supported"),762 else => |cpu_arch| {
763 @compileLog("linux arch", cpu_arch, "is not supported");
764 },
729 });765 });
730 }766 }
731 }767 }
lib/std/Thread/Futex.zig+20-5
...@@ -64,10 +64,9 @@ pub fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut}...@@ -64,10 +64,9 @@ pub fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut}
64/// Unblocks at most `num_waiters` callers blocked in a `wait()` call on `ptr`.64/// Unblocks at most `num_waiters` callers blocked in a `wait()` call on `ptr`.
65/// `num_waiters` of 1 unblocks at most one `wait(ptr, ...)` and `maxInt(u32)` unblocks effectively all `wait(ptr, ...)`.65/// `num_waiters` of 1 unblocks at most one `wait(ptr, ...)` and `maxInt(u32)` unblocks effectively all `wait(ptr, ...)`.
66pub fn wake(ptr: *const Atomic(u32), num_waiters: u32) void {66pub fn wake(ptr: *const Atomic(u32), num_waiters: u32) void {
67 if (num_waiters == 0 or single_threaded) {67 if (single_threaded) return;
68 return;68 if (num_waiters == 0) return;
69 }69
70
71 return OsFutex.wake(ptr, num_waiters);70 return OsFutex.wake(ptr, num_waiters);
72}71}
7372
...@@ -80,7 +79,23 @@ else if (target.isDarwin())...@@ -80,7 +79,23 @@ else if (target.isDarwin())
80else if (std.builtin.link_libc)79else if (std.builtin.link_libc)
81 PosixFutex80 PosixFutex
82else81else
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
85const WindowsFutex = struct {100const WindowsFutex = struct {
86 const windows = std.os.windows;101 const windows = std.os.windows;