diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-05 12:43:29 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-05 12:43:29 +0200 |
commit | 0716da1da363236e85dd8e49deb74818cdab0dba (patch) | |
tree | 534cdbef10e52fb1cfcb3740003edde7286bfd77 | |
parent | e12bec15829441ced304102d66f3b0db0fb17c72 (diff) | |
parent | 0056ffe061639184faf72432e5aa27b0915de65b (diff) | |
download | psutil-0716da1da363236e85dd8e49deb74818cdab0dba.tar.gz |
Merge branch 'master' of github.com:giampaolo/psutil
-rw-r--r-- | psutil/_psutil_windows.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index a1a68857..53617c58 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -495,6 +495,7 @@ psutil_cpu_count_phys(PyObject *self, PyObject *args) { DWORD length = 0; DWORD offset = 0; DWORD ncpus = 0; + DWORD prev_processor_info_size = 0; // GetLogicalProcessorInformationEx() is available from Windows 7 // onward. Differently from GetLogicalProcessorInformation() @@ -533,13 +534,20 @@ psutil_cpu_count_phys(PyObject *self, PyObject *args) { } ptr = buffer; - while (ptr->Size > 0 && offset + ptr->Size <= length) { + while (offset < length) { + // Advance ptr by the size of the previous + // SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX struct. + ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)\ + (((char*)ptr) + prev_processor_info_size); + if (ptr->Relationship == RelationProcessorCore) { ncpus += 1; } + + // When offset == length, we've reached the last processor + // info struct in the buffer. offset += ptr->Size; - ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)\ - (((char*)ptr) + ptr->Size); + prev_processor_info_size = ptr->Size; } free(buffer); |