Skip to content

Commit 58dfb6c

Browse files
authored
win: compute parallelism from process cpu affinity (libuv#4521)
Use GetProcessAffinityMask() to estimate the available parallelism. Before this commit, it simply used the number of available CPUs. Fixes: libuv#4520
1 parent b5eb41d commit 58dfb6c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/win/util.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,19 +512,23 @@ int uv_uptime(double* uptime) {
512512

513513

514514
unsigned int uv_available_parallelism(void) {
515-
SYSTEM_INFO info;
516-
unsigned rc;
515+
DWORD_PTR procmask;
516+
DWORD_PTR sysmask;
517+
int count;
518+
int i;
517519

518520
/* TODO(bnoordhuis) Use GetLogicalProcessorInformationEx() to support systems
519521
* with > 64 CPUs? See https://github.com/libuv/libuv/pull/3458
520522
*/
521-
GetSystemInfo(&info);
523+
count = 0;
524+
if (GetProcessAffinityMask(GetCurrentProcess(), &procmask, &sysmask))
525+
for (i = 0; i < 64; i++) /* a.k.a. count = popcount(procmask); */
526+
count += 1 & (procmask >> i);
522527

523-
rc = info.dwNumberOfProcessors;
524-
if (rc < 1)
525-
rc = 1;
528+
if (count > 0)
529+
return count;
526530

527-
return rc;
531+
return 1;
528532
}
529533

530534

0 commit comments

Comments
 (0)