diff options
author | Jan Niklas Hasse <jhasse@bixense.com> | 2019-02-26 13:37:19 (GMT) |
---|---|---|
committer | Jan Niklas Hasse <jhasse@bixense.com> | 2019-02-26 13:37:19 (GMT) |
commit | 1bcc689324bdee090eed035353724abc3fa7c909 (patch) | |
tree | 4d715c5dc7846a8c18dbfe71324aebc711ba3605 /src | |
parent | a683551cc77b5f25cb18914b59d93a1b54e3c64a (diff) | |
download | Ninja-1bcc689324bdee090eed035353724abc3fa7c909.zip Ninja-1bcc689324bdee090eed035353724abc3fa7c909.tar.gz Ninja-1bcc689324bdee090eed035353724abc3fa7c909.tar.bz2 |
Take CPU set limitations into account when calculating processor count
Fixes #1278.
Diffstat (limited to 'src')
-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 } |