authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-25 16:54:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-25 16:54:32-07:00
log37a1d08de2ce263439713180f57741d16fb27e23
tree9c6eae297ebc492c0a1a94a4d3d25fc3bcd07bd9
parent96a08c1698189baa01e051bcee2c488ba594fa0c

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)

3 files changed, 40 insertions(+), 40 deletions(-)

lib/std/Thread.zig+35-31
......@@ -487,38 +487,42 @@ pub const CpuCountError = error{
487487};
488488
489489pub fn cpuCount() CpuCountError!usize {
490 if (std.Target.current.os.tag == .linux) {
491 const cpu_set = try os.sched_getaffinity(0);
492 return @as(usize, os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast
493 }
494 if (std.Target.current.os.tag == .windows) {
495 return os.windows.peb().NumberOfProcessors;
496 }
497 if (std.Target.current.os.tag == .openbsd) {
498 var count: c_int = undefined;
499 var count_size: usize = @sizeOf(c_int);
500 const mib = [_]c_int{ os.CTL_HW, os.HW_NCPUONLINE };
501 os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) {
502 error.NameTooLong, error.UnknownName => unreachable,
503 else => |e| return e,
504 };
505 return @intCast(usize, count);
506 }
507 if (std.Target.current.os.tag == .haiku) {
508 var count: u32 = undefined;
509 var system_info: os.system_info = undefined;
510 const rc = os.system.get_system_info(&system_info);
511 count = system_info.cpu_count;
512 return @intCast(usize, count);
490 switch (std.Target.current.os.tag) {
491 .linux => {
492 const cpu_set = try os.sched_getaffinity(0);
493 return @as(usize, os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast
494 },
495 .windows => {
496 return os.windows.peb().NumberOfProcessors;
497 },
498 .openbsd => {
499 var count: c_int = undefined;
500 var count_size: usize = @sizeOf(c_int);
501 const mib = [_]c_int{ os.CTL_HW, os.HW_NCPUONLINE };
502 os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) {
503 error.NameTooLong, error.UnknownName => unreachable,
504 else => |e| return e,
505 };
506 return @intCast(usize, count);
507 },
508 .haiku => {
509 var count: u32 = undefined;
510 var system_info: os.system_info = undefined;
511 const rc = os.system.get_system_info(&system_info);
512 count = system_info.cpu_count;
513 return @intCast(usize, count);
514 },
515 else => {
516 var count: c_int = undefined;
517 var count_len: usize = @sizeOf(c_int);
518 const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
519 os.sysctlbynameZ(name, &count, &count_len, null, 0) catch |err| switch (err) {
520 error.NameTooLong, error.UnknownName => unreachable,
521 else => |e| return e,
522 };
523 return @intCast(usize, count);
524 },
513525 }
514 var count: c_int = undefined;
515 var count_len: usize = @sizeOf(c_int);
516 const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
517 os.sysctlbynameZ(name, &count, &count_len, null, 0) catch |err| switch (err) {
518 error.NameTooLong, error.UnknownName => unreachable,
519 else => |e| return e,
520 };
521 return @intCast(usize, count);
522526}
523527
524528pub fn getCurrentThreadId() u64 {
lib/std/os.zig+5-5
......@@ -3892,7 +3892,7 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
38923892 }
38933893 }
38943894 }
3895 if (comptime std.Target.current.isHaiku()) {
3895 if (std.Target.current.os.tag == .haiku) {
38963896 var fds: [2]fd_t = try pipe();
38973897 if (flags == 0) return fds;
38983898 errdefer {
......@@ -3939,10 +3939,10 @@ pub fn sysctl(
39393939 newlen: usize,
39403940) SysCtlError!void {
39413941 if (builtin.os.tag == .wasi) {
3942 @panic("unsupported");
3942 @panic("unsupported"); // TODO should be compile error, not panic
39433943 }
39443944 if (builtin.os.tag == .haiku) {
3945 @panic("unsupported");
3945 @panic("unsupported"); // TODO should be compile error, not panic
39463946 }
39473947
39483948 const name_len = math.cast(c_uint, name.len) catch return error.NameTooLong;
......@@ -3966,10 +3966,10 @@ pub fn sysctlbynameZ(
39663966 newlen: usize,
39673967) SysCtlError!void {
39683968 if (builtin.os.tag == .wasi) {
3969 @panic("unsupported");
3969 @panic("unsupported"); // TODO should be compile error, not panic
39703970 }
39713971 if (builtin.os.tag == .haiku) {
3972 @panic("unsupported");
3972 @panic("unsupported"); // TODO should be compile error, not panic
39733973 }
39743974
39753975 switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) {
lib/std/target.zig-4
......@@ -1339,10 +1339,6 @@ pub const Target = struct {
13391339 return self.os.tag.isDarwin();
13401340 }
13411341
1342 pub fn isHaiku(self: Target) bool {
1343 return self.os.tag == .haiku;
1344 }
1345
13461342 pub fn isGnuLibC_os_tag_abi(os_tag: Os.Tag, abi: Abi) bool {
13471343 return os_tag == .linux and abi.isGnu();
13481344 }