aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-02-17 13:55:12 +0000
committerRon Yorston <rmy@pobox.com>2021-02-17 13:55:12 +0000
commit2d20b9d88c4fc91637babaafa4a60dd7943e03a7 (patch)
tree7c4df30c9160457f174b7c33d331f889a24f84b1 /coreutils
parentd2804fc6020aad3f9d0ed914d8c2aefa37ffa6d8 (diff)
downloadbusybox-w32-2d20b9d88c4fc91637babaafa4a60dd7943e03a7.tar.gz
busybox-w32-2d20b9d88c4fc91637babaafa4a60dd7943e03a7.tar.bz2
busybox-w32-2d20b9d88c4fc91637babaafa4a60dd7943e03a7.zip
nproc: port to WIN32 and enable by default
Use the WIN32 API GetProcessAffinityMask() to obtain the number of processors configured and the number available to the current process. This only works for up to 64 processors.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/nproc.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/coreutils/nproc.c b/coreutils/nproc.c
index 31e452bc4..7025765c5 100644
--- a/coreutils/nproc.c
+++ b/coreutils/nproc.c
@@ -29,6 +29,7 @@
29int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 29int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
30int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) 30int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
31{ 31{
32#if !ENABLE_PLATFORM_MINGW32
32 unsigned long mask[1024]; 33 unsigned long mask[1024];
33 int count = 0; 34 int count = 0;
34#if ENABLE_LONG_OPTS 35#if ENABLE_LONG_OPTS
@@ -63,6 +64,35 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
63 } 64 }
64 } 65 }
65 } 66 }
67#else /* ENABLE_PLATFORM_MINGW32 */
68 int count = 0;
69 DWORD_PTR process_affinity, system_affinity;
70#if ENABLE_LONG_OPTS
71 int ignore = 0;
72 int opts = getopt32long(argv, "\xfe:+",
73 "ignore\0" Required_argument "\xfe"
74 "all\0" No_argument "\xff"
75 , &ignore
76 );
77#endif
78 if (!GetProcessAffinityMask(GetCurrentProcess(), &process_affinity,
79 &system_affinity)) {
80 process_affinity = system_affinity = 0;
81 }
82
83#if ENABLE_LONG_OPTS
84 if (opts & (1 << 1)) {
85 for (count = 0; system_affinity; system_affinity >>= 1) {
86 count += system_affinity & 1;
87 }
88 } else
89#endif
90 {
91 for (count = 0; process_affinity; process_affinity >>= 1) {
92 count += process_affinity & 1;
93 }
94 }
95#endif /* ENABLE_PLATFORM_MINGW32 */
66 96
67 IF_LONG_OPTS(count -= ignore;) 97 IF_LONG_OPTS(count -= ignore;)
68 if (count <= 0) 98 if (count <= 0)