summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Niklas Hasse <jhasse@bixense.com>2020-12-01 09:01:37 (GMT)
committerGitHub <noreply@github.com>2020-12-01 09:01:37 (GMT)
commit7cff4770b553e8a1a1eab9aefe093c6b95bdebb4 (patch)
tree2c67541c84e07f484264437df6aa7cf739f89b02
parented056bdd8c8d578a9952bd93b76f29c14199c85b (diff)
parent9d4ea5a8e81395672e0c3b59f8926ba48a223000 (diff)
downloadNinja-7cff4770b553e8a1a1eab9aefe093c6b95bdebb4.zip
Ninja-7cff4770b553e8a1a1eab9aefe093c6b95bdebb4.tar.gz
Ninja-7cff4770b553e8a1a1eab9aefe093c6b95bdebb4.tar.bz2
Merge pull request #1887 from mjguzik/freebsd_cpuset
Add FreeBSD support to GetProcessorCount
-rw-r--r--src/util.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/util.cc b/src/util.cc
index c76f730..05bdb2d 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -51,6 +51,10 @@
#include <sys/sysinfo.h>
#endif
+#if defined(__FreeBSD__)
+#include <sys/cpuset.h>
+#endif
+
#include "edit_distance.h"
#include "metrics.h"
@@ -485,10 +489,17 @@ int GetProcessorCount() {
#ifdef _WIN32
return GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
#else
-#ifdef CPU_COUNT
// The number of exposed processors might not represent the actual number of
// processors threads can run on. This happens when a CPU set limitation is
// active, see https://github.com/ninja-build/ninja/issues/1278
+#if defined(__FreeBSD__)
+ cpuset_t mask;
+ CPU_ZERO(&mask);
+ if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(mask),
+ &mask) == 0) {
+ return CPU_COUNT(&mask);
+ }
+#elif defined(CPU_COUNT)
cpu_set_t set;
if (sched_getaffinity(getpid(), sizeof(set), &set) == 0) {
return CPU_COUNT(&set);