std/os/index.zig: use "hw.logicalcpu" instead of "hw.ncpu" in macOS; (#1317)

Tracking Issue #1252 ;

hw.ncpu was deprecated in macOS. Among 4 new options available (hw.{physicalcpu, physicalcpu_max, logicalcpu, logicalcpu_max}), hw.logicalcpu was chosen because it actually reflects the number of logical cores the OS sees.
This commit is contained in:
kristopher tate 2018-08-03 01:59:59 +09:00 committed by Andrew Kelley
parent e66f538972
commit 432b7685bf

View File

@ -2790,7 +2790,7 @@ pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize {
builtin.Os.macosx => {
var count: c_int = undefined;
var count_len: usize = @sizeOf(c_int);
const rc = posix.sysctlbyname(c"hw.ncpu", @ptrCast(*c_void, &count), &count_len, null, 0);
const rc = posix.sysctlbyname(c"hw.logicalcpu", @ptrCast(*c_void, &count), &count_len, null, 0);
const err = posix.getErrno(rc);
switch (err) {
0 => return @intCast(usize, count),