{
int ncpu = 0;
#ifdef MS_WINDOWS
- SYSTEM_INFO sysinfo;
- GetSystemInfo(&sysinfo);
- ncpu = sysinfo.dwNumberOfProcessors;
+ /* Vista is supported and the GetMaximumProcessorCount API is Win7+
+ Need to fallback to Vista behavior if this call isn't present */
+ HINSTANCE hKernel32;
+ hKernel32 = GetModuleHandleW(L"KERNEL32");
+
+ static DWORD(CALLBACK *_GetMaximumProcessorCount)(WORD) = NULL;
+ *(FARPROC*)&_GetMaximumProcessorCount = GetProcAddress(hKernel32,
+ "GetMaximumProcessorCount");
+ if (_GetMaximumProcessorCount != NULL) {
+ ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
+ }
+ else {
+ SYSTEM_INFO sysinfo;
+ GetSystemInfo(&sysinfo);
+ ncpu = sysinfo.dwNumberOfProcessors;
+ }
#elif defined(__hpux)
ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)