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