From 0ca202556c6ffc4f4fb8acd17d0854fdc0b0a2df Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 9 Sep 2023 12:01:36 +0000 Subject: ipc: define _SC_NPROCESSORS_ONLN for NetBSD We'll reorganize this into a hash table for ease-of-reading. --- lib/PublicInbox/IPC.pm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'lib/PublicInbox/IPC.pm') diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm index 528b9133..39021f42 100644 --- a/lib/PublicInbox/IPC.pm +++ b/lib/PublicInbox/IPC.pm @@ -451,12 +451,18 @@ sub DESTROY { ipc_worker_stop($self); } +# _SC_NPROCESSORS_ONLN = 84 on both Linux glibc and musl, +# emitted using: $^X devel/sysdefs-list +my %NPROCESSORS_ONLN = ( + linux => 84, + freebsd => 58, + openbsd => 503, + netbsd => 1002 +); + sub detect_nproc () { - # _SC_NPROCESSORS_ONLN = 84 on both Linux glibc and musl - return POSIX::sysconf(84) if $^O eq 'linux'; - return POSIX::sysconf(58) if $^O eq 'freebsd'; - return POSIX::sysconf(503) if $^O eq 'openbsd'; - # TODO: more OSes + my $n = $NPROCESSORS_ONLN{$^O}; + return POSIX::sysconf($n) if defined $n; # getconf(1) is POSIX, but *NPROCESSORS* vars are not for (qw(_NPROCESSORS_ONLN NPROCESSORS_ONLN)) { -- cgit v1.2.3-24-ge0c7