| 1 |
# pthread_sigmask.m4 |
| 2 |
# serial 25 |
| 3 |
dnl Copyright (C) 2011-2026 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) |
| 12 |
|
| 13 |
AC_CHECK_FUNCS_ONCE([pthread_sigmask]) |
| 14 |
|
| 15 |
dnl On MinGW pthread_sigmask is just a macro which always returns 0. |
| 16 |
dnl It does not exist as a real function, which is required by POSIX. |
| 17 |
AC_CACHE_CHECK([whether pthread_sigmask is a macro], |
| 18 |
[gl_cv_func_pthread_sigmask_macro], |
| 19 |
[AC_EGREP_CPP([headers_define_pthread_sigmask], [ |
| 20 |
#include <pthread.h> |
| 21 |
#include <signal.h> |
| 22 |
#if defined _WIN32 && defined pthread_sigmask |
| 23 |
headers_define_pthread_sigmask |
| 24 |
#endif], |
| 25 |
[gl_cv_func_pthread_sigmask_macro=yes], |
| 26 |
[gl_cv_func_pthread_sigmask_macro=no]) |
| 27 |
]) |
| 28 |
|
| 29 |
PTHREAD_SIGMASK_LIB= |
| 30 |
|
| 31 |
if test $gl_cv_func_pthread_sigmask_macro = yes; then |
| 32 |
dnl pthread_sigmask is a dummy macro. |
| 33 |
HAVE_PTHREAD_SIGMASK=0 |
| 34 |
dnl Make sure to '#undef pthread_sigmask' before defining it. |
| 35 |
REPLACE_PTHREAD_SIGMASK=1 |
| 36 |
else |
| 37 |
dnl Test whether the gnulib module 'threadlib' is in use. |
| 38 |
dnl Some packages like Emacs use --avoid=threadlib. |
| 39 |
dnl Write the symbol in such a way that it does not cause 'aclocal' to pick |
| 40 |
dnl the threadlib.m4 file that is installed in $PREFIX/share/aclocal/. |
| 41 |
m4_ifdef([gl_][THREADLIB], [ |
| 42 |
AC_REQUIRE([gl_][THREADLIB]) |
| 43 |
|
| 44 |
if test "$gl_threads_api" = posix; then |
| 45 |
if test $ac_cv_func_pthread_sigmask = yes; then |
| 46 |
dnl pthread_sigmask is available without -lpthread. |
| 47 |
: |
| 48 |
else |
| 49 |
if test -n "$LIBMULTITHREAD"; then |
| 50 |
AC_CACHE_CHECK([for pthread_sigmask in $LIBMULTITHREAD], |
| 51 |
[gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD], |
| 52 |
[gl_saved_LIBS="$LIBS" |
| 53 |
LIBS="$LIBS $LIBMULTITHREAD" |
| 54 |
AC_LINK_IFELSE( |
| 55 |
[AC_LANG_PROGRAM( |
| 56 |
[[#include <pthread.h> |
| 57 |
#include <signal.h> |
| 58 |
]], |
| 59 |
[[return pthread_sigmask (0, (sigset_t *) 0, (sigset_t *) 0);]]) |
| 60 |
], |
| 61 |
[gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD=yes], |
| 62 |
[gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD=no]) |
| 63 |
LIBS="$gl_saved_LIBS" |
| 64 |
]) |
| 65 |
if test $gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD = yes; then |
| 66 |
dnl pthread_sigmask is available with -pthread or -lpthread. |
| 67 |
PTHREAD_SIGMASK_LIB="$LIBMULTITHREAD" |
| 68 |
else |
| 69 |
dnl pthread_sigmask is not available at all. |
| 70 |
HAVE_PTHREAD_SIGMASK=0 |
| 71 |
fi |
| 72 |
else |
| 73 |
dnl pthread_sigmask is not available at all. |
| 74 |
HAVE_PTHREAD_SIGMASK=0 |
| 75 |
fi |
| 76 |
fi |
| 77 |
else |
| 78 |
dnl pthread_sigmask may exist but does not interoperate with the chosen |
| 79 |
dnl multithreading facility. |
| 80 |
if test $ac_cv_func_pthread_sigmask = yes; then |
| 81 |
REPLACE_PTHREAD_SIGMASK=1 |
| 82 |
else |
| 83 |
HAVE_PTHREAD_SIGMASK=0 |
| 84 |
fi |
| 85 |
fi |
| 86 |
], [ |
| 87 |
dnl The module 'threadlib' is not in use, due to --avoid=threadlib being |
| 88 |
dnl specified. |
| 89 |
dnl The package either has prepared CPPFLAGS and LIBS for use of |
| 90 |
dnl POSIX:2008 threads, or wants to build single-threaded programs. |
| 91 |
if test $ac_cv_func_pthread_sigmask = yes; then |
| 92 |
dnl pthread_sigmask exists and does not require extra libraries. |
| 93 |
dnl Assume that it is declared. |
| 94 |
: |
| 95 |
else |
| 96 |
dnl pthread_sigmask either does not exist or needs extra libraries. |
| 97 |
HAVE_PTHREAD_SIGMASK=0 |
| 98 |
dnl Define the symbol rpl_pthread_sigmask, not pthread_sigmask, |
| 99 |
dnl so as to not accidentally override the system's pthread_sigmask |
| 100 |
dnl symbol from libpthread. |
| 101 |
REPLACE_PTHREAD_SIGMASK=1 |
| 102 |
fi |
| 103 |
]) |
| 104 |
fi |
| 105 |
|
| 106 |
AC_SUBST([PTHREAD_SIGMASK_LIB]) |
| 107 |
dnl For backward compatibility. |
| 108 |
LIB_PTHREAD_SIGMASK="$PTHREAD_SIGMASK_LIB" |
| 109 |
AC_SUBST([LIB_PTHREAD_SIGMASK]) |
| 110 |
dnl We don't need a variable LTLIB_PTHREAD_SIGMASK, because when |
| 111 |
dnl "$gl_threads_api" = posix, $LTLIBMULTITHREAD and $LIBMULTITHREAD are the |
| 112 |
dnl same. |
| 113 |
|
| 114 |
dnl Now test for some bugs in the system function. |
| 115 |
if test $HAVE_PTHREAD_SIGMASK = 1; then |
| 116 |
AC_REQUIRE([AC_PROG_CC]) |
| 117 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 118 |
|
| 119 |
dnl On FreeBSD 13.0, MidnightBSD 1.1, HP-UX 11.31, Solaris 9, in programs |
| 120 |
dnl that are not linked with -lpthread, the pthread_sigmask() function |
| 121 |
dnl always returns 0 and has no effect. |
| 122 |
if test -z "$PTHREAD_SIGMASK_LIB"; then |
| 123 |
case " $LIBS " in |
| 124 |
*' -pthread '*) ;; |
| 125 |
*' -lpthread '*) ;; |
| 126 |
*) |
| 127 |
AC_CACHE_CHECK([whether pthread_sigmask works without -lpthread], |
| 128 |
[gl_cv_func_pthread_sigmask_in_libc_works], |
| 129 |
[ |
| 130 |
AC_RUN_IFELSE( |
| 131 |
[AC_LANG_SOURCE([[ |
| 132 |
#include <pthread.h> |
| 133 |
#include <signal.h> |
| 134 |
#include <stddef.h> |
| 135 |
int main () |
| 136 |
{ |
| 137 |
sigset_t set; |
| 138 |
sigemptyset (&set); |
| 139 |
return pthread_sigmask (1729, &set, NULL) != 0; |
| 140 |
}]])], |
| 141 |
[gl_cv_func_pthread_sigmask_in_libc_works=no], |
| 142 |
[gl_cv_func_pthread_sigmask_in_libc_works=yes], |
| 143 |
[ |
| 144 |
changequote(,)dnl |
| 145 |
case "$host_os" in |
| 146 |
freebsd* | midnightbsd* | hpux* | solaris | solaris2.[2-9]*) |
| 147 |
gl_cv_func_pthread_sigmask_in_libc_works="guessing no";; |
| 148 |
*) |
| 149 |
gl_cv_func_pthread_sigmask_in_libc_works="guessing yes";; |
| 150 |
esac |
| 151 |
changequote([,])dnl |
| 152 |
]) |
| 153 |
]) |
| 154 |
case "$gl_cv_func_pthread_sigmask_in_libc_works" in |
| 155 |
*no) |
| 156 |
REPLACE_PTHREAD_SIGMASK=1 |
| 157 |
AC_DEFINE([PTHREAD_SIGMASK_INEFFECTIVE], [1], |
| 158 |
[Define to 1 if pthread_sigmask may return 0 and have no effect.]) |
| 159 |
;; |
| 160 |
esac;; |
| 161 |
esac |
| 162 |
fi |
| 163 |
|
| 164 |
dnl On Cygwin 1.7.5, the pthread_sigmask() has a wrong return value |
| 165 |
dnl convention: Upon failure, it returns -1 and sets errno. |
| 166 |
AC_CACHE_CHECK([whether pthread_sigmask returns error numbers], |
| 167 |
[gl_cv_func_pthread_sigmask_return_works], |
| 168 |
[ |
| 169 |
gl_saved_LIBS="$LIBS" |
| 170 |
LIBS="$LIBS $PTHREAD_SIGMASK_LIB" |
| 171 |
AC_RUN_IFELSE( |
| 172 |
[AC_LANG_SOURCE([[ |
| 173 |
#include <pthread.h> |
| 174 |
#include <signal.h> |
| 175 |
#include <stddef.h> |
| 176 |
int main () |
| 177 |
{ |
| 178 |
sigset_t set; |
| 179 |
sigemptyset (&set); |
| 180 |
if (pthread_sigmask (1729, &set, NULL) == -1) |
| 181 |
return 1; |
| 182 |
return 0; |
| 183 |
}]])], |
| 184 |
[gl_cv_func_pthread_sigmask_return_works=yes], |
| 185 |
[gl_cv_func_pthread_sigmask_return_works=no], |
| 186 |
[case "$host_os" in |
| 187 |
cygwin*) |
| 188 |
gl_cv_func_pthread_sigmask_return_works="guessing no";; |
| 189 |
*) |
| 190 |
gl_cv_func_pthread_sigmask_return_works="guessing yes";; |
| 191 |
esac |
| 192 |
]) |
| 193 |
LIBS="$gl_saved_LIBS" |
| 194 |
]) |
| 195 |
case "$gl_cv_func_pthread_sigmask_return_works" in |
| 196 |
*no) |
| 197 |
REPLACE_PTHREAD_SIGMASK=1 |
| 198 |
AC_DEFINE([PTHREAD_SIGMASK_FAILS_WITH_ERRNO], [1], |
| 199 |
[Define to 1 if pthread_sigmask(), when it fails, returns -1 and sets errno.]) |
| 200 |
;; |
| 201 |
esac |
| 202 |
fi |
| 203 |
]) |
| 204 |
|
| 205 |
# Prerequisite of lib/pthread_sigmask.c. |
| 206 |
AC_DEFUN([gl_PREREQ_PTHREAD_SIGMASK], |
| 207 |
[ |
| 208 |
if test $HAVE_PTHREAD_SIGMASK = 1; then |
| 209 |
AC_DEFINE([HAVE_PTHREAD_SIGMASK], [1], |
| 210 |
[Define to 1 if the pthread_sigmask function can be used (despite bugs).]) |
| 211 |
fi |
| 212 |
]) |