about summary refs log tree commit homepage
path: root/lib/PublicInbox/IPC.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-09-09 12:01:36 +0000
committerEric Wong <e@80x24.org>2023-09-09 21:31:54 +0000
commit0ca202556c6ffc4f4fb8acd17d0854fdc0b0a2df (patch)
tree0bf3416ee587863ce54e5314e9ba60e4e8703829 /lib/PublicInbox/IPC.pm
parent305ccc1e8502602b1fc766ba1a542c8edaf6a82a (diff)
downloadpublic-inbox-0ca202556c6ffc4f4fb8acd17d0854fdc0b0a2df.tar.gz
We'll reorganize this into a hash table for ease-of-reading.
Diffstat (limited to 'lib/PublicInbox/IPC.pm')
-rw-r--r--lib/PublicInbox/IPC.pm16
1 files changed, 11 insertions, 5 deletions
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)) {