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
This commit is contained in:
Ben Noordhuis 2024-09-02 11:24:11 +02:00 committed by GitHub
parent f00d4b6775
commit 5ff1fc724f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)