summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Niklas Hasse <jhasse@bixense.com>2019-02-26 14:37:19 +0100
committerJan Niklas Hasse <jhasse@bixense.com>2019-02-26 14:37:19 +0100
commit1bcc689324bdee090eed035353724abc3fa7c909 (patch)
tree4d715c5dc7846a8c18dbfe71324aebc711ba3605
parenta683551cc77b5f25cb18914b59d93a1b54e3c64a (diff)
downloadninja-1bcc689324bdee090eed035353724abc3fa7c909.tar.gz
Take CPU set limitations into account when calculating processor count
Fixes #1278.
-rw-r--r--src/util.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index 47a5de2..ee810d6 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -485,6 +485,15 @@ int GetProcessorCount() {
GetNativeSystemInfo(&info);
return info.dwNumberOfProcessors;
#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
+ cpu_set_t set;
+ if (sched_getaffinity(getpid(), sizeof(set), &set) == 0) {
+ return CPU_COUNT(&set);
+ }
+#endif
return sysconf(_SC_NPROCESSORS_ONLN);
#endif
}