mirror of
https://github.com/reactos/CMake.git
synced 2024-11-28 14:01:21 +00:00
d7204e649e
Run the `clang-format.bash` script to update all our C and C++ code to a new style defined by `.clang-format`. Use `clang-format` version 6.0. * If you reached this commit for a line in `git blame`, re-run the blame operation starting at the parent of this commit to see older history for the content. * See the parent commit for instructions to rebase a change across this style transition commit.
63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
|
#include "cmAffinity.h"
|
|
|
|
#include "cm_uv.h"
|
|
|
|
#ifndef CMAKE_USE_SYSTEM_LIBUV
|
|
# ifdef _WIN32
|
|
# define CM_HAVE_CPU_AFFINITY
|
|
# include <windows.h>
|
|
# elif defined(__linux__) || defined(__FreeBSD__)
|
|
# define CM_HAVE_CPU_AFFINITY
|
|
# include <pthread.h>
|
|
# include <sched.h>
|
|
# if defined(__FreeBSD__)
|
|
# include <pthread_np.h>
|
|
# include <sys/cpuset.h>
|
|
# include <sys/param.h>
|
|
# endif
|
|
# if defined(__linux__)
|
|
typedef cpu_set_t cm_cpuset_t;
|
|
# else
|
|
typedef cpuset_t cm_cpuset_t;
|
|
# endif
|
|
# endif
|
|
#endif
|
|
|
|
namespace cmAffinity {
|
|
|
|
std::set<size_t> GetProcessorsAvailable()
|
|
{
|
|
std::set<size_t> processorsAvailable;
|
|
#ifdef CM_HAVE_CPU_AFFINITY
|
|
int cpumask_size = uv_cpumask_size();
|
|
if (cpumask_size > 0) {
|
|
# ifdef _WIN32
|
|
DWORD_PTR procmask;
|
|
DWORD_PTR sysmask;
|
|
if (GetProcessAffinityMask(GetCurrentProcess(), &procmask, &sysmask) !=
|
|
0) {
|
|
for (int i = 0; i < cpumask_size; ++i) {
|
|
if (procmask & (((DWORD_PTR)1) << i)) {
|
|
processorsAvailable.insert(i);
|
|
}
|
|
}
|
|
}
|
|
# else
|
|
cm_cpuset_t cpuset;
|
|
CPU_ZERO(&cpuset); // NOLINT(clang-tidy)
|
|
if (pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset) == 0) {
|
|
for (int i = 0; i < cpumask_size; ++i) {
|
|
if (CPU_ISSET(i, &cpuset)) {
|
|
processorsAvailable.insert(i);
|
|
}
|
|
}
|
|
}
|
|
# endif
|
|
}
|
|
#endif
|
|
return processorsAvailable;
|
|
}
|
|
}
|