| ... | ... | @@ -487,38 +487,42 @@ pub const CpuCountError = error{ |
| 487 | 487 | }; |
| 488 | 488 | |
| 489 | 489 | pub 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 | }, |
| 513 | 525 | } |
| 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); |
| 522 | 526 | } |
| 523 | 527 | |
| 524 | 528 | pub fn getCurrentThreadId() u64 { |