]> code.delx.au - gnu-emacs/blob - m4/pthread_sigmask.m4
Merge from origin/emacs-24
[gnu-emacs] / m4 / pthread_sigmask.m4
1 # pthread_sigmask.m4 serial 15
2 dnl Copyright (C) 2011-2015 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_PTHREAD_SIGMASK],
8 [
9 AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
10
11 AC_CHECK_FUNCS_ONCE([pthread_sigmask])
12 LIB_PTHREAD_SIGMASK=
13
14 dnl Test whether the gnulib module 'threadlib' is in use.
15 dnl Some packages like Emacs use --avoid=threadlib.
16 dnl Write the symbol in such a way that it does not cause 'aclocal' to pick
17 dnl the threadlib.m4 file that is installed in $PREFIX/share/aclocal/.
18 m4_ifdef([gl_][THREADLIB], [
19 AC_REQUIRE([gl_][THREADLIB])
20
21 if test "$gl_threads_api" = posix; then
22 if test $ac_cv_func_pthread_sigmask = yes; then
23 dnl pthread_sigmask is available without -lpthread.
24 :
25 else
26 if test -n "$LIBMULTITHREAD"; then
27 AC_CACHE_CHECK([for pthread_sigmask in $LIBMULTITHREAD],
28 [gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD],
29 [gl_save_LIBS="$LIBS"
30 LIBS="$LIBS $LIBMULTITHREAD"
31 AC_LINK_IFELSE(
32 [AC_LANG_PROGRAM(
33 [[#include <pthread.h>
34 #include <signal.h>
35 ]],
36 [[return pthread_sigmask (0, (sigset_t *) 0, (sigset_t *) 0);]])
37 ],
38 [gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD=yes],
39 [gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD=no])
40 LIBS="$gl_save_LIBS"
41 ])
42 if test $gl_cv_func_pthread_sigmask_in_LIBMULTITHREAD = yes; then
43 dnl pthread_sigmask is available with -pthread or -lpthread.
44 LIB_PTHREAD_SIGMASK="$LIBMULTITHREAD"
45 else
46 dnl pthread_sigmask is not available at all.
47 HAVE_PTHREAD_SIGMASK=0
48 fi
49 else
50 dnl pthread_sigmask is not available at all.
51 HAVE_PTHREAD_SIGMASK=0
52 fi
53 fi
54 else
55 dnl pthread_sigmask may exist but does not interoperate with the chosen
56 dnl multithreading facility.
57 dnl If "$gl_threads_api" = pth, we could use the function pth_sigmask,
58 dnl but it is equivalent to sigprocmask, so we choose to emulate
59 dnl pthread_sigmask with sigprocmask also in this case. This yields fewer
60 dnl link dependencies.
61 if test $ac_cv_func_pthread_sigmask = yes; then
62 REPLACE_PTHREAD_SIGMASK=1
63 else
64 HAVE_PTHREAD_SIGMASK=0
65 fi
66 fi
67 ], [
68 dnl The module 'threadlib' is not in use, due to --avoid=threadlib being
69 dnl specified.
70 dnl The package either has prepared CPPFLAGS and LIBS for use of POSIX:2008
71 dnl threads, or wants to build single-threaded programs.
72 if test $ac_cv_func_pthread_sigmask = yes; then
73 dnl pthread_sigmask exists and does not require extra libraries.
74 dnl Assume that it is declared.
75 :
76 else
77 dnl pthread_sigmask either does not exist or needs extra libraries.
78 HAVE_PTHREAD_SIGMASK=0
79 dnl Define the symbol rpl_pthread_sigmask, not pthread_sigmask,
80 dnl so as to not accidentally override the system's pthread_sigmask
81 dnl symbol from libpthread. This is necessary on IRIX 6.5.
82 REPLACE_PTHREAD_SIGMASK=1
83 fi
84 ])
85
86 AC_SUBST([LIB_PTHREAD_SIGMASK])
87 dnl We don't need a variable LTLIB_PTHREAD_SIGMASK, because when
88 dnl "$gl_threads_api" = posix, $LTLIBMULTITHREAD and $LIBMULTITHREAD are the
89 dnl same.
90
91 dnl Now test for some bugs in the system function.
92 if test $HAVE_PTHREAD_SIGMASK = 1; then
93 AC_REQUIRE([AC_PROG_CC])
94 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
95
96 dnl On FreeBSD 6.4, HP-UX 11.31, Solaris 9, in programs that are not linked
97 dnl with -lpthread, the pthread_sigmask() function always returns 0 and has
98 dnl no effect.
99 if test -z "$LIB_PTHREAD_SIGMASK"; then
100 case " $LIBS " in
101 *' -pthread '*) ;;
102 *' -lpthread '*) ;;
103 *)
104 AC_CACHE_CHECK([whether pthread_sigmask works without -lpthread],
105 [gl_cv_func_pthread_sigmask_in_libc_works],
106 [
107 AC_RUN_IFELSE(
108 [AC_LANG_SOURCE([[
109 #include <pthread.h>
110 #include <signal.h>
111 #include <stddef.h>
112 int main ()
113 {
114 sigset_t set;
115 sigemptyset (&set);
116 return pthread_sigmask (1729, &set, NULL) != 0;
117 }]])],
118 [gl_cv_func_pthread_sigmask_in_libc_works=no],
119 [gl_cv_func_pthread_sigmask_in_libc_works=yes],
120 [
121 changequote(,)dnl
122 case "$host_os" in
123 freebsd* | hpux* | solaris | solaris2.[2-9]*)
124 gl_cv_func_pthread_sigmask_in_libc_works="guessing no";;
125 *)
126 gl_cv_func_pthread_sigmask_in_libc_works="guessing yes";;
127 esac
128 changequote([,])dnl
129 ])
130 ])
131 case "$gl_cv_func_pthread_sigmask_in_libc_works" in
132 *no)
133 REPLACE_PTHREAD_SIGMASK=1
134 AC_DEFINE([PTHREAD_SIGMASK_INEFFECTIVE], [1],
135 [Define to 1 if pthread_sigmask may return 0 and have no effect.])
136 ;;
137 esac;;
138 esac
139 fi
140
141 dnl On Cygwin 1.7.5, the pthread_sigmask() has a wrong return value
142 dnl convention: Upon failure, it returns -1 and sets errno.
143 AC_CACHE_CHECK([whether pthread_sigmask returns error numbers],
144 [gl_cv_func_pthread_sigmask_return_works],
145 [
146 gl_save_LIBS="$LIBS"
147 LIBS="$LIBS $LIB_PTHREAD_SIGMASK"
148 AC_RUN_IFELSE(
149 [AC_LANG_SOURCE([[
150 #include <pthread.h>
151 #include <signal.h>
152 #include <stddef.h>
153 int main ()
154 {
155 sigset_t set;
156 sigemptyset (&set);
157 if (pthread_sigmask (1729, &set, NULL) == -1)
158 return 1;
159 return 0;
160 }]])],
161 [gl_cv_func_pthread_sigmask_return_works=yes],
162 [gl_cv_func_pthread_sigmask_return_works=no],
163 [case "$host_os" in
164 cygwin*)
165 gl_cv_func_pthread_sigmask_return_works="guessing no";;
166 *)
167 gl_cv_func_pthread_sigmask_return_works="guessing yes";;
168 esac
169 ])
170 LIBS="$gl_save_LIBS"
171 ])
172 case "$gl_cv_func_pthread_sigmask_return_works" in
173 *no)
174 REPLACE_PTHREAD_SIGMASK=1
175 AC_DEFINE([PTHREAD_SIGMASK_FAILS_WITH_ERRNO], [1],
176 [Define to 1 if pthread_sigmask(), when it fails, returns -1 and sets errno.])
177 ;;
178 esac
179
180 dnl On IRIX 6.5, in a single-threaded program, pending signals are not
181 dnl immediately delivered when they are unblocked through pthread_sigmask,
182 dnl only a little while later.
183 AC_CACHE_CHECK([whether pthread_sigmask unblocks signals correctly],
184 [gl_cv_func_pthread_sigmask_unblock_works],
185 [
186 case "$host_os" in
187 irix*)
188 gl_cv_func_pthread_sigmask_unblock_works="guessing no";;
189 *)
190 gl_cv_func_pthread_sigmask_unblock_works="guessing yes";;
191 esac
192 m4_ifdef([gl_][THREADLIB],
193 [dnl Link against $LIBMULTITHREAD, not only $LIB_PTHREAD_SIGMASK.
194 dnl Otherwise we get a false positive on those platforms where
195 dnl $gl_cv_func_pthread_sigmask_in_libc_works is "no".
196 gl_save_LIBS=$LIBS
197 LIBS="$LIBS $LIBMULTITHREAD"])
198 AC_RUN_IFELSE(
199 [AC_LANG_SOURCE([[
200 #include <pthread.h>
201 #include <signal.h>
202 #include <stdio.h>
203 #include <stdlib.h>
204 #include <unistd.h>
205 static volatile int sigint_occurred;
206 static void
207 sigint_handler (int sig)
208 {
209 sigint_occurred++;
210 }
211 int main ()
212 {
213 sigset_t set;
214 int pid = getpid ();
215 char command[80];
216 signal (SIGINT, sigint_handler);
217 sigemptyset (&set);
218 sigaddset (&set, SIGINT);
219 if (!(pthread_sigmask (SIG_BLOCK, &set, NULL) == 0))
220 return 1;
221 sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, pid);
222 if (!(system (command) == 0))
223 return 2;
224 sleep (2);
225 if (!(sigint_occurred == 0))
226 return 3;
227 if (!(pthread_sigmask (SIG_UNBLOCK, &set, NULL) == 0))
228 return 4;
229 if (!(sigint_occurred == 1)) /* This fails on IRIX. */
230 return 5;
231 return 0;
232 }]])],
233 [:],
234 [gl_cv_func_pthread_sigmask_unblock_works=no],
235 [:])
236 m4_ifdef([gl_][THREADLIB], [LIBS=$gl_save_LIBS])
237 ])
238 case "$gl_cv_func_pthread_sigmask_unblock_works" in
239 *no)
240 REPLACE_PTHREAD_SIGMASK=1
241 AC_DEFINE([PTHREAD_SIGMASK_UNBLOCK_BUG], [1],
242 [Define to 1 if pthread_sigmask() unblocks signals incorrectly.])
243 ;;
244 esac
245 fi
246 ])
247
248 # Prerequisite of lib/pthread_sigmask.c.
249 AC_DEFUN([gl_PREREQ_PTHREAD_SIGMASK],
250 [
251 if test $HAVE_PTHREAD_SIGMASK = 1; then
252 AC_DEFINE([HAVE_PTHREAD_SIGMASK], [1],
253 [Define to 1 if the pthread_sigmask function can be used (despite bugs).])
254 fi
255 ])