summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-02-20 04:49:40 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2019-02-20 04:49:40 -0800
commita7ff4a33c2cb2c9cefa916a60016e0b9211758fa (patch)
treecb4084da9d3a01f9dafe892040710beb4086d4f3
parent8c54a5f7b96af534252b20ea8f87a93fbb10a1aa (diff)
downloadpsutil-a7ff4a33c2cb2c9cefa916a60016e0b9211758fa.tar.gz
port GetActiveProcessorCount
-rw-r--r--psutil/_psutil_windows.c7
-rw-r--r--psutil/arch/windows/global.c2
-rw-r--r--psutil/arch/windows/global.h8
3 files changed, 6 insertions, 11 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index d995f200..260e04a0 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -205,15 +205,12 @@ 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 026a3726..a185a9c2 100644
--- a/psutil/arch/windows/global.c
+++ b/psutil/arch/windows/global.c
@@ -92,13 +92,11 @@ psutil_load_globals() {
"iphlpapi.dll", "GetExtendedUdpTable");
if (! psutil_GetExtendedUdpTable)
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 4957200f..02ae6ca3 100644
--- a/psutil/arch/windows/global.h
+++ b/psutil/arch/windows/global.h
@@ -14,6 +14,7 @@ typedef DWORD (WINAPI * _GetExtendedTcpTable)(PVOID, PDWORD, BOOL, ULONG,
TCP_TABLE_CLASS, ULONG);
typedef DWORD (WINAPI * _GetExtendedUdpTable)(PVOID, PDWORD, BOOL, ULONG,
UDP_TABLE_CLASS, ULONG);
+typedef DWORD (CALLBACK *_GetActiveProcessorCount)(WORD);
// probably unnecessary?
/*
@@ -21,12 +22,8 @@ typedef DWORD (WINAPI * _GetExtendedUdpTable)(PVOID, PDWORD, BOOL, ULONG,
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
#endif
-typedef DWORD (CALLBACK *_GetActiveProcessorCount)(WORD);
typedef ULONGLONG (CALLBACK *_GetTickCount64)(void);
-_GetActiveProcessorCount \
- psutil_GetActiveProcessorCount;
-
_GetTickCount64 \
psutil_GetTickCount64;
@@ -56,5 +53,8 @@ _GetExtendedTcpTable \
_GetExtendedUdpTable \
psutil_GetExtendedUdpTable;
+_GetActiveProcessorCount \
+ psutil_GetActiveProcessorCount;
+
int psutil_load_globals();