summaryrefslogtreecommitdiffstats
path: root/src/util.cc
diff options
context:
space:
mode:
authorMateusz Guzik <mjguzik@gmail.com>2020-11-28 23:54:09 (GMT)
committerMateusz Guzik <mjguzik@gmail.com>2020-11-30 23:01:41 (GMT)
commit9d4ea5a8e81395672e0c3b59f8926ba48a223000 (patch)
tree2c67541c84e07f484264437df6aa7cf739f89b02 /src/util.cc
parented056bdd8c8d578a9952bd93b76f29c14199c85b (diff)
downloadNinja-9d4ea5a8e81395672e0c3b59f8926ba48a223000.zip
Ninja-9d4ea5a8e81395672e0c3b59f8926ba48a223000.tar.gz
Ninja-9d4ea5a8e81395672e0c3b59f8926ba48a223000.tar.bz2
Add FreeBSD support to GetProcessorCount
Diffstat (limited to 'src/util.cc')
-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);