Implement nproc for mingw.
authorBruno Haible <bruno@clisp.org>
Sun, 18 Oct 2009 09:22:22 +0000 (11:22 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 18 Oct 2009 09:22:22 +0000 (11:22 +0200)
ChangeLog
lib/nproc.c

index 5a820cd..fbd6694 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-10-18  Bruno Haible  <bruno@clisp.org>
 
+       Implement nproc for mingw.
+       * lib/nproc.c: Include <windows.h>
+       (num_processors): On native Windows platforms, try GetSystemInfo.
+
+2009-10-18  Bruno Haible  <bruno@clisp.org>
+
        Implement nproc for IRIX.
        * lib/nproc.c: Include <sys/sysmp.h>.
        (num_processors): On IRIX systems, try sysmp.
index 04a047c..b5a70b1 100644 (file)
 # include <sys/sysctl.h>
 #endif
 
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+
 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
 
 /* Return the total number of processors.  The result is guaranteed to
@@ -90,5 +95,14 @@ num_processors (void)
   }
 #endif
 
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  { /* This works on native Windows platforms.  */
+    SYSTEM_INFO system_info;
+    GetSystemInfo (&system_info);
+    if (0 < system_info.dwNumberOfProcessors)
+      return system_info.dwNumberOfProcessors;
+  }
+#endif
+
   return 1;
 }