From e72be78e98b166e5b6dcdc7ec7b22d2b4d9ee5ca Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 21 Nov 2019 16:12:56 -0800 Subject: util: add macos support for getting number of CPUs Without this mac builds w/brew must be falling through the single CPU default linux failure code. --- src/til_util.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/til_util.c b/src/til_util.c index e9b1021..dd2fca2 100644 --- a/src/til_util.c +++ b/src/til_util.c @@ -7,6 +7,11 @@ #include #endif +#ifdef __MACH__ +#include +#include +#endif + #include "til_util.h" #define TIL_SYSFS_CPU "/sys/devices/system/cpu/cpu" @@ -20,6 +25,16 @@ unsigned til_get_ncpus(void) GetSystemInfo(&sysinfo); return sysinfo.dwNumberOfProcessors; +#endif + +#ifdef __MACH__ + int count; + size_t count_len = sizeof(count); + + if (sysctlbyname("hw.logicalcpu_max", &count, &count_len, NULL, 0) < 0) + return 1; + + return count; #else char path[cstrlen(TIL_SYSFS_CPU "1024") + 1]; unsigned n; -- cgit v1.2.3