pthread_sigmask: Fix link requirements on OSF/1 5.1 and with pth.
authorBruno Haible <bruno@clisp.org>
Fri, 8 Jul 2011 02:05:45 +0000 (04:05 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 8 Jul 2011 02:05:45 +0000 (04:05 +0200)
* lib/signal.in.h (pthread_sigmask): Override if
REPLACE_PTHREAD_SIGMASK is 1.
* m4/signal_h.m4 (gl_SIGNAL_H_DEFAULTS): Initialize
REPLACE_PTHREAD_SIGMASK.
* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Set also
REPLACE_PTHREAD_SIGMASK. Set and substitute LIB_PTHREAD_SIGMASK.
* modules/signal (Makefile.am): Substitute REPLACE_PTHREAD_SIGMASK.
* modules/pthread_sigmask (Depends-on, configure.ac): Update condition.
(Link): Set to $(LIB_PTHREAD_SIGMASK), not $(LIBMULTITHREAD).

ChangeLog
lib/signal.in.h
m4/pthread_sigmask.m4
m4/signal_h.m4
modules/pthread_sigmask
modules/signal

index 581b066..00165e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2011-07-07  Bruno Haible  <bruno@clisp.org>
 
+       pthread_sigmask: Fix link requirements on OSF/1 5.1 and with pth.
+       * lib/signal.in.h (pthread_sigmask): Override if
+       REPLACE_PTHREAD_SIGMASK is 1.
+       * m4/signal_h.m4 (gl_SIGNAL_H_DEFAULTS): Initialize
+       REPLACE_PTHREAD_SIGMASK.
+       * m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Set also
+       REPLACE_PTHREAD_SIGMASK. Set and substitute LIB_PTHREAD_SIGMASK.
+       * modules/signal (Makefile.am): Substitute REPLACE_PTHREAD_SIGMASK.
+       * modules/pthread_sigmask (Depends-on, configure.ac): Update condition.
+       (Link): Set to $(LIB_PTHREAD_SIGMASK), not $(LIBMULTITHREAD).
+
+2011-07-07  Bruno Haible  <bruno@clisp.org>
+
        pthread_sigmask: Ensure declaration in <signal.h>.
        * lib/signal.in.h: On MacOS X, FreeBSD, OpenBSD, OSF/1, Solaris 2.6,
        include <pthread.h>.
index 4757279..93787f7 100644 (file)
@@ -125,12 +125,23 @@ typedef void (*sighandler_t) (int);
 
 
 #if @GNULIB_PTHREAD_SIGMASK@
-# if !@HAVE_PTHREAD_SIGMASK@
+# if @REPLACE_PTHREAD_SIGMASK@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef pthread_sigmask
+#   define pthread_sigmask rpl_pthread_sigmask
+#  endif
+_GL_FUNCDECL_RPL (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+_GL_CXXALIAS_RPL (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+# else
+#  if !@HAVE_PTHREAD_SIGMASK@
 _GL_FUNCDECL_SYS (pthread_sigmask, int,
                   (int how, const sigset_t *new_mask, sigset_t *old_mask));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (pthread_sigmask, int,
                   (int how, const sigset_t *new_mask, sigset_t *old_mask));
+# endif
 _GL_CXXALIASWARN (pthread_sigmask);
 #elif defined GNULIB_POSIXCHECK
 # undef pthread_sigmask
index 2147c08..984f69d 100644 (file)
@@ -1,4 +1,4 @@
-# pthread_sigmask.m4 serial 4
+# pthread_sigmask.m4 serial 5
 dnl Copyright (C) 2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -6,21 +6,67 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK],
 [
+  AC_CHECK_FUNCS_ONCE([pthread_sigmask])
+  LIB_PTHREAD_SIGMASK=
   m4_ifdef([gl_THREADLIB], [
     AC_REQUIRE([gl_THREADLIB])
     if test "$gl_threads_api" = posix; then
-      gl_save_LIBS="$LIBS"
-      LIBS="$LIBS $LIBMULTITHREAD"
-      AC_CHECK_FUNCS([pthread_sigmask])
-      LIBS="$gl_save_LIBS"
+      if test $ac_cv_func_pthread_sigmask = yes; then
+        dnl pthread_sigmask is available without -lpthread.
+        :
+      else
+        if test -n "$LIBMULTITHREAD"; then
+          AC_CACHE_CHECK([for pthread_sigmask in $LIBMULTITHREAD],
+            [gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD],
+            [gl_save_LIBS="$LIBS"
+             LIBS="$LIBS $LIBMULTITHREAD"
+             AC_COMPILE_IFELSE(
+               [AC_LANG_PROGRAM(
+                  [[#include <pthread.h>
+                    #include <signal.h>
+                  ]],
+                  [[return pthread_sigmask (0, (sigset_t *) 0, (sigset_t *) 0);]])
+               ],
+               [gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD=yes],
+               [gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD=no])
+             LIBS="$gl_save_LIBS"
+            ])
+          if test $gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD = yes; then
+            dnl pthread_sigmask is available with -lpthread.
+            LIB_PTHREAD_SIGMASK="$LIBMULTITHREAD"
+          else
+            dnl pthread_sigmask is not available at all.
+            HAVE_PTHREAD_SIGMASK=0
+          fi
+        else
+          dnl pthread_sigmask is not available at all.
+          HAVE_PTHREAD_SIGMASK=0
+        fi
+      fi
     else
-      ac_cv_func_pthread_sigmask=no
+      dnl pthread_sigmask may exist but does not interoperate with the chosen
+      dnl multithreading facility.
+      dnl If "$gl_threads_api" = pth, we could use the function pth_sigmask,
+      dnl but it is equivalent to sigprocmask, so we choose to emulate
+      dnl pthread_sigmask with sigprocmask also in this case. This yields fewer
+      dnl link dependencies.
+      if test $ac_cv_func_pthread_sigmask = yes; then
+        REPLACE_PTHREAD_SIGMASK=1
+      else
+        HAVE_PTHREAD_SIGMASK=0
+      fi
+    fi
+  ] ,[
+    dnl If module 'threadlib' is not in use, assume all programs will be
+    dnl single-threaded.
+    if test $ac_cv_func_pthread_sigmask = yes; then
+      REPLACE_PTHREAD_SIGMASK=1
+    else
+      HAVE_PTHREAD_SIGMASK=0
     fi
-  ], [
-    AC_CHECK_FUNCS_ONCE([pthread_sigmask])
   ])
-
-  if test $ac_cv_func_pthread_sigmask = no; then
-    HAVE_PTHREAD_SIGMASK=0
-  fi
+  AC_SUBST([LIB_PTHREAD_SIGMASK])
+  dnl We don't need a variable LTLIB_PTHREAD_SIGMASK, because when
+  dnl "$gl_threads_api" = posix, $LTLIBMULTITHREAD and $LIBMULTITHREAD are the
+  dnl same: either both empty or both "-lpthread".
 ])
index 96270a9..b9536fb 100644 (file)
@@ -1,4 +1,4 @@
-# signal_h.m4 serial 15
+# signal_h.m4 serial 16
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -73,4 +73,5 @@ AC_DEFUN([gl_SIGNAL_H_DEFAULTS],
   HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=1;
                                AC_SUBST([HAVE_TYPE_VOLATILE_SIG_ATOMIC_T])
   HAVE_SIGHANDLER_T=1;         AC_SUBST([HAVE_SIGHANDLER_T])
+  REPLACE_PTHREAD_SIGMASK=0;   AC_SUBST([REPLACE_PTHREAD_SIGMASK])
 ])
index 8f1a0a0..087c158 100644 (file)
@@ -7,11 +7,11 @@ m4/pthread_sigmask.m4
 
 Depends-on:
 signal
-sigprocmask     [test $HAVE_PTHREAD_SIGMASK = 0]
+sigprocmask     [test $HAVE_PTHREAD_SIGMASK = 0 || test $REPLACE_PTHREAD_SIGMASK = 1]
 
 configure.ac:
 gl_FUNC_PTHREAD_SIGMASK
-if test $HAVE_PTHREAD_SIGMASK = 0; then
+if test $HAVE_PTHREAD_SIGMASK = 0 || test $REPLACE_PTHREAD_SIGMASK = 1; then
   AC_LIBOBJ([pthread_sigmask])
 fi
 gl_SIGNAL_MODULE_INDICATOR([pthread_sigmask])
@@ -22,7 +22,7 @@ Include:
 <signal.h>
 
 Link:
-$(LIBMULTITHREAD)
+$(LIB_PTHREAD_SIGMASK)
 
 License:
 LGPLv2+
index d84105b..785da78 100644 (file)
@@ -40,6 +40,7 @@ signal.h: signal.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''HAVE_STRUCT_SIGACTION_SA_SIGACTION''@|$(HAVE_STRUCT_SIGACTION_SA_SIGACTION)|g' \
              -e 's|@''HAVE_TYPE_VOLATILE_SIG_ATOMIC_T''@|$(HAVE_TYPE_VOLATILE_SIG_ATOMIC_T)|g' \
              -e 's|@''HAVE_SIGHANDLER_T''@|$(HAVE_SIGHANDLER_T)|g' \
+             -e 's|@''REPLACE_PTHREAD_SIGMASK''@|$(REPLACE_PTHREAD_SIGMASK)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \