| author | |
| committer | |
| log | 7b323f84ca876c86bbe06f132d5a5d3775def3a2 |
| tree | aa136c9710efbc131c138d658a9bb000475de5b9 |
| parent | c6fb968a3d702fbf8067164052ccf562f5e362ef |
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) |
| 45 | else if (target.os.tag == .linux) | 45 | else if (target.os.tag == .linux) |
| 46 | LinuxThreadImpl | 46 | LinuxThreadImpl |
| 47 | else | 47 | else |
| 48 | @compileLog("Unsupported operating system", target.os.tag); | 48 | UnsupportedImpl; |
| 49 | 49 | ||
| 50 | impl: Impl, | 50 | impl: Impl, |
| 51 | 51 | ||
| ... | @@ -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 | } |
| 202 | 202 | ||
| 203 | const 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 | |||
| 203 | const WindowsThreadImpl = struct { | 237 | const WindowsThreadImpl = struct { |
| 204 | const windows = os.windows; | 238 | const windows = os.windows; |
| 205 | 239 | ||
| ... | @@ -725,7 +759,9 @@ const LinuxThreadImpl = struct { | ... | @@ -725,7 +759,9 @@ const LinuxThreadImpl = struct { |
| 725 | \\ li a7, 93 | 759 | \\ li a7, 93 |
| 726 | \\ ecall | 760 | \\ 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, ...)`. |
| 66 | pub fn wake(ptr: *const Atomic(u32), num_waiters: u32) void { | 66 | pub 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 | } |
| 73 | 72 | ||
| ... | @@ -80,7 +79,23 @@ else if (target.isDarwin()) | ... | @@ -80,7 +79,23 @@ else if (target.isDarwin()) |
| 80 | else if (std.builtin.link_libc) | 79 | else if (std.builtin.link_libc) |
| 81 | PosixFutex | 80 | PosixFutex |
| 82 | else | 81 | else |
| 83 | @compileError("Operating System unsupported"); | 82 | UnsupportedFutex; |
| 83 | |||
| 84 | const 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 | }; | ||
| 84 | 99 | ||
| 85 | const WindowsFutex = struct { | 100 | const WindowsFutex = struct { |
| 86 | const windows = std.os.windows; | 101 | const windows = std.os.windows; |