summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-11-21 16:12:56 -0800
committerVito Caputo <vcaputo@pengaru.com>2023-05-23 21:17:08 -0700
commite72be78e98b166e5b6dcdc7ec7b22d2b4d9ee5ca (patch)
treec498140e9b4afaf97cebb7483628c0a5b86ed7cd /src
parent49017136713f4cec7ed1dc5b6256988176616e9a (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/til_util.c15
1 files changed, 15 insertions, 0 deletions
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 <windows.h>
#endif
+#ifdef __MACH__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#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;
© All Rights Reserved