diff options
author | Ron Yorston <rmy@pobox.com> | 2024-06-23 09:35:35 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-06-23 09:44:03 +0100 |
commit | b07c177b446498ccd739b367f9e80337c3dfa55a (patch) | |
tree | 8230bce5f937e46ae1a6f18677904d2eccc4ae9e /coreutils/nproc.c | |
parent | 1b094d366f808a2ebc4824004f0d6f75f13c09cb (diff) | |
parent | a6ce017a8a2db09c6f23aa6abf7ce21fd00c2fdf (diff) | |
download | busybox-w32-b07c177b446498ccd739b367f9e80337c3dfa55a.tar.gz busybox-w32-b07c177b446498ccd739b367f9e80337c3dfa55a.tar.bz2 busybox-w32-b07c177b446498ccd739b367f9e80337c3dfa55a.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'coreutils/nproc.c')
-rw-r--r-- | coreutils/nproc.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/coreutils/nproc.c b/coreutils/nproc.c index 7c91a286f..5faa57a65 100644 --- a/coreutils/nproc.c +++ b/coreutils/nproc.c | |||
@@ -23,7 +23,6 @@ | |||
23 | //usage: "\n --ignore=N Exclude N CPUs" | 23 | //usage: "\n --ignore=N Exclude N CPUs" |
24 | //usage: ) | 24 | //usage: ) |
25 | 25 | ||
26 | #include <sched.h> | ||
27 | #include "libbb.h" | 26 | #include "libbb.h" |
28 | 27 | ||
29 | int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 28 | int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -59,16 +58,16 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
59 | } | 58 | } |
60 | } else | 59 | } else |
61 | #endif | 60 | #endif |
62 | if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) { | 61 | { |
63 | int i; | 62 | int i; |
64 | for (i = 0; i < ARRAY_SIZE(mask); i++) { | 63 | unsigned sz = 2 * 1024; |
65 | unsigned long m = mask[i]; | 64 | unsigned long *mask = get_malloc_cpu_affinity(0, &sz); |
66 | while (m) { | 65 | sz /= sizeof(long); |
67 | if (m & 1) | 66 | for (i = 0; i < sz; i++) { |
68 | count++; | 67 | if (mask[i] != 0) /* most mask[i] are usually 0 */ |
69 | m >>= 1; | 68 | count += bb_popcnt_long(mask[i]); |
70 | } | ||
71 | } | 69 | } |
70 | IF_FEATURE_CLEAN_UP(free(mask);) | ||
72 | } | 71 | } |
73 | #else /* ENABLE_PLATFORM_MINGW32 */ | 72 | #else /* ENABLE_PLATFORM_MINGW32 */ |
74 | if (GetProcessAffinityMask(GetCurrentProcess(), &process_affinity, | 73 | if (GetProcessAffinityMask(GetCurrentProcess(), &process_affinity, |