summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--m4/fp_check_pthreads.m417
-rw-r--r--rts/posix/Itimer.c18
-rw-r--r--rts/posix/OSThreads.c2
-rw-r--r--rts/posix/itimer/Pthread.c2
4 files changed, 34 insertions, 5 deletions
diff --git a/m4/fp_check_pthreads.m4 b/m4/fp_check_pthreads.m4
index 008b97d482..8160f76d4b 100644
--- a/m4/fp_check_pthreads.m4
+++ b/m4/fp_check_pthreads.m4
@@ -82,6 +82,23 @@ AC_DEFUN([FP_CHECK_PTHREADS],
AC_MSG_RESULT(no)
)
+ dnl NetBSD
+ AC_MSG_CHECKING([for pthread_setname_np (NetBSD)])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM(
+ [[
+ #include <pthread.h>
+ ]],
+ [[pthread_setname_np(pthread_self(), "%s", "name");]]
+ )],
+ [
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_NETBSD], [1],
+ [Define to 1 if you have the NetBSD version of pthread_setname_np])
+ ],
+ AC_MSG_RESULT([no])
+ )
+
dnl FreeBSD
AC_MSG_CHECKING([for pthread_set_name_np])
AC_LINK_IFELSE([
diff --git a/rts/posix/Itimer.c b/rts/posix/Itimer.c
index 98b23f623e..eba45cc72e 100644
--- a/rts/posix/Itimer.c
+++ b/rts/posix/Itimer.c
@@ -21,11 +21,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",
@@ -38,6 +39,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"
@@ -73,6 +77,10 @@
#define USE_PTHREAD_FOR_ITIMER
#endif
+#if defined(netbsd_HOST_OS)
+#define USE_PTHREAD_FOR_ITIMER
+#endif
+
#if defined(solaris2_HOST_OS)
/* USE_TIMER_CREATE is usually disabled for Solaris. In fact it is
supported well on this OS, but requires additional privilege. When
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index 58476080c6..8ac23d4168 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -172,6 +172,8 @@ createOSThread (OSThreadId* pId, char *name STG_UNUSED,
pthread_setname_np(*pId, name);
#elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN)
pthread_setname_np(name);
+#elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
+ pthread_setname_np(*pId, "%s", name);
#endif
}
return result;
diff --git a/rts/posix/itimer/Pthread.c b/rts/posix/itimer/Pthread.c
index 7b968f28f0..5098d4f117 100644
--- a/rts/posix/itimer/Pthread.c
+++ b/rts/posix/itimer/Pthread.c
@@ -212,6 +212,8 @@ initTicker (Time interval, TickProc handle_tick)
pthread_setname_np(thread, "ghc_ticker");
#elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN)
pthread_setname_np("ghc_ticker");
+#elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
+ pthread_setname_np(thread, "%s", "ghc_ticker");
#endif
} else {
barf("Itimer: Failed to spawn thread: %s", strerror(errno));