Skip to content

Commit

Permalink
win: fix uv_available_parallelism on win32 (libuv#4525)
Browse files Browse the repository at this point in the history
Fixes commit 58dfb6c 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: libuv#4524
(cherry picked from commit 5ff1fc7)
  • Loading branch information
bnoordhuis authored and giordano committed Sep 2, 2024
1 parent c57e7f0 commit 69814ce
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/win/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,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)
Expand Down

0 comments on commit 69814ce

Please sign in to comment.