diff options
author | Bruno Haible <bruno@clisp.org> | 2019-07-15 02:36:13 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-07-15 02:36:13 +0200 |
commit | c1c1d4f6239eece0857e8c6465e92c0806a7c147 (patch) | |
tree | 893d450b4f2d7093a61939589065b9a865dc17cb /m4/pthread_h.m4 | |
parent | 3fdb19cf7a5c3c4ada691fdb9d8e01701c747298 (diff) | |
download | gnulib-c1c1d4f6239eece0857e8c6465e92c0806a7c147.tar.gz |
pthread-h: New module.
* lib/pthread.in.h: Define replacement functions only if GNULIB_PTHREAD
is 1.
* m4/pthread_h.m4: Renamed from m4/pthread.m4.
(gl_PTHREAD_H): Renamed from gl_PTHREAD_CHECK. Don't test whether
<pthread.h> pollutes the namespace; instead, prepare for generating a
pthread.h always. Substitute HAVE_PTHREAD_H here.
(gl_PTHREAD_H_DEFAULTS): Renamed from gl_PTHREAD_DEFAULTS. Initialize
GNULIB_PTHREAD. Don't initialize HAVE_PTHREAD_H here.
* modules/pthread-h: New file, based on modules/pthread.
* modules/pthread: Rely on 'pthread-h'.
* m4/pthread_mutex_timedlock.m4 (gl_FUNC_PTHREAD_MUTEX_TIMEDLOCK):
Update.
* modules/pthread_mutex_timedlock (Depends-on): Add pthread-h. Remove
pthread.
Diffstat (limited to 'm4/pthread_h.m4')
-rw-r--r-- | m4/pthread_h.m4 | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/m4/pthread_h.m4 b/m4/pthread_h.m4 new file mode 100644 index 0000000000..d55a471b39 --- /dev/null +++ b/m4/pthread_h.m4 @@ -0,0 +1,95 @@ +# pthread_h.m4 serial 1 +dnl Copyright (C) 2009-2019 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_PTHREAD_H], +[ + dnl Use AC_REQUIRE here, so that the default behavior below is expanded + dnl once only, before all statements that occur in other macros. + AC_REQUIRE([gl_PTHREAD_H_DEFAULTS]) + + gl_CHECK_NEXT_HEADERS([pthread.h]) + if test $ac_cv_header_pthread_h = yes; then + HAVE_PTHREAD_H=1 + else + HAVE_PTHREAD_H=0 + fi + AC_SUBST([HAVE_PTHREAD_H]) + + AC_CHECK_TYPES([pthread_t, pthread_spinlock_t], [], [], + [AC_INCLUDES_DEFAULT[ + #if HAVE_PTHREAD_H + #include <pthread.h> + #endif]]) + if test $ac_cv_type_pthread_t != yes; then + HAVE_PTHREAD_T=0 + fi + if test $ac_cv_type_pthread_spinlock_t != yes; then + HAVE_PTHREAD_SPINLOCK_T=0 + fi + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use, if it is not common + dnl enough to be declared everywhere. + gl_WARN_ON_USE_PREPARE([[#include <pthread.h> + ]], [pthread_mutex_timedlock]) + + AC_REQUIRE([AC_C_RESTRICT]) + + LIB_PTHREAD= + if test $ac_cv_header_pthread_h = yes; then + dnl We cannot use AC_SEARCH_LIBS here, because on OSF/1 5.1 pthread_join + dnl is defined as a macro which expands to __phread_join, and libpthread + dnl contains a definition for __phread_join but none for pthread_join. + dnl Also, FreeBSD 9 puts pthread_create in libpthread and pthread_join + dnl in libc, whereas on IRIX 6.5 the reverse is true; so check for both. + AC_CACHE_CHECK([for library containing pthread_create and pthread_join], + [gl_cv_lib_pthread], + [gl_saved_libs=$LIBS + gl_cv_lib_pthread= + for gl_lib_prefix in '' '-pthread' '-lpthread'; do + LIBS="$gl_lib_prefix $gl_saved_libs" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include <pthread.h> + void *noop (void *p) { return p; }]], + [[pthread_t pt; + void *arg = 0; + pthread_create (&pt, 0, noop, arg); + pthread_join (pthread_self (), &arg);]])], + [if test -z "$gl_lib_prefix"; then + gl_cv_lib_pthread="none required" + else + gl_cv_lib_pthread=$gl_lib_prefix + fi]) + test -n "$gl_cv_lib_pthread" && break + done + LIBS="$gl_saved_libs" + ]) + if test "$gl_cv_lib_pthread" != "none required"; then + LIB_PTHREAD="$gl_cv_lib_pthread" + fi + fi + AC_SUBST([LIB_PTHREAD]) +]) + +AC_DEFUN([gl_PTHREAD_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_PTHREAD_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) + dnl Define it also as a C macro, for the benefit of the unit tests. + gl_MODULE_INDICATOR_FOR_TESTS([$1]) +]) + +AC_DEFUN([gl_PTHREAD_H_DEFAULTS], +[ + GNULIB_PTHREAD=0; AC_SUBST([GNULIB_PTHREAD]) + GNULIB_PTHREAD_MUTEX_TIMEDLOCK=0; AC_SUBST([GNULIB_PTHREAD_MUTEX_TIMEDLOCK]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_PTHREAD_MUTEX_TIMEDLOCK=1; AC_SUBST([HAVE_PTHREAD_MUTEX_TIMEDLOCK]) + HAVE_PTHREAD_SPINLOCK_T=1; AC_SUBST([HAVE_PTHREAD_SPINLOCK_T]) + HAVE_PTHREAD_T=1; AC_SUBST([HAVE_PTHREAD_T]) +]) |