Commit 7b323f84ca
Changed files (2)
lib
std
Thread
lib/std/Thread/Futex.zig
@@ -64,10 +64,9 @@ pub fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut}
/// Unblocks at most `num_waiters` callers blocked in a `wait()` call on `ptr`.
/// `num_waiters` of 1 unblocks at most one `wait(ptr, ...)` and `maxInt(u32)` unblocks effectively all `wait(ptr, ...)`.
pub fn wake(ptr: *const Atomic(u32), num_waiters: u32) void {
- if (num_waiters == 0 or single_threaded) {
- return;
- }
-
+ if (single_threaded) return;
+ if (num_waiters == 0) return;
+
return OsFutex.wake(ptr, num_waiters);
}
@@ -80,7 +79,23 @@ else if (target.isDarwin())
else if (std.builtin.link_libc)
PosixFutex
else
- @compileError("Operating System unsupported");
+ UnsupportedFutex;
+
+const UnsupportedFutex = struct {
+ fn wait(ptr: *const Atomic(u32), expect: u32, timeout: ?u64) error{TimedOut}!void {
+ return unsupported(.{ptr, expect, timeout});
+ }
+
+ fn wake(ptr: *const Atomic(u32), num_waiters: u32) void {
+ return unsupported(.{ptr, num_waiters});
+ }
+
+ fn unsupported(unused: anytype) noreturn {
+ @compileLog("Unsupported operating system", target.os.tag);
+ _ = unused;
+ unreachable;
+ }
+};
const WindowsFutex = struct {
const windows = std.os.windows;
lib/std/Thread.zig
@@ -45,7 +45,7 @@ else if (use_pthreads)
else if (target.os.tag == .linux)
LinuxThreadImpl
else
- @compileLog("Unsupported operating system", target.os.tag);
+ UnsupportedImpl;
impl: Impl,
@@ -200,6 +200,40 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
}
}
+const UnsupportedImpl = struct {
+ pub const ThreadHandle = void;
+
+ fn getCurrentId() u64 {
+ return unsupported({});
+ }
+
+ fn getCpuCount() !usize {
+ return unsupported({});
+ }
+
+ fn spawn(config: SpawnConfig, comptime f: anytype, args: anytype) !Impl {
+ return unsupported(.{config, f, args});
+ }
+
+ fn getHandle(self: Impl) ThreadHandle {
+ return unsupported(self);
+ }
+
+ fn detach(self: Impl) void {
+ return unsupported(self);
+ }
+
+ fn join(self: Impl) void {
+ return unsupported(self);
+ }
+
+ fn unsupported(unusued: anytype) noreturn {
+ @compileLog("Unsupported operating system", target.os.tag);
+ _ = unusued;
+ unreachable;
+ }
+};
+
const WindowsThreadImpl = struct {
const windows = os.windows;
@@ -725,7 +759,9 @@ const LinuxThreadImpl = struct {
\\ li a7, 93
\\ ecall
),
- else => @compileError("Platform not supported"),
+ else => |cpu_arch| {
+ @compileLog("linux arch", cpu_arch, "is not supported");
+ },
});
}
}