Skip to content

Commit e763959

Browse files
bnoordhuisgiordano
authored andcommitted
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 (cherry picked from commit 58dfb6c)
1 parent ca3a5a4 commit e763959

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
@@ -513,19 +513,23 @@ int uv_uptime(double* uptime) {
513513

514514

515515
unsigned int uv_available_parallelism(void) {
516-
SYSTEM_INFO info;
517-
unsigned rc;
516+
DWORD_PTR procmask;
517+
DWORD_PTR sysmask;
518+
int count;
519+
int i;
518520

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

524-
rc = info.dwNumberOfProcessors;
525-
if (rc < 1)
526-
rc = 1;
529+
if (count > 0)
530+
return count;
527531

528-
return rc;
532+
return 1;
529533
}
530534

531535

0 commit comments

Comments
 (0)