]> Savannah Git Hosting - gnulib.git/commitdiff
nproc, physmem: Use sysctl() as a fallback on GNU/kFreeBSD.
authorBruno Haible <bruno@clisp.org>
Sun, 13 Aug 2023 23:04:36 +0000 (01:04 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 13 Aug 2023 23:04:36 +0000 (01:04 +0200)
* lib/nproc.c: Do include <sys/sysctl.h> on GNU/kFreeBSD.
(num_processors_ignoring_omp): Call sysctl on GNU/kFreeBSD.
* lib/physmem.c: Do include <sys/sysctl.h> on GNU/kFreeBSD.
(physmem_total, physmem_available): Call sysctl on GNU/kFreeBSD.

ChangeLog
lib/nproc.c
lib/physmem.c

index 05d4466c776ff8ec759df3977d7505f75a3780da..6ed28e97d87c2400b09e38dd3405a714cf72e913 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-08-13  Bruno Haible  <bruno@clisp.org>
+
+       nproc, physmem: Use sysctl() as a fallback on GNU/kFreeBSD.
+       * lib/nproc.c: Do include <sys/sysctl.h> on GNU/kFreeBSD.
+       (num_processors_ignoring_omp): Call sysctl on GNU/kFreeBSD.
+       * lib/physmem.c: Do include <sys/sysctl.h> on GNU/kFreeBSD.
+       (physmem_total, physmem_available): Call sysctl on GNU/kFreeBSD.
+
 2023-08-13  Bruno Haible  <bruno@clisp.org>
 
        physmem: Add tests.
index 2740c458c11f0dc2e22c7e38e835d6d5a3af6ed4..e3de1873a96bd9ba695ec463f77f171bd0fcfca4 100644 (file)
@@ -46,7 +46,7 @@
 # include <sys/param.h>
 #endif
 
-#if HAVE_SYS_SYSCTL_H && ! defined __GLIBC__
+#if HAVE_SYS_SYSCTL_H && !(defined __GLIBC__ && defined __linux__)
 # include <sys/sysctl.h>
 #endif
 
@@ -306,7 +306,7 @@ num_processors_ignoring_omp (enum nproc_query query)
   /* Finally, as fallback, use the APIs that don't distinguish between
      NPROC_CURRENT and NPROC_ALL.  */
 
-#if HAVE_SYSCTL && ! defined __GLIBC__ && defined HW_NCPU
+#if HAVE_SYSCTL && !(defined __GLIBC__ && defined __linux__) && defined HW_NCPU
   { /* This works on macOS, FreeBSD, NetBSD, OpenBSD.
        macOS 10.14 does not allow mib to be const.  */
     int nprocs;
index f4505871413aa951d3a7784888fbf6f292b351f3..398f99b727e53605e811d64eb37bf81be2ffcded 100644 (file)
@@ -50,7 +50,7 @@
 # include <sys/param.h>
 #endif
 
-#if HAVE_SYS_SYSCTL_H && ! defined __GLIBC__
+#if HAVE_SYS_SYSCTL_H && !(defined __GLIBC__ && defined __linux__)
 # include <sys/sysctl.h>
 #endif
 
@@ -96,7 +96,7 @@ double
 physmem_total (void)
 {
 #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE
-  { /* This works on linux-gnu, solaris2 and cygwin.  */
+  { /* This works on linux-gnu, kfreebsd-gnu, solaris2, and cygwin.  */
     double pages = sysconf (_SC_PHYS_PAGES);
     double pagesize = sysconf (_SC_PAGESIZE);
     if (0 <= pages && 0 <= pagesize)
@@ -153,8 +153,8 @@ physmem_total (void)
   }
 #endif
 
-#if HAVE_SYSCTL && ! defined __GLIBC__ && defined HW_PHYSMEM
-  { /* This works on *bsd and darwin.  */
+#if HAVE_SYSCTL && !(defined __GLIBC__ && defined __linux__) && defined HW_PHYSMEM
+  { /* This works on *bsd, kfreebsd-gnu, and darwin.  */
     unsigned int physmem;
     size_t len = sizeof physmem;
     static int mib[2] = { CTL_HW, HW_PHYSMEM };
@@ -208,7 +208,7 @@ double
 physmem_available (void)
 {
 #if defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE
-  { /* This works on linux-gnu, solaris2 and cygwin.  */
+  { /* This works on linux-gnu, kfreebsd-gnu, solaris2, and cygwin.  */
     double pages = sysconf (_SC_AVPHYS_PAGES);
     double pagesize = sysconf (_SC_PAGESIZE);
     if (0 <= pages && 0 <= pagesize)
@@ -267,8 +267,8 @@ physmem_available (void)
   }
 #endif
 
-#if HAVE_SYSCTL && ! defined __GLIBC__ && defined HW_USERMEM
-  { /* This works on *bsd and darwin.  */
+#if HAVE_SYSCTL && !(defined __GLIBC__ && defined __linux__) && defined HW_USERMEM
+  { /* This works on *bsd, kfreebsd-gnu, and darwin.  */
     unsigned int usermem;
     size_t len = sizeof usermem;
     static int mib[2] = { CTL_HW, HW_USERMEM };