From c17396691ce116a949618cb03d740997c7e80788 Mon Sep 17 00:00:00 2001 From: Al Hoang <3811822-hoanga@users.noreply.gitlab.com> Date: Sun, 17 Jan 2021 13:29:00 -0600 Subject: initial support for haiku sync update * add cpu count * use haiku find_directory * add definitions and exports for building in haiku --- lib/std/Thread.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/std/Thread.zig') diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 80de19fe19..52f625edf4 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -504,6 +504,13 @@ pub fn cpuCount() CpuCountError!usize { }; return @intCast(usize, count); } + if (std.Target.current.os.tag == .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); + } 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"; @@ -538,6 +545,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"); }, -- cgit v1.2.3 From 37a1d08de2ce263439713180f57741d16fb27e23 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 25 Feb 2021 16:54:32 -0700 Subject: haiku: minor fixups * no isHaiku() function since there is not more than one os tag that this applies to. * clean up some control flow into a switch * add some TODO comments to investigate panics that suspiciously look like they should be compile errors (see #363) --- lib/std/Thread.zig | 66 +++++++++++++++++++++++++++++------------------------- lib/std/os.zig | 10 ++++----- lib/std/target.zig | 4 ---- 3 files changed, 40 insertions(+), 40 deletions(-) (limited to 'lib/std/Thread.zig') diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 52f625edf4..77277bd154 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -487,38 +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); - } - if (std.Target.current.os.tag == .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); + 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 { diff --git a/lib/std/os.zig b/lib/std/os.zig index 8d5c680b26..6b13ec94c9 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3892,7 +3892,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t { } } } - if (comptime std.Target.current.isHaiku()) { + if (std.Target.current.os.tag == .haiku) { var fds: [2]fd_t = try pipe(); if (flags == 0) return fds; errdefer { @@ -3939,10 +3939,10 @@ pub fn sysctl( newlen: usize, ) SysCtlError!void { if (builtin.os.tag == .wasi) { - @panic("unsupported"); + @panic("unsupported"); // TODO should be compile error, not panic } if (builtin.os.tag == .haiku) { - @panic("unsupported"); + @panic("unsupported"); // TODO should be compile error, not panic } const name_len = math.cast(c_uint, name.len) catch return error.NameTooLong; @@ -3966,10 +3966,10 @@ pub fn sysctlbynameZ( newlen: usize, ) SysCtlError!void { if (builtin.os.tag == .wasi) { - @panic("unsupported"); + @panic("unsupported"); // TODO should be compile error, not panic } if (builtin.os.tag == .haiku) { - @panic("unsupported"); + @panic("unsupported"); // TODO should be compile error, not panic } switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) { diff --git a/lib/std/target.zig b/lib/std/target.zig index bf0492624d..7e05f35932 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -1339,10 +1339,6 @@ pub const Target = struct { return self.os.tag.isDarwin(); } - pub fn isHaiku(self: Target) bool { - return self.os.tag == .haiku; - } - pub fn isGnuLibC_os_tag_abi(os_tag: Os.Tag, abi: Abi) bool { return os_tag == .linux and abi.isGnu(); } -- cgit v1.2.3