]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
ipc: define _SC_NPROCESSORS_ONLN for NetBSD
authorEric Wong <e@80x24.org>
Sat, 9 Sep 2023 12:01:36 +0000 (12:01 +0000)
committerEric Wong <e@80x24.org>
Sat, 9 Sep 2023 21:31:54 +0000 (21:31 +0000)
We'll reorganize this into a hash table for ease-of-reading.

lib/PublicInbox/IPC.pm

index 528b91333742ffb30ccd5f71827929d0a07b1135..39021f4253d3260df56ed4afb6ff993e8a86f590 100644 (file)
@@ -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)) {