From 7f7a64a1d6ef791d3b111245301d73902e9e4875 Mon Sep 17 00:00:00 2001 From: Waley Chen Date: Thu, 25 Feb 2016 18:09:15 -0500 Subject: SERVER-22398 Add SystemInfo::numAvailableCores --- src/mongo/util/processinfo_windows.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/mongo/util/processinfo_windows.cpp') diff --git a/src/mongo/util/processinfo_windows.cpp b/src/mongo/util/processinfo_windows.cpp index 224cd5a896a..e39fa6778da 100644 --- a/src/mongo/util/processinfo_windows.cpp +++ b/src/mongo/util/processinfo_windows.cpp @@ -31,6 +31,9 @@ #include "mongo/platform/basic.h" +#include +#include +#include #include #include @@ -73,6 +76,18 @@ ProcessInfo::ProcessInfo(ProcessId pid) {} ProcessInfo::~ProcessInfo() {} +// get the number of CPUs available to the current process +boost::optional ProcessInfo::getNumAvailableCores() { + DWORD_PTR process_mask, system_mask; + + if (GetProcessAffinityMask(GetCurrentProcess(), &process_mask, &system_mask)) { + std::bitset<32> mask(process_mask); + if (mask.count() > 0) + return mask.count(); + } + return boost::none; +} + bool ProcessInfo::supported() { return true; } -- cgit v1.2.1