authorgravatar for semarie@online.frSébastien Marie <semarie@online.fr> 2020-11-10 05:25:59+00:00
committergravatar for semarie@online.frSébastien Marie <semarie@online.fr> 2020-11-10 05:25:59+00:00
log8784c7b581b8a21c3698c4564e2a912676adaa2e
tree247e7e69085df023675dc859e4996952be34ead9
parent20b19d0092a70999ff58a0f8969e64ec4ecf6c2e

openbsd: proper implementation for Thread.cpuCount()


2 files changed, 13 insertions(+), 0 deletions(-)

lib/std/os/bits/openbsd.zig+3
......@@ -292,10 +292,13 @@ pub const AI_ADDRCONFIG = 64;
292292
293293pub const CTL_KERN = 1;
294294pub const CTL_DEBUG = 5;
295pub const CTL_HW = 6;
295296
296297pub const KERN_PROC_ARGS = 55;
297298pub const KERN_PROC_ARGV = 1;
298299
300pub const HW_NCPUONLINE = 25;
301
299302pub const PATH_MAX = 1024;
300303
301304pub const STDIN_FILENO = 0;
lib/std/thread.zig+10
......@@ -491,6 +491,16 @@ pub const Thread = struct {
491491 if (std.Target.current.os.tag == .windows) {
492492 return os.windows.peb().NumberOfProcessors;
493493 }
494 if (std.Target.current.os.tag == .openbsd) {
495 var count: c_int = undefined;
496 var count_size: usize = @sizeOf(c_int);
497 const mib = [_]c_int{ os.CTL_HW, os.HW_NCPUONLINE };
498 os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) {
499 error.NameTooLong, error.UnknownName => unreachable,
500 else => |e| return e,
501 };
502 return @intCast(usize, count);
503 }
494504 var count: c_int = undefined;
495505 var count_len: usize = @sizeOf(c_int);
496506 const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu";