Implement nproc for HP-UX.
authorBruno Haible <bruno@clisp.org>
Sun, 18 Oct 2009 08:42:19 +0000 (10:42 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 18 Oct 2009 08:42:19 +0000 (10:42 +0200)
ChangeLog
lib/nproc.c
m4/nproc.m4

index 240ef97..c715d0a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-10-18  Bruno Haible  <bruno@clisp.org>
+
+       Implement nproc for HP-UX.
+       * lib/nproc.c: Include <sys/pstat.h>
+       (num_processors): On HP-UX systems, try pstat_getdynamic.
+       * m4/nproc.m4 (gl_PREREQ_NPROC): Check for sys/pstat.h and
+       pstat_getdynamic.
+
 2009-10-18  Giuseppe Scrivano  <gscrivano@gnu.org>
             Bruno Haible  <bruno@clisp.org>
 
index a1a7c41..48c0d8a 100644 (file)
 
 #include <sys/types.h>
 
+#if HAVE_SYS_PSTAT_H
+# include <sys/pstat.h>
+#endif
+
 #if HAVE_SYS_PARAM_H
 # include <sys/param.h>
 #endif
@@ -49,6 +53,15 @@ num_processors (void)
   }
 #endif
 
+#if HAVE_PSTAT_GETDYNAMIC
+  { /* This works on HP-UX.  */
+    struct pst_dynamic psd;
+    if (0 <= pstat_getdynamic (&psd, sizeof psd, 1, 0)
+       && 0 < psd.psd_proc_cnt)
+      return psd.psd_proc_cnt;
+  }
+#endif
+
 #if HAVE_SYSCTL && defined HW_NCPU
   { /* This works on MacOS X, FreeBSD, NetBSD, OpenBSD.  */
     int nprocs;
index 73b812d..5bcae80 100644 (file)
@@ -1,4 +1,4 @@
-# nproc.m4 serial 1
+# nproc.m4 serial 2
 dnl Copyright (C) 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -12,7 +12,7 @@ AC_DEFUN([gl_NPROC],
 # Prerequisites of lib/nproc.c.
 AC_DEFUN([gl_PREREQ_NPROC],
 [
-  AC_CHECK_HEADERS([sys/param.h],,, [AC_INCLUDES_DEFAULT])
+  AC_CHECK_HEADERS([sys/pstat.h sys/param.h],,, [AC_INCLUDES_DEFAULT])
   dnl <sys/sysctl.h> requires <sys/param.h> on OpenBSD 4.0.
   AC_CHECK_HEADERS([sys/sysctl.h],,,
     [AC_INCLUDES_DEFAULT
@@ -20,5 +20,5 @@ AC_DEFUN([gl_PREREQ_NPROC],
      # include <sys/param.h>
      #endif
     ])
-  AC_CHECK_FUNCS([sysctl])
+  AC_CHECK_FUNCS([pstat_getdynamic sysctl])
 ])