diff options
author | Brad King <brad.king@kitware.com> | 2017-04-12 13:10:22 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-04-12 13:10:22 (GMT) |
commit | ada8e0cac4b50d07f4d07ecd584bf00e7afd3ac5 (patch) | |
tree | c336973c11619343de55064f40353059ad010fcf /Source/kwsys/SystemInformation.cxx | |
parent | fddd559406558a2037733e5b760e9dd04e9edfd1 (diff) | |
parent | 85841e8bd5e678f69271272db7f838f873347812 (diff) | |
download | CMake-ada8e0cac4b50d07f4d07ecd584bf00e7afd3ac5.zip CMake-ada8e0cac4b50d07f4d07ecd584bf00e7afd3ac5.tar.gz CMake-ada8e0cac4b50d07f4d07ecd584bf00e7afd3ac5.tar.bz2 |
Merge branch 'upstream-KWSys' into update-kwsys
* upstream-KWSys:
KWSys 2017-04-12 (23a4c211)
Diffstat (limited to 'Source/kwsys/SystemInformation.cxx')
-rw-r--r-- | Source/kwsys/SystemInformation.cxx | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index 93312e9..70f1a43 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/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 } |