X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=m4%2Fpthread_sigmask.m4;h=0346a20af21bc2218e0efefe4feba323886a2b15;hb=5191b3546cfb6c163228c23f214e325ddf60d46f;hp=c65a4ce3507cd71553a15f226137dece2c686d21;hpb=43243b5fdcf1e0c0e016cabe190f1ab29b984871;p=gnulib.git diff --git a/m4/pthread_sigmask.m4 b/m4/pthread_sigmask.m4 index c65a4ce35..0346a20af 100644 --- a/m4/pthread_sigmask.m4 +++ b/m4/pthread_sigmask.m4 @@ -1,15 +1,23 @@ -# pthread_sigmask.m4 serial 8 -dnl Copyright (C) 2011 Free Software Foundation, Inc. +# pthread_sigmask.m4 serial 13 +dnl Copyright (C) 2011-2013 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_FUNC_PTHREAD_SIGMASK], [ + AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([pthread_sigmask]) LIB_PTHREAD_SIGMASK= - m4_ifdef([gl_THREADLIB], [ - AC_REQUIRE([gl_THREADLIB]) + + dnl Test whether the gnulib module 'threadlib' is in use. + dnl Some packages like Emacs use --avoid=threadlib. + dnl Write the symbol in such a way that it does not cause 'aclocal' to pick + dnl the threadlib.m4 file that is installed in $PREFIX/share/aclocal/. + m4_ifdef([gl_][THREADLIB], [ + AC_REQUIRE([gl_][THREADLIB]) + if test "$gl_threads_api" = posix; then if test $ac_cv_func_pthread_sigmask = yes; then dnl pthread_sigmask is available without -lpthread. @@ -56,20 +64,25 @@ AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK], HAVE_PTHREAD_SIGMASK=0 fi fi - ] ,[ - dnl gl_THREADLIB is not in use. Assume the application wants - dnl POSIX semantics. - if test $ac_cv_func_pthread_sigmask != yes; then - gl_save_LIBS=$LIBS - AC_SEARCH_LIBS([pthread_sigmask], [pthread c_r]) - LIBS=$gl_save_LIBS - if test "$ac_cv_search_pthread_sigmask" = no; then - HAVE_PTHREAD_SIGMASK=0 - elif test "$ac_cv_search_pthread_sigmask" != 'none required'; then - LIB_PTHREAD_SIGMASK=$ac_cv_search_pthread_sigmask - fi + ], [ + dnl The module 'threadlib' is not in use, due to --avoid=threadlib being + dnl specified. + dnl The package either has prepared CPPFLAGS and LIBS for use of POSIX:2008 + dnl threads, or wants to build single-threaded programs. + if test $ac_cv_func_pthread_sigmask = yes; then + dnl pthread_sigmask exists and does not require extra libraries. + dnl Assume that it is declared. + : + else + dnl pthread_sigmask either does not exist or needs extra libraries. + HAVE_PTHREAD_SIGMASK=0 + dnl Define the symbol rpl_pthread_sigmask, not pthread_sigmask, + dnl so as to not accidentally override the system's pthread_sigmask + dnl symbol from libpthread. This is necessary on IRIX 6.5. + REPLACE_PTHREAD_SIGMASK=1 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 @@ -115,7 +128,7 @@ changequote([,])dnl *no) REPLACE_PTHREAD_SIGMASK=1 AC_DEFINE([PTHREAD_SIGMASK_INEFFECTIVE], [1], - [Define to 1 if pthread_mask() may returns 0 and have no effect.]) + [Define to 1 if pthread_sigmask() may returns 0 and have no effect.]) ;; esac fi @@ -155,10 +168,74 @@ int main () *no) REPLACE_PTHREAD_SIGMASK=1 AC_DEFINE([PTHREAD_SIGMASK_FAILS_WITH_ERRNO], [1], - [Define to 1 if pthread_mask(), when it fails, returns -1 and sets errno.]) + [Define to 1 if pthread_sigmask(), when it fails, returns -1 and sets errno.]) ;; esac + dnl On IRIX 6.5, in a single-threaded program, pending signals are not + dnl immediately delivered when they are unblocked through pthread_sigmask, + dnl only a little while later. + AC_CACHE_CHECK([whether pthread_sigmask unblocks signals correctly], + [gl_cv_func_pthread_sigmask_unblock_works], + [ + case "$host_os" in + irix*) + gl_cv_func_pthread_sigmask_unblock_works="guessing no";; + *) + gl_cv_func_pthread_sigmask_unblock_works="guessing yes";; + esac + dnl Here we link against $LIBMULTITHREAD, not only $LIB_PTHREAD_SIGMASK, + dnl otherwise we get a false positive on those platforms where + dnl $gl_cv_func_pthread_sigmask_in_libc_works is "no". + gl_save_LIBS="$LIBS" + LIBS="$LIBS $LIBMULTITHREAD" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +#include +#include +static volatile int sigint_occurred; +static void +sigint_handler (int sig) +{ + sigint_occurred++; +} +int main () +{ + sigset_t set; + int pid = getpid (); + char command[80]; + signal (SIGINT, sigint_handler); + sigemptyset (&set); + sigaddset (&set, SIGINT); + if (!(pthread_sigmask (SIG_BLOCK, &set, NULL) == 0)) + return 1; + sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, pid); + if (!(system (command) == 0)) + return 2; + sleep (2); + if (!(sigint_occurred == 0)) + return 3; + if (!(pthread_sigmask (SIG_UNBLOCK, &set, NULL) == 0)) + return 4; + if (!(sigint_occurred == 1)) /* This fails on IRIX. */ + return 5; + return 0; +}]])], + [:], + [gl_cv_func_pthread_sigmask_unblock_works=no], + [:]) + LIBS="$gl_save_LIBS" + ]) + case "$gl_cv_func_pthread_sigmask_unblock_works" in + *no) + REPLACE_PTHREAD_SIGMASK=1 + AC_DEFINE([PTHREAD_SIGMASK_UNBLOCK_BUG], [1], + [Define to 1 if pthread_sigmask() unblocks signals incorrectly.]) + ;; + esac fi ])