diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-19 15:50:29 -0800 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-19 15:50:29 -0800 |
| commit | 4a5bb37c29f91438656cf4b5c70197e78984dc29 (patch) | |
| tree | 9755eb45046237fd8d34a015132fef273b6bf09b /psutil | |
| parent | 53f5ef447a95fbda1ca514be576a5ba40134fd66 (diff) | |
| download | psutil-4a5bb37c29f91438656cf4b5c70197e78984dc29.tar.gz | |
port GetActiveProcessorCount
Diffstat (limited to 'psutil')
| -rw-r--r-- | psutil/_psutil_windows.c | 8 | ||||
| -rw-r--r-- | psutil/arch/windows/global.c | 9 | ||||
| -rw-r--r-- | psutil/arch/windows/global.h | 5 |
3 files changed, 15 insertions, 7 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index a3b08ad7..268d0645 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -205,15 +205,11 @@ unsigned int psutil_get_num_cpus(int fail_on_err) { unsigned int ncpus = 0; SYSTEM_INFO sysinfo; - static DWORD(CALLBACK *_GetActiveProcessorCount)(WORD) = NULL; - // GetActiveProcessorCount is available only on 64 bit versions // of Windows from Windows 7 onward. // Windows Vista 64 bit and Windows XP don't have it. - _GetActiveProcessorCount = \ - psutil_GetProcAddress("kernel32", "GetActiveProcessorCount"); - if (_GetActiveProcessorCount != NULL) { - ncpus = _GetActiveProcessorCount(ALL_PROCESSOR_GROUPS); + if (psutil_GetActiveProcessorCount != NULL) { + ncpus = psutil_GetActiveProcessorCount(ALL_PROCESSOR_GROUPS); if ((ncpus == 0) && (fail_on_err == 1)) { PyErr_SetFromWindowsErr(0); } diff --git a/psutil/arch/windows/global.c b/psutil/arch/windows/global.c index 6a50176b..bf30c605 100644 --- a/psutil/arch/windows/global.c +++ b/psutil/arch/windows/global.c @@ -51,6 +51,8 @@ ps_GetProcAddressFromLib(LPCSTR libname, LPCSTR procname) { int psutil_load_globals() { + // Mandatory. + psutil_NtQuerySystemInformation = ps_GetProcAddressFromLib( "ntdll.dll", "NtQuerySystemInformation"); if (psutil_NtQuerySystemInformation == NULL) @@ -64,7 +66,7 @@ psutil_load_globals() { psutil_NtSetInformationProcess = ps_GetProcAddress( "ntdll.dll", "NtSetInformationProcess"); if (! psutil_NtSetInformationProcess) - return NULL; + return 1; psutil_rtlIpv4AddressToStringA = ps_GetProcAddressFromLib( "ntdll.dll", "RtlIpv4AddressToStringA"); @@ -76,5 +78,10 @@ psutil_load_globals() { if (! psutil_rtlIpv6AddressToStringA) return 1; + // Optionals. + + psutil_GetActiveProcessorCount = ps_GetProcAddress( + "kernel32", "GetActiveProcessorCount"); + return 0; } diff --git a/psutil/arch/windows/global.h b/psutil/arch/windows/global.h index 9fa48e42..51bdd7f4 100644 --- a/psutil/arch/windows/global.h +++ b/psutil/arch/windows/global.h @@ -10,6 +10,8 @@ typedef PSTR (NTAPI * _RtlIpv4AddressToStringA)(struct in_addr *, PSTR); typedef PSTR (NTAPI * _RtlIpv6AddressToStringA)(struct in6_addr *, PSTR); typedef DWORD (_stdcall * NTQSI_PROC) (int, PVOID, ULONG, PULONG); +typedef DWORD (CALLBACK *_GetActiveProcessorCount)(WORD); + _RtlIpv4AddressToStringA \ psutil_rtlIpv4AddressToStringA; @@ -26,5 +28,8 @@ _NtSetInformationProcess NTQSI_PROC \ psutil_NtQuerySystemInformation; +_GetActiveProcessorCount \ + psutil_GetActiveProcessorCount; + int psutil_load_globals(); |
