From 5ff1fc724f7f53d921599dbe18e6f96b298233f1 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 2 Sep 2024 11:24:11 +0200 Subject: [PATCH] win: fix uv_available_parallelism on win32 (#4525) Fixes commit 58dfb6c89b from a few days ago. DWORD_PTR is 32 bits on x86 Windows. Use the right bit count when checking the population count. Interestingly enough, it manifested itself as double counting online processors, presumably because the compiler emits a ROR instead of SHR. Fixes: https://github.com/libuv/libuv/issues/4524 --- src/win/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/util.c b/src/win/util.c index 1cc42fd4..e0dba1aa 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -516,7 +516,7 @@ unsigned int uv_available_parallelism(void) { */ count = 0; if (GetProcessAffinityMask(GetCurrentProcess(), &procmask, &sysmask)) - for (i = 0; i < 64; i++) /* a.k.a. count = popcount(procmask); */ + for (i = 0; i < 8 * sizeof(procmask); i++) count += 1 & (procmask >> i); if (count > 0)