diff options
-rw-r--r-- | src/util.cc | 9 |
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 } |