summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2019-09-11 15:15:39 (GMT)
committerZachary Ware <zachary.ware@gmail.com>2019-09-11 15:15:39 (GMT)
commitaa929273caca2f4e24e3aa9e790272fd4458ad35 (patch)
treecaf4d6d037b22ec3574ccff27d4e3b8cdec1194e /Modules/posixmodule.c
parente20134f889a0cfcc37a46979f31a1c98b800de07 (diff)
downloadcpython-aa929273caca2f4e24e3aa9e790272fd4458ad35.zip
cpython-aa929273caca2f4e24e3aa9e790272fd4458ad35.tar.gz
cpython-aa929273caca2f4e24e3aa9e790272fd4458ad35.tar.bz2
bpo-33166: Change os.cpu_count to return active (real) processors (GH-15949)
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c20
1 files changed, 3 insertions, 17 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 88d3d83..089572f 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -12204,23 +12204,9 @@ os_cpu_count_impl(PyObject *module)
{
int ncpu = 0;
#ifdef MS_WINDOWS
- /* Vista is supported and the GetMaximumProcessorCount API is Win7+
- Need to fallback to Vista behavior if this call isn't present */
- HINSTANCE hKernel32;
- static DWORD(CALLBACK *_GetMaximumProcessorCount)(WORD) = NULL;
- Py_BEGIN_ALLOW_THREADS
- hKernel32 = GetModuleHandleW(L"KERNEL32");
- *(FARPROC*)&_GetMaximumProcessorCount = GetProcAddress(hKernel32,
- "GetMaximumProcessorCount");
- Py_END_ALLOW_THREADS
- if (_GetMaximumProcessorCount != NULL) {
- ncpu = _GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
- }
- else {
- SYSTEM_INFO sysinfo;
- GetSystemInfo(&sysinfo);
- ncpu = sysinfo.dwNumberOfProcessors;
- }
+ /* Declare prototype here to avoid pulling in all of the Win7 APIs in 3.8 */
+ DWORD WINAPI GetActiveProcessorCount(WORD group);
+ ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
#elif defined(__hpux)
ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)