summaryrefslogtreecommitdiffstats
path: root/SystemInformation.cxx
diff options
context:
space:
mode:
authorKWSys Upstream <kwrobot@kitware.com>2017-04-12 13:08:58 (GMT)
committerBrad King <brad.king@kitware.com>2017-04-12 13:10:22 (GMT)
commit85841e8bd5e678f69271272db7f838f873347812 (patch)
treeeb74d111e23c0b680a97ddb0a24d475983826100 /SystemInformation.cxx
parente9c5505bf9c51c34dea703b86a293ff04475db54 (diff)
downloadCMake-85841e8bd5e678f69271272db7f838f873347812.zip
CMake-85841e8bd5e678f69271272db7f838f873347812.tar.gz
CMake-85841e8bd5e678f69271272db7f838f873347812.tar.bz2
KWSys 2017-04-12 (23a4c211)
Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit 23a4c211e90c1cfd399c3632141dbd549a5db8cf (master). Upstream Shortlog ----------------- Brad King (2): 41a9dfef SystemInformation: Fix dynamic loader failure on WinXP SP2 3ead6158 SystemTools: Fix stat() wrapper compilation with Borland Daniel Pfeifer (1): ce5b0d34 Disable include-what-you-use Mathieu Westphal (1): a2bf6bb3 SystemTools: Add cross-platform stat() wrapper
Diffstat (limited to 'SystemInformation.cxx')
-rw-r--r--SystemInformation.cxx23
1 files changed, 20 insertions, 3 deletions
diff --git a/SystemInformation.cxx b/SystemInformation.cxx
index 93312e9..70f1a43 100644
--- a/SystemInformation.cxx
+++ b/SystemInformation.cxx
@@ -4341,18 +4341,35 @@ unsigned char SystemInformationImplementation::GetAPICId()
void SystemInformationImplementation::CPUCountWindows()
{
#if defined(_WIN32)
- std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> ProcInfo;
this->NumberOfPhysicalCPU = 0;
this->NumberOfLogicalCPU = 0;
+ typedef BOOL(WINAPI * GetLogicalProcessorInformationType)(
+ PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
+ static GetLogicalProcessorInformationType pGetLogicalProcessorInformation =
+ (GetLogicalProcessorInformationType)GetProcAddress(
+ GetModuleHandleW(L"kernel32"), "GetLogicalProcessorInformation");
+
+ if (!pGetLogicalProcessorInformation) {
+ // Fallback to approximate implementation on ancient Windows versions.
+ SYSTEM_INFO info;
+ ZeroMemory(&info, sizeof(info));
+ GetSystemInfo(&info);
+ this->NumberOfPhysicalCPU =
+ static_cast<unsigned int>(info.dwNumberOfProcessors);
+ this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
+ return;
+ }
+
+ std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> ProcInfo;
{
DWORD Length = 0;
- DWORD rc = GetLogicalProcessorInformation(NULL, &Length);
+ DWORD rc = pGetLogicalProcessorInformation(NULL, &Length);
assert(FALSE == rc);
(void)rc; // Silence unused variable warning in Borland C++ 5.81
assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
ProcInfo.resize(Length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
- rc = GetLogicalProcessorInformation(&ProcInfo[0], &Length);
+ rc = pGetLogicalProcessorInformation(&ProcInfo[0], &Length);
assert(rc != FALSE);
(void)rc; // Silence unused variable warning in Borland C++ 5.81
}