summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPHO <pho@cielonegro.org>2021-05-05 16:49:21 +0900
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-07 20:06:43 -0400
commit39be32839e4622c6df2f0544f2ad6fc9ed51c81c (patch)
tree1761a7d22b3cf08ece16979f1cd537c4e85c051b
parent740103c509767f901ebf955f326186f9eabc4a0e (diff)
downloadhaskell-39be32839e4622c6df2f0544f2ad6fc9ed51c81c.tar.gz
rts: Correctly call pthread_setname_np() on NetBSD
NetBSD supports pthread_setname_np() but it expects a printf-style format string and a string argument. Also use pthread for itimer on this platform.
-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));