Blame m4/pthread_sigmask.m4

Packit Service 991b93
# pthread_sigmask.m4 serial 18
Packit Service 991b93
dnl Copyright (C) 2011-2020 Free Software Foundation, Inc.
Packit Service 991b93
dnl This file is free software; the Free Software Foundation
Packit Service 991b93
dnl gives unlimited permission to copy and/or distribute it,
Packit Service 991b93
dnl with or without modifications, as long as this notice is preserved.
Packit Service 991b93
Packit Service 991b93
AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK],
Packit Service 991b93
[
Packit Service 991b93
  AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
Packit Service 991b93
Packit Service 991b93
  AC_CHECK_FUNCS_ONCE([pthread_sigmask])
Packit Service 991b93
Packit Service 991b93
  dnl On MinGW pthread_sigmask is just a macro which always returns 0.
Packit Service 991b93
  dnl It does not exist as a real function, which is required by POSIX.
Packit Service 991b93
  AC_CACHE_CHECK([whether pthread_sigmask is a macro],
Packit Service 991b93
    [gl_cv_func_pthread_sigmask_macro],
Packit Service 991b93
    [AC_EGREP_CPP([headers_define_pthread_sigmask], [
Packit Service 991b93
#include <pthread.h>
Packit Service 991b93
#include <signal.h>
Packit Service 991b93
#ifdef pthread_sigmask
Packit Service 991b93
 headers_define_pthread_sigmask
Packit Service 991b93
#endif],
Packit Service 991b93
       [gl_cv_func_pthread_sigmask_macro=yes],
Packit Service 991b93
       [gl_cv_func_pthread_sigmask_macro=no])
Packit Service 991b93
    ])
Packit Service 991b93
Packit Service 991b93
  LIB_PTHREAD_SIGMASK=
Packit Service 991b93
Packit Service 991b93
  if test $gl_cv_func_pthread_sigmask_macro = yes; then
Packit Service 991b93
    dnl pthread_sigmask is a dummy macro.
Packit Service 991b93
    HAVE_PTHREAD_SIGMASK=0
Packit Service 991b93
    dnl Make sure to '#undef pthread_sigmask' before defining it.
Packit Service 991b93
    REPLACE_PTHREAD_SIGMASK=1
Packit Service 991b93
  else
Packit Service 991b93
    dnl Test whether the gnulib module 'threadlib' is in use.
Packit Service 991b93
    dnl Some packages like Emacs use --avoid=threadlib.
Packit Service 991b93
    dnl Write the symbol in such a way that it does not cause 'aclocal' to pick
Packit Service 991b93
    dnl the threadlib.m4 file that is installed in $PREFIX/share/aclocal/.
Packit Service 991b93
    m4_ifdef([gl_][THREADLIB], [
Packit Service 991b93
      AC_REQUIRE([gl_][THREADLIB])
Packit Service 991b93
Packit Service 991b93
      if test "$gl_threads_api" = posix; then
Packit Service 991b93
        if test $ac_cv_func_pthread_sigmask = yes; then
Packit Service 991b93
          dnl pthread_sigmask is available without -lpthread.
Packit Service 991b93
          :
Packit Service 991b93
        else
Packit Service 991b93
          if test -n "$LIBMULTITHREAD"; then
Packit Service 991b93
            AC_CACHE_CHECK([for pthread_sigmask in $LIBMULTITHREAD],
Packit Service 991b93
              [gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD],
Packit Service 991b93
              [gl_save_LIBS="$LIBS"
Packit Service 991b93
               LIBS="$LIBS $LIBMULTITHREAD"
Packit Service 991b93
               AC_LINK_IFELSE(
Packit Service 991b93
                 [AC_LANG_PROGRAM(
Packit Service 991b93
                    [[#include <pthread.h>
Packit Service 991b93
                      #include <signal.h>
Packit Service 991b93
                    ]],
Packit Service 991b93
                    [[return pthread_sigmask (0, (sigset_t *) 0, (sigset_t *) 0);]])
Packit Service 991b93
                 ],
Packit Service 991b93
                 [gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD=yes],
Packit Service 991b93
                 [gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD=no])
Packit Service 991b93
               LIBS="$gl_save_LIBS"
Packit Service 991b93
              ])
Packit Service 991b93
            if test $gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD = yes; then
Packit Service 991b93
              dnl pthread_sigmask is available with -pthread or -lpthread.
Packit Service 991b93
              LIB_PTHREAD_SIGMASK="$LIBMULTITHREAD"
Packit Service 991b93
            else
Packit Service 991b93
              dnl pthread_sigmask is not available at all.
Packit Service 991b93
              HAVE_PTHREAD_SIGMASK=0
Packit Service 991b93
            fi
Packit Service 991b93
          else
Packit Service 991b93
            dnl pthread_sigmask is not available at all.
Packit Service 991b93
            HAVE_PTHREAD_SIGMASK=0
Packit Service 991b93
          fi
Packit Service 991b93
        fi
Packit Service 991b93
      else
Packit Service 991b93
        dnl pthread_sigmask may exist but does not interoperate with the chosen
Packit Service 991b93
        dnl multithreading facility.
Packit Service 991b93
        if test $ac_cv_func_pthread_sigmask = yes; then
Packit Service 991b93
          REPLACE_PTHREAD_SIGMASK=1
Packit Service 991b93
        else
Packit Service 991b93
          HAVE_PTHREAD_SIGMASK=0
Packit Service 991b93
        fi
Packit Service 991b93
      fi
Packit Service 991b93
    ], [
Packit Service 991b93
      dnl The module 'threadlib' is not in use, due to --avoid=threadlib being
Packit Service 991b93
      dnl specified.
Packit Service 991b93
      dnl The package either has prepared CPPFLAGS and LIBS for use of
Packit Service 991b93
      dnl POSIX:2008 threads, or wants to build single-threaded programs.
Packit Service 991b93
      if test $ac_cv_func_pthread_sigmask = yes; then
Packit Service 991b93
        dnl pthread_sigmask exists and does not require extra libraries.
Packit Service 991b93
        dnl Assume that it is declared.
Packit Service 991b93
        :
Packit Service 991b93
      else
Packit Service 991b93
        dnl pthread_sigmask either does not exist or needs extra libraries.
Packit Service 991b93
        HAVE_PTHREAD_SIGMASK=0
Packit Service 991b93
        dnl Define the symbol rpl_pthread_sigmask, not pthread_sigmask,
Packit Service 991b93
        dnl so as to not accidentally override the system's pthread_sigmask
Packit Service 991b93
        dnl symbol from libpthread. This is necessary on IRIX 6.5.
Packit Service 991b93
        REPLACE_PTHREAD_SIGMASK=1
Packit Service 991b93
      fi
Packit Service 991b93
    ])
Packit Service 991b93
  fi
Packit Service 991b93
Packit Service 991b93
  AC_SUBST([LIB_PTHREAD_SIGMASK])
Packit Service 991b93
  dnl We don't need a variable LTLIB_PTHREAD_SIGMASK, because when
Packit Service 991b93
  dnl "$gl_threads_api" = posix, $LTLIBMULTITHREAD and $LIBMULTITHREAD are the
Packit Service 991b93
  dnl same.
Packit Service 991b93
Packit Service 991b93
  dnl Now test for some bugs in the system function.
Packit Service 991b93
  if test $HAVE_PTHREAD_SIGMASK = 1; then
Packit Service 991b93
    AC_REQUIRE([AC_PROG_CC])
Packit Service 991b93
    AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit Service 991b93
Packit Service 991b93
    dnl On FreeBSD 6.4, HP-UX 11.31, Solaris 9, in programs that are not linked
Packit Service 991b93
    dnl with -lpthread, the pthread_sigmask() function always returns 0 and has
Packit Service 991b93
    dnl no effect.
Packit Service 991b93
    if test -z "$LIB_PTHREAD_SIGMASK"; then
Packit Service 991b93
      case " $LIBS " in
Packit Service 991b93
        *' -pthread '*) ;;
Packit Service 991b93
        *' -lpthread '*) ;;
Packit Service 991b93
        *)
Packit Service 991b93
          AC_CACHE_CHECK([whether pthread_sigmask works without -lpthread],
Packit Service 991b93
            [gl_cv_func_pthread_sigmask_in_libc_works],
Packit Service 991b93
            [
Packit Service 991b93
              AC_RUN_IFELSE(
Packit Service 991b93
                [AC_LANG_SOURCE([[
Packit Service 991b93
                   #include <pthread.h>
Packit Service 991b93
                   #include <signal.h>
Packit Service 991b93
                   #include <stddef.h>
Packit Service 991b93
                   int main ()
Packit Service 991b93
                   {
Packit Service 991b93
                     sigset_t set;
Packit Service 991b93
                     sigemptyset (&set);
Packit Service 991b93
                     return pthread_sigmask (1729, &set, NULL) != 0;
Packit Service 991b93
                   }]])],
Packit Service 991b93
                [gl_cv_func_pthread_sigmask_in_libc_works=no],
Packit Service 991b93
                [gl_cv_func_pthread_sigmask_in_libc_works=yes],
Packit Service 991b93
                [
Packit Service 991b93
                 changequote(,)dnl
Packit Service 991b93
                 case "$host_os" in
Packit Service 991b93
                   freebsd* | hpux* | solaris | solaris2.[2-9]*)
Packit Service 991b93
                     gl_cv_func_pthread_sigmask_in_libc_works="guessing no";;
Packit Service 991b93
                   *)
Packit Service 991b93
                     gl_cv_func_pthread_sigmask_in_libc_works="guessing yes";;
Packit Service 991b93
                 esac
Packit Service 991b93
                 changequote([,])dnl
Packit Service 991b93
                ])
Packit Service 991b93
            ])
Packit Service 991b93
          case "$gl_cv_func_pthread_sigmask_in_libc_works" in
Packit Service 991b93
            *no)
Packit Service 991b93
              REPLACE_PTHREAD_SIGMASK=1
Packit Service 991b93
              AC_DEFINE([PTHREAD_SIGMASK_INEFFECTIVE], [1],
Packit Service 991b93
                [Define to 1 if pthread_sigmask may return 0 and have no effect.])
Packit Service 991b93
              ;;
Packit Service 991b93
          esac;;
Packit Service 991b93
      esac
Packit Service 991b93
    fi
Packit Service 991b93
Packit Service 991b93
    dnl On Cygwin 1.7.5, the pthread_sigmask() has a wrong return value
Packit Service 991b93
    dnl convention: Upon failure, it returns -1 and sets errno.
Packit Service 991b93
    AC_CACHE_CHECK([whether pthread_sigmask returns error numbers],
Packit Service 991b93
      [gl_cv_func_pthread_sigmask_return_works],
Packit Service 991b93
      [
Packit Service 991b93
        gl_save_LIBS="$LIBS"
Packit Service 991b93
        LIBS="$LIBS $LIB_PTHREAD_SIGMASK"
Packit Service 991b93
        AC_RUN_IFELSE(
Packit Service 991b93
          [AC_LANG_SOURCE([[
Packit Service 991b93
#include <pthread.h>
Packit Service 991b93
#include <signal.h>
Packit Service 991b93
#include <stddef.h>
Packit Service 991b93
int main ()
Packit Service 991b93
{
Packit Service 991b93
  sigset_t set;
Packit Service 991b93
  sigemptyset (&set);
Packit Service 991b93
  if (pthread_sigmask (1729, &set, NULL) == -1)
Packit Service 991b93
    return 1;
Packit Service 991b93
  return 0;
Packit Service 991b93
}]])],
Packit Service 991b93
          [gl_cv_func_pthread_sigmask_return_works=yes],
Packit Service 991b93
          [gl_cv_func_pthread_sigmask_return_works=no],
Packit Service 991b93
          [case "$host_os" in
Packit Service 991b93
             cygwin*)
Packit Service 991b93
               gl_cv_func_pthread_sigmask_return_works="guessing no";;
Packit Service 991b93
             *)
Packit Service 991b93
               gl_cv_func_pthread_sigmask_return_works="guessing yes";;
Packit Service 991b93
           esac
Packit Service 991b93
          ])
Packit Service 991b93
        LIBS="$gl_save_LIBS"
Packit Service 991b93
      ])
Packit Service 991b93
    case "$gl_cv_func_pthread_sigmask_return_works" in
Packit Service 991b93
      *no)
Packit Service 991b93
        REPLACE_PTHREAD_SIGMASK=1
Packit Service 991b93
        AC_DEFINE([PTHREAD_SIGMASK_FAILS_WITH_ERRNO], [1],
Packit Service 991b93
          [Define to 1 if pthread_sigmask(), when it fails, returns -1 and sets errno.])
Packit Service 991b93
        ;;
Packit Service 991b93
    esac
Packit Service 991b93
Packit Service 991b93
    dnl On IRIX 6.5, in a single-threaded program, pending signals are not
Packit Service 991b93
    dnl immediately delivered when they are unblocked through pthread_sigmask,
Packit Service 991b93
    dnl only a little while later.
Packit Service 991b93
    AC_CACHE_CHECK([whether pthread_sigmask unblocks signals correctly],
Packit Service 991b93
      [gl_cv_func_pthread_sigmask_unblock_works],
Packit Service 991b93
      [
Packit Service 991b93
        case "$host_os" in
Packit Service 991b93
          irix*)
Packit Service 991b93
            gl_cv_func_pthread_sigmask_unblock_works="guessing no";;
Packit Service 991b93
          *)
Packit Service 991b93
            gl_cv_func_pthread_sigmask_unblock_works="guessing yes";;
Packit Service 991b93
        esac
Packit Service 991b93
        m4_ifdef([gl_][THREADLIB],
Packit Service 991b93
          [dnl Link against $LIBMULTITHREAD, not only $LIB_PTHREAD_SIGMASK.
Packit Service 991b93
           dnl Otherwise we get a false positive on those platforms where
Packit Service 991b93
           dnl $gl_cv_func_pthread_sigmask_in_libc_works is "no".
Packit Service 991b93
           gl_save_LIBS=$LIBS
Packit Service 991b93
           LIBS="$LIBS $LIBMULTITHREAD"])
Packit Service 991b93
        AC_RUN_IFELSE(
Packit Service 991b93
          [AC_LANG_SOURCE([[
Packit Service 991b93
#include <pthread.h>
Packit Service 991b93
#include <signal.h>
Packit Service 991b93
#include <stdio.h>
Packit Service 991b93
#include <stdlib.h>
Packit Service 991b93
#include <unistd.h>
Packit Service 991b93
static volatile int sigint_occurred;
Packit Service 991b93
static void
Packit Service 991b93
sigint_handler (int sig)
Packit Service 991b93
{
Packit Service 991b93
  sigint_occurred++;
Packit Service 991b93
}
Packit Service 991b93
int main ()
Packit Service 991b93
{
Packit Service 991b93
  sigset_t set;
Packit Service 991b93
  int pid = getpid ();
Packit Service 991b93
  char command[80];
Packit Service 991b93
  signal (SIGINT, sigint_handler);
Packit Service 991b93
  sigemptyset (&set);
Packit Service 991b93
  sigaddset (&set, SIGINT);
Packit Service 991b93
  if (!(pthread_sigmask (SIG_BLOCK, &set, NULL) == 0))
Packit Service 991b93
    return 1;
Packit Service 991b93
  sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, pid);
Packit Service 991b93
  if (!(system (command) == 0))
Packit Service 991b93
    return 2;
Packit Service 991b93
  sleep (2);
Packit Service 991b93
  if (!(sigint_occurred == 0))
Packit Service 991b93
    return 3;
Packit Service 991b93
  if (!(pthread_sigmask (SIG_UNBLOCK, &set, NULL) == 0))
Packit Service 991b93
    return 4;
Packit Service 991b93
  if (!(sigint_occurred == 1)) /* This fails on IRIX.  */
Packit Service 991b93
    return 5;
Packit Service 991b93
  return 0;
Packit Service 991b93
}]])],
Packit Service 991b93
          [:],
Packit Service 991b93
          [gl_cv_func_pthread_sigmask_unblock_works=no],
Packit Service 991b93
          [:])
Packit Service 991b93
        m4_ifdef([gl_][THREADLIB], [LIBS=$gl_save_LIBS])
Packit Service 991b93
      ])
Packit Service 991b93
    case "$gl_cv_func_pthread_sigmask_unblock_works" in
Packit Service 991b93
      *no)
Packit Service 991b93
        REPLACE_PTHREAD_SIGMASK=1
Packit Service 991b93
        AC_DEFINE([PTHREAD_SIGMASK_UNBLOCK_BUG], [1],
Packit Service 991b93
          [Define to 1 if pthread_sigmask() unblocks signals incorrectly.])
Packit Service 991b93
        ;;
Packit Service 991b93
    esac
Packit Service 991b93
  fi
Packit Service 991b93
])
Packit Service 991b93
Packit Service 991b93
# Prerequisite of lib/pthread_sigmask.c.
Packit Service 991b93
AC_DEFUN([gl_PREREQ_PTHREAD_SIGMASK],
Packit Service 991b93
[
Packit Service 991b93
  if test $HAVE_PTHREAD_SIGMASK = 1; then
Packit Service 991b93
    AC_DEFINE([HAVE_PTHREAD_SIGMASK], [1],
Packit Service 991b93
      [Define to 1 if the pthread_sigmask function can be used (despite bugs).])
Packit Service 991b93
  fi
Packit Service 991b93
])