Skip to content

Commit

Permalink
Take CPU set into account when determining concurrency on Linux. (mic…
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwixz authored Feb 6, 2024
1 parent 9c1e418 commit df2ef84
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <sys/sysctl.h>
#endif

#if defined(__linux__)
#include <sched.h>
#endif

#if defined(_WIN32)
#include <lmcons.h>
#include <winbase.h>
Expand Down Expand Up @@ -686,6 +690,15 @@ namespace vcpkg
}
else
{
#if defined(__linux__)
// Get the number of threads we are allowed to run on,
// this might be less than the number of hardware threads.
cpu_set_t set;
if (sched_getaffinity(getpid(), sizeof(set), &set) == 0)
{
return static_cast<unsigned int>(CPU_COUNT(&set)) + 1;
}
#endif
return std::thread::hardware_concurrency() + 1;
}
}();
Expand Down

0 comments on commit df2ef84

Please sign in to comment.