diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-02-25 16:00:00 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-25 16:00:00 -0800 |
| commit | 7edb204edfa41e11776ac009da5a20fb1c907f5f (patch) | |
| tree | 9c6eae297ebc492c0a1a94a4d3d25fc3bcd07bd9 /lib/std/Thread.zig | |
| parent | 297eabd4accbcae42bfe821078a79e4af06a2dde (diff) | |
| parent | 37a1d08de2ce263439713180f57741d16fb27e23 (diff) | |
| download | zig-7edb204edfa41e11776ac009da5a20fb1c907f5f.tar.gz zig-7edb204edfa41e11776ac009da5a20fb1c907f5f.zip | |
Merge pull request #7546 from hoanga/haiku-support
initial support for haiku
Diffstat (limited to 'lib/std/Thread.zig')
| -rw-r--r-- | lib/std/Thread.zig | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 80de19fe19..77277bd154 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -487,31 +487,42 @@ pub const CpuCountError = error{ }; pub fn cpuCount() CpuCountError!usize { - if (std.Target.current.os.tag == .linux) { - const cpu_set = try os.sched_getaffinity(0); - return @as(usize, os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast - } - if (std.Target.current.os.tag == .windows) { - return os.windows.peb().NumberOfProcessors; - } - if (std.Target.current.os.tag == .openbsd) { - var count: c_int = undefined; - var count_size: usize = @sizeOf(c_int); - const mib = [_]c_int{ os.CTL_HW, os.HW_NCPUONLINE }; - os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) { - error.NameTooLong, error.UnknownName => unreachable, - else => |e| return e, - }; - return @intCast(usize, count); + switch (std.Target.current.os.tag) { + .linux => { + const cpu_set = try os.sched_getaffinity(0); + return @as(usize, os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast + }, + .windows => { + return os.windows.peb().NumberOfProcessors; + }, + .openbsd => { + var count: c_int = undefined; + var count_size: usize = @sizeOf(c_int); + const mib = [_]c_int{ os.CTL_HW, os.HW_NCPUONLINE }; + os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) { + error.NameTooLong, error.UnknownName => unreachable, + else => |e| return e, + }; + return @intCast(usize, count); + }, + .haiku => { + var count: u32 = undefined; + var system_info: os.system_info = undefined; + const rc = os.system.get_system_info(&system_info); + count = system_info.cpu_count; + return @intCast(usize, count); + }, + else => { + var count: c_int = undefined; + var count_len: usize = @sizeOf(c_int); + const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu"; + os.sysctlbynameZ(name, &count, &count_len, null, 0) catch |err| switch (err) { + error.NameTooLong, error.UnknownName => unreachable, + else => |e| return e, + }; + return @intCast(usize, count); + }, } - var count: c_int = undefined; - var count_len: usize = @sizeOf(c_int); - const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu"; - os.sysctlbynameZ(name, &count, &count_len, null, 0) catch |err| switch (err) { - error.NameTooLong, error.UnknownName => unreachable, - else => |e| return e, - }; - return @intCast(usize, count); } pub fn getCurrentThreadId() u64 { @@ -538,6 +549,9 @@ pub fn getCurrentThreadId() u64 { .openbsd => { return @bitCast(u32, c.getthrid()); }, + .haiku => { + return @bitCast(u32, c.find_thread(null)); + }, else => { @compileError("getCurrentThreadId not implemented for this platform"); }, |
