summaryrefslogtreecommitdiff
path: root/rts/m4/fp_check_pthreads.m4
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-10-28 19:02:16 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-01-02 02:52:48 -0500
commit7beb9fff1bee1ccbf7f2258ce527b8d5df2a85ea (patch)
tree2868fd769f2a528e67e6e6fa2760b3dab77d5252 /rts/m4/fp_check_pthreads.m4
parent7b2cf80717a6b16e3f6135c6c6905bd5d3bbde72 (diff)
downloadhaskell-wip/rts-configure-2.tar.gz
rts configure scriptwip/rts-configure-2
Need to use CPP not `if` in rts.buildinfo Bump cabal submodule to include https://github.com/haskell/cabal/pull/8565
Diffstat (limited to 'rts/m4/fp_check_pthreads.m4')
-rw-r--r--rts/m4/fp_check_pthreads.m4117
1 files changed, 117 insertions, 0 deletions
diff --git a/rts/m4/fp_check_pthreads.m4 b/rts/m4/fp_check_pthreads.m4
new file mode 100644
index 0000000000..5c63cac2a5
--- /dev/null
+++ b/rts/m4/fp_check_pthreads.m4
@@ -0,0 +1,117 @@
+dnl FP_CHECK_PTHREADS
+dnl ----------------------------------
+dnl Check various aspects of the platform's pthreads support
+AC_DEFUN([FP_CHECK_PTHREADS],
+[
+ dnl Some platforms (e.g. Android's Bionic) have pthreads support available
+ dnl without linking against libpthread. Check whether -lpthread is necessary
+ dnl to use pthreads.
+ dnl
+ dnl Note that it is important that this happens before we AC_CHECK_LIB(thread)
+ AC_MSG_CHECKING(whether -lpthread is needed for pthreads)
+ AC_CHECK_FUNC(pthread_create,
+ [
+ AC_MSG_RESULT(no)
+ need_lpthread=0
+ ],
+ [
+ AC_CHECK_LIB(pthread, pthread_create,
+ [
+ AC_MSG_RESULT(yes)
+ need_lpthread=1
+ ],
+ [
+ AC_MSG_RESULT([no pthreads support found.])
+ need_lpthread=0
+ ])
+ ])
+ AC_DEFINE_UNQUOTED([GHC_NEED_LIBPTHREAD], [$need_lpthread],
+ [Define 1 if we need to link code using pthreads with -lpthread])
+
+ dnl Setting thread names
+ dnl ~~~~~~~~~~~~~~~~~~~~
+ dnl The portability situation here is complicated:
+ dnl
+ dnl * FreeBSD supports pthread_set_name_np in <pthread_np.h>
+ dnl and (if not _POSIX_SOURCE) pthread_setname_np() in <pthread.h>
+ dnl because of the conditional visibility, we prefer the former.
+ dnl * glibc supports pthread_setname_np
+ dnl * Darwin supports pthread_setname_np but does not take a
+ dnl pthread_t argument.
+ dnl
+ AC_CHECK_HEADERS([pthread_np.h])
+
+ dnl ** pthread_setname_np is a recent addition to glibc, and OS X has
+ dnl a different single-argument version.
+ AC_CHECK_LIB(pthread, pthread_setname_np)
+
+ AC_MSG_CHECKING([for pthread_setname_np (Darwin)])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM(
+ [[
+ #include <pthread.h>
+ ]],
+ [[pthread_setname_np("name");]]
+ )],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_DARWIN], [1],
+ [Define to 1 if you have the Darwin version of pthread_setname_np])
+ ],
+ AC_MSG_RESULT(no)
+ )
+
+ dnl glibc
+ AC_MSG_CHECKING([for pthread_setname_np (glibc)])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM(
+ [[
+ #define _GNU_SOURCE
+ #include <pthread.h>
+ ]],
+ [[pthread_setname_np(pthread_self(), "name");]]
+ )],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1],
+ [Define to 1 if you have the glibc version of pthread_setname_np])
+ ],
+ 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([
+ AC_LANG_PROGRAM(
+ [[
+ #include <pthread_np.h>
+ ]],
+ [[pthread_set_name_np(pthread_self(), "name");]]
+ )],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([HAVE_PTHREAD_SET_NAME_NP], [1],
+ [Define to 1 if you have pthread_set_name_np])
+ ],
+ AC_MSG_RESULT(no)
+ )
+
+ AC_CHECK_FUNCS_ONCE([pthread_condattr_setclock])
+])