summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-11-21 16:12:56 -0800
committerVito Caputo <vcaputo@pengaru.com>2019-11-21 16:12:56 -0800
commit4b39563c13db030c0997e5c32ad82f8f9041f5f0 (patch)
treef39bf9de484b1a5eb8830d93e0427cfa083a1b5a
parent796b3a8b0669ee5e09c6faba6614e3f228d36595 (diff)
util: add macos support for getting number of CPUsmac
Without this mac builds w/brew must be falling through the single CPU default linux failure code.
-rw-r--r--src/util.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 500ac75..49d938a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -7,6 +7,11 @@
#include <windows.h>
#endif
+#ifdef __MACH__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
#include "util.h"
#define SYSFS_CPU "/sys/devices/system/cpu/cpu"
@@ -20,6 +25,16 @@ unsigned 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(SYSFS_CPU "1024") + 1];
unsigned n;
© 2021 All Rights Reserved