Bugzilla bug #25981: BSD-derived systems use systcl() to get the number
authorwtc%netscape.com
Sat, 15 Jul 2000 17:23:57 +0000
changeset 1481 f72bacd684d65f7c564849b2b9b0399ef6eef004
parent 1480 b8a08510058b4c8acc6f5e2f7b15d3bccd0f04e2
child 1482 5242eb8308847e1498a20abfc6b689acf8755d5e
push idunknown
push userunknown
push dateunknown
bugs25981
Bugzilla bug #25981: BSD-derived systems use systcl() to get the number of processors. Thanks to Hans Lambermont <hans@blender.nl> for pointing out the use of sysctl().
pr/src/misc/prsystem.c
--- a/pr/src/misc/prsystem.c
+++ b/pr/src/misc/prsystem.c
@@ -44,16 +44,24 @@
 #define INCL_DOS
 #include <os2.h>
 /* define the required constant if it is not already defined in the headers */
 #ifndef QSV_NUMPROCESSORS
 #define QSV_NUMPROCESSORS 26
 #endif
 #endif
 
+/* BSD-derived systems use sysctl() to get the number of processors */
+#if defined(BSDI) || defined(FREEBSD) || defined(NETBSD) \
+    || defined(OPENBSD) || defined(RHAPSODY)
+#define _PR_HAVE_SYSCTL
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
 #if defined(HPUX)
 #include <sys/mp.h>
 #endif
 
 #if defined(XP_UNIX)
 #include <unistd.h>
 #include <sys/utsname.h>
 #endif
@@ -154,48 +162,47 @@ PR_IMPLEMENT(PRStatus) PR_GetSystemInfo(
 **   Every platform does it a bit different.
 **     numCpus is the returned value.
 **   for each platform's "if defined" section
 **     declare your local variable
 **     do your thing, assign to numCpus
 **   order of the if defined()s may be important,
 **     especially for unix variants. Do platform
 **     specific implementations before XP_UNIX.
-**     Watch order of RHAPSODY (first) and XP_MAC (after RHAPSODY).
 ** 
 */
 PR_IMPLEMENT(PRInt32) PR_GetNumberOfProcessors( void )
 {
     PRInt32     numCpus;
 #if defined(WIN32)
     SYSTEM_INFO     info;
 
     GetSystemInfo( &info );
     numCpus = info.dwNumberOfProcessors;
-#elif defined(RHAPSODY)  /* "darwin" or Mac OS/X */
+#elif defined(XP_MAC)
+    numCpus = MPProcessors();
+#elif defined(BEOS)
+    system_info sysInfo;
+
+    get_system_info(&sysInfo);
+    numCpus = sysInfo.cpu_count;
+#elif defined(OS2)
+    DosQuerySysInfo( QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &numCpus, sizeof(numCpus));
+#elif defined(_PR_HAVE_SYSCTL)
     int mib[2];
     int rc;
     size_t len = sizeof(numCpus);
 
     mib[0] = CTL_HW;
     mib[1] = HW_NCPU;
     rc = sysctl( mib, 2, &numCpus, &len, NULL, 0 );
     if ( -1 == rc )  {
         numCpus = -1; /* set to -1 for return value on error */
         PR_SetError( PR_UNKNOWN_ERROR, _MD_ERRNO());
     }
-#elif defined(XP_MAC)
-    numCpus = MPProcessors();
-#elif defined(BEOS)
-    system_info sysInfo;
-
-    get_system_info(&sysInfo);
-    numCpus = sysInfo.cpu_count;
-#elif defined(OS2)
-    DosQuerySysInfo( QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &numCpus, sizeof(numCpus));
 #elif defined(HPUX)
     numCpus = mpctl( MPC_GETNUMSPUS, 0, 0 );
     if ( numCpus < 1 )  {
         numCpus = -1; /* set to -1 for return value on error */
         PR_SetError( PR_UNKNOWN_ERROR, _MD_ERRNO());
     }
 #elif defined(IRIX)
     numCpus = sysconf( _SC_NPROC_ONLN );