summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPHO <pho@cielonegro.org>2021-05-05 16:37:56 +0900
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-07 20:06:43 -0400
commit740103c509767f901ebf955f326186f9eabc4a0e (patch)
tree987493693784cd5f36f5cce4171bb50e3fbcef2d
parent8e0f48bdd6e83279939d8fdd2ec1e5707725030d (diff)
downloadhaskell-740103c509767f901ebf955f326186f9eabc4a0e.tar.gz
rts/posix/OSThreads.c: Implement getNumberOfProcessors() for NetBSD
-rw-r--r--rts/posix/OSThreads.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index e039b43573..58476080c6 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -11,11 +11,12 @@
/* We've defined _POSIX_SOURCE via "PosixSource.h", and yet still use
some non-POSIX features. With _POSIX_SOURCE defined, visibility of
- non-POSIX extension prototypes requires _DARWIN_C_SOURCE on Mac OS X and
- __BSD_VISIBLE on FreeBSD and DragonflyBSD. Otherwise, for example, code
- using pthread_setname_np(3) and variants will not compile. We must
- therefore define the additional macros that expose non-POSIX APIs early,
- before any of the relevant system headers are included via "Rts.h".
+ non-POSIX extension prototypes requires _DARWIN_C_SOURCE on Mac OS X,
+ __BSD_VISIBLE on FreeBSD and DragonflyBSD, and _NETBSD_SOURCE on
+ NetBSD. Otherwise, for example, code using pthread_setname_np(3) and
+ variants will not compile. We must therefore define the additional
+ macros that expose non-POSIX APIs early, before any of the relevant
+ system headers are included via "Rts.h".
An alternative approach could be to write portable wrappers or stubs for all
the non-posix functions in a C-module that does not include "PosixSource.h",
@@ -28,6 +29,9 @@
#if defined(darwin_HOST_OS)
#define _DARWIN_C_SOURCE 1
#endif
+#if defined(netbsd_HOST_OS)
+#define _NETBSD_SOURCE 1
+#endif
#include "Rts.h"
@@ -51,7 +55,7 @@
#include <string.h>
#endif
-#if defined(darwin_HOST_OS) || defined(freebsd_HOST_OS)
+#if defined(darwin_HOST_OS) || defined(freebsd_HOST_OS) || defined(netbsd_HOST_OS)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
@@ -308,6 +312,15 @@ getNumberOfProcessors (void)
if(sysctlbyname("hw.ncpu",&nproc,&size,NULL,0) != 0)
nproc = 1;
}
+#elif defined(netbsd_HOST_OS)
+ int mib[2] = { CTL_HW, HW_NCPUONLINE };
+ size_t size = sizeof(nproc);
+ if (sysctl(mib, 2, &nproc, &size, NULL, 0) != 0) {
+ mib[1] = HW_NCPU;
+ if (sysctl(mib, 2, &nproc, &size, NULL, 0) != 0) {
+ nproc = 1;
+ }
+ }
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
// N.B. This is the number of physical processors.
nproc = sysconf(_SC_NPROCESSORS_ONLN);