1 dnl -----------------------------------------------------------------
2 dnl apr_threads.m4: APR's autoconf macros for testing thread support
6 dnl APR_CHECK_PTHREADS_H([ ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
8 dnl gcc issues warnings when parsing AIX 4.3.3's pthread.h
9 dnl which causes autoconf to incorrectly conclude that
10 dnl pthreads is not available.
11 dnl Turn off warnings if we're using gcc.
13 AC_DEFUN(APR_CHECK_PTHREADS_H, [
14 if test "$GCC" = "yes"; then
16 CPPFLAGS="$CPPFLAGS -w"
17 AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
20 AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
26 dnl APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS
28 AC_DEFUN(APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS, [
29 AC_CACHE_CHECK(whether pthread_getspecific takes two arguments, ac_cv_pthread_getspecific_two_args,[
35 pthread_getspecific(key,&tmp);
37 ac_cv_pthread_getspecific_two_args=yes
39 ac_cv_pthread_getspecific_two_args=no
43 if test "$ac_cv_pthread_getspecific_two_args" = "yes"; then
44 AC_DEFINE(PTHREAD_GETSPECIFIC_TAKES_TWO_ARGS, 1, [Define if pthread_getspecific() has two args])
50 dnl APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG
52 AC_DEFUN(APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG, [
53 AC_CACHE_CHECK(whether pthread_attr_getdetachstate takes one argument, ac_cv_pthread_attr_getdetachstate_one_arg,[
58 pthread_attr_getdetachstate(attr);
60 ac_cv_pthread_attr_getdetachstate_one_arg=yes
62 ac_cv_pthread_attr_getdetachstate_one_arg=no
66 if test "$ac_cv_pthread_attr_getdetachstate_one_arg" = "yes"; then
67 AC_DEFINE(PTHREAD_ATTR_GETDETACHSTATE_TAKES_ONE_ARG, 1, [Define if pthread_attr_getdetachstate() has one arg])
73 dnl APR_PTHREADS_TRY_RUN(actions-if-success)
75 dnl Try running a program which uses pthreads, executing the
76 dnl actions-if-success commands on success.
78 AC_DEFUN(APR_PTHREADS_TRY_RUN, [
83 void *thread_routine(void *data) {
89 pthread_mutexattr_t mattr;
90 pthread_once_t once_init = PTHREAD_ONCE_INIT;
92 pthread_mutexattr_init(&mattr);
93 return pthread_create(&thd, NULL, thread_routine, &data);
94 } ], [apr_p_t_r=yes], [apr_p_t_r=no], [apr_p_t_r=no])
96 if test $apr_p_t_r = yes; then
104 dnl APR_PTHREADS_CHECK()
106 dnl Try to find a way to enable POSIX threads. Sets the
107 dnl pthreads_working variable to "yes" on success.
109 AC_DEFUN(APR_PTHREADS_CHECK,[
111 AC_CACHE_CHECK([for CFLAGS needed for pthreads], [apr_cv_pthreads_cflags],
112 [apr_ptc_cflags=$CFLAGS
113 for flag in none -kthread -pthread -pthreads -mt -mthreads -Kthread -threads; do
114 CFLAGS=$apr_ptc_cflags
115 test "x$flag" != "xnone" && CFLAGS="$CFLAGS $flag"
116 APR_PTHREADS_TRY_RUN([
117 apr_cv_pthreads_cflags="$flag"
121 CFLAGS=$apr_ptc_cflags
124 if test -n "$apr_cv_pthreads_cflags"; then
126 if test "x$apr_cv_pthreads_cflags" != "xnone"; then
127 APR_ADDTO(CFLAGS,[$apr_cv_pthreads_cflags])
131 # The CFLAGS may or may not be sufficient to ensure that libapr
132 # depends on the pthreads library: some versions of libtool
133 # drop -pthread when passed on the link line; some versions of
134 # gcc ignore -pthread when linking a shared object. So always
135 # try and add the relevant library to LIBS too.
137 AC_CACHE_CHECK([for LIBS needed for pthreads], [apr_cv_pthreads_lib], [
139 for lib in -lpthread -lpthreads -lc_r; do
140 LIBS="$apr_ptc_libs $lib"
141 APR_PTHREADS_TRY_RUN([
142 apr_cv_pthreads_lib=$lib
149 if test -n "$apr_cv_pthreads_lib"; then
151 APR_ADDTO(LIBS,[$apr_cv_pthreads_lib])
154 if test "$pthreads_working" = "yes"; then
155 threads_result="POSIX Threads found"
157 threads_result="POSIX Threads not found"
162 dnl APR_PTHREADS_CHECK_SAVE
163 dnl APR_PTHREADS_CHECK_RESTORE
165 dnl Save the global environment variables that might be modified during
166 dnl the checks for threading support so that they can restored if the
167 dnl result is not what the caller wanted.
169 AC_DEFUN(APR_PTHREADS_CHECK_SAVE, [
170 apr_pthsv_CFLAGS="$CFLAGS"
171 apr_pthsv_LIBS="$LIBS"
174 AC_DEFUN(APR_PTHREADS_CHECK_RESTORE, [
175 CFLAGS="$apr_pthsv_CFLAGS"
176 LIBS="$apr_pthsv_LIBS"
180 dnl APR_CHECK_SIGWAIT_ONE_ARG
182 AC_DEFUN(APR_CHECK_SIGWAIT_ONE_ARG,[
183 AC_CACHE_CHECK(whether sigwait takes one argument,ac_cv_sigwait_one_arg,[
185 #if defined(__NETBSD__) || defined(DARWIN)
186 /* When using the unproven-pthreads package, we need to pull in this
187 * header to get a prototype for sigwait(). Else things will fail later
188 * on. XXX Should probably be fixed in the unproven-pthreads package.
189 * Darwin is declaring sigwait() in the wrong place as well.
199 ac_cv_sigwait_one_arg=yes
201 ac_cv_sigwait_one_arg=no
203 if test "$ac_cv_sigwait_one_arg" = "yes"; then
204 AC_DEFINE(SIGWAIT_TAKES_ONE_ARG,1,[ ])
208 dnl Check for recursive mutex support (per SUSv3).
209 AC_DEFUN([APR_CHECK_PTHREAD_RECURSIVE_MUTEX], [
210 AC_CACHE_CHECK([for recursive mutex support], [apr_cv_mutex_recursive],
211 [AC_TRY_RUN([#include <sys/types.h>
216 pthread_mutexattr_t attr;
219 exit (pthread_mutexattr_init(&attr)
220 || pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)
221 || pthread_mutex_init(&m, &attr));
222 }], [apr_cv_mutex_recursive=yes], [apr_cv_mutex_recursive=no],
223 [apr_cv_mutex_recursive=no])])
225 if test "$apr_cv_mutex_recursive" = "yes"; then
226 AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE], 1,
227 [Define if recursive pthread mutexes are available])
231 dnl Check for robust process-shared mutex support
232 AC_DEFUN([APR_CHECK_PTHREAD_ROBUST_SHARED_MUTEX], [
233 AC_CACHE_CHECK([for robust cross-process mutex support],
234 [apr_cv_mutex_robust_shared],
236 #include <sys/types.h>
240 int main(int argc, char **argv)
242 pthread_mutex_t mutex;
243 pthread_mutexattr_t attr;
245 if (pthread_mutexattr_init(&attr))
247 if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))
249 if (pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP))
251 if (pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT))
253 if (pthread_mutex_init(&mutex, &attr))
255 if (pthread_mutexattr_destroy(&attr))
257 if (pthread_mutex_destroy(&mutex))
261 }], [apr_cv_mutex_robust_shared=yes], [apr_cv_mutex_robust_shared=no])])
263 if test "$apr_cv_mutex_robust_shared" = "yes"; then
264 AC_DEFINE([HAVE_PTHREAD_MUTEX_ROBUST], 1,
265 [Define if cross-process robust mutexes are available])