From: Baptiste Daroussin Date: Sat, 15 Apr 2017 14:25:08 +0000 (+0200) Subject: Enable multithreading on BSD X-Git-Tag: v1.2.0^2~44^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F659%2Fhead;p=thirdparty%2Fzstd.git Enable multithreading on BSD --- diff --git a/programs/util.h b/programs/util.h index b989e8232..5f437b2b2 100644 --- a/programs/util.h +++ b/programs/util.h @@ -657,6 +657,24 @@ failed: } } +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) + +/* Use apple-provided syscall + * see: man 3 sysctl */ +UTIL_STATIC int UTIL_countPhysicalCores(void) +{ + static int numPhysicalCores = 0; + + if (numPhysicalCores != 0) return numPhysicalCores; + + numPhysicalCores = (int)sysconf(_SC_NPROCESSORS_ONLN); + if (numPhysicalCores == -1) { + /* value not queryable, fall back on 1 */ + return numPhysicalCores = 1; + } + return numPhysicalCores; +} + #else UTIL_STATIC int UTIL_countPhysicalCores(void)