1
dnl -------------------------------------------------------- -*- autoconf -*-
2
dnl Copyright 2000-2005 The Apache Software Foundation
4
dnl Licensed under the Apache License, Version 2.0 (the "License");
5
dnl you may not use this file except in compliance with the License.
6
dnl You may obtain a copy of the License at
8
dnl http://www.apache.org/licenses/LICENSE-2.0
10
dnl Unless required by applicable law or agreed to in writing, software
11
dnl distributed under the License is distributed on an "AS IS" BASIS,
12
dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
dnl See the License for the specific language governing permissions and
14
dnl limitations under the License.
16
dnl -----------------------------------------------------------------
17
dnl apr_threads.m4: APR's autoconf macros for testing thread support
21
dnl APR_CHECK_PTHREADS_H([ ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
23
dnl gcc issues warnings when parsing AIX 4.3.3's pthread.h
24
dnl which causes autoconf to incorrectly conclude that
25
dnl pthreads is not available.
26
dnl Turn off warnings if we're using gcc.
28
AC_DEFUN(APR_CHECK_PTHREADS_H, [
29
if test "$GCC" = "yes"; then
31
CPPFLAGS="$CPPFLAGS -w"
32
AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
35
AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
41
dnl APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS
43
AC_DEFUN(APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS, [
44
AC_CACHE_CHECK(whether pthread_getspecific takes two arguments, ac_cv_pthread_getspecific_two_args,[
50
pthread_getspecific(key,&tmp);
52
ac_cv_pthread_getspecific_two_args=yes
54
ac_cv_pthread_getspecific_two_args=no
58
if test "$ac_cv_pthread_getspecific_two_args" = "yes"; then
59
AC_DEFINE(PTHREAD_GETSPECIFIC_TAKES_TWO_ARGS, 1, [Define if pthread_getspecific() has two args])
65
dnl APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG
67
AC_DEFUN(APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG, [
68
AC_CACHE_CHECK(whether pthread_attr_getdetachstate takes one argument, ac_cv_pthread_attr_getdetachstate_one_arg,[
73
pthread_attr_getdetachstate(attr);
75
ac_cv_pthread_attr_getdetachstate_one_arg=yes
77
ac_cv_pthread_attr_getdetachstate_one_arg=no
81
if test "$ac_cv_pthread_attr_getdetachstate_one_arg" = "yes"; then
82
AC_DEFINE(PTHREAD_ATTR_GETDETACHSTATE_TAKES_ONE_ARG, 1, [Define if pthread_attr_getdetachstate() has one arg])
88
dnl APR_PTHREADS_TRY_RUN(actions-if-success)
90
dnl Try running a program which uses pthreads, executing the
91
dnl actions-if-success commands on success.
93
AC_DEFUN(APR_PTHREADS_TRY_RUN, [
98
void *thread_routine(void *data) {
104
pthread_mutexattr_t mattr;
105
pthread_once_t once_init = PTHREAD_ONCE_INIT;
107
pthread_mutexattr_init(&mattr);
108
return pthread_create(&thd, NULL, thread_routine, &data);
109
} ], [apr_p_t_r=yes], [apr_p_t_r=no], [apr_p_t_r=no])
111
if test $apr_p_t_r = yes; then
119
dnl APR_PTHREADS_CHECK()
121
dnl Try to find a way to enable POSIX threads. Sets the
122
dnl pthreads_working variable to "yes" on success.
124
AC_DEFUN(APR_PTHREADS_CHECK,[
126
AC_CACHE_CHECK([for CFLAGS needed for pthreads], [apr_cv_pthreads_cflags],
127
[apr_ptc_cflags=$CFLAGS
128
for flag in none -kthread -pthread -pthreads -mt -mthreads -Kthread -threads; do
129
CFLAGS=$apr_ptc_cflags
130
test "x$flag" != "xnone" && CFLAGS="$CFLAGS $flag"
131
APR_PTHREADS_TRY_RUN([
132
apr_cv_pthreads_cflags="$flag"
136
CFLAGS=$apr_ptc_cflags
139
if test -n "$apr_cv_pthreads_cflags"; then
141
if test "x$apr_cv_pthreads_cflags" != "xnone"; then
142
APR_ADDTO(CFLAGS,[$apr_cv_pthreads_cflags])
146
# The CFLAGS may or may not be sufficient to ensure that libapr
147
# depends on the pthreads library: some versions of libtool
148
# drop -pthread when passed on the link line; some versions of
149
# gcc ignore -pthread when linking a shared object. So always
150
# try and add the relevant library to LIBS too.
152
AC_CACHE_CHECK([for LIBS needed for pthreads], [apr_cv_pthreads_lib], [
154
for lib in -lpthread -lpthreads -lc_r; do
155
LIBS="$apr_ptc_libs $lib"
156
APR_PTHREADS_TRY_RUN([
157
apr_cv_pthreads_lib=$lib
164
if test -n "$apr_cv_pthreads_lib"; then
166
APR_ADDTO(LIBS,[$apr_cv_pthreads_lib])
169
if test "$pthreads_working" = "yes"; then
170
threads_result="POSIX Threads found"
172
threads_result="POSIX Threads not found"
177
dnl APR_PTHREADS_CHECK_SAVE
178
dnl APR_PTHREADS_CHECK_RESTORE
180
dnl Save the global environment variables that might be modified during
181
dnl the checks for threading support so that they can restored if the
182
dnl result is not what the caller wanted.
184
AC_DEFUN(APR_PTHREADS_CHECK_SAVE, [
185
apr_pthsv_CFLAGS="$CFLAGS"
186
apr_pthsv_LIBS="$LIBS"
189
AC_DEFUN(APR_PTHREADS_CHECK_RESTORE, [
190
CFLAGS="$apr_pthsv_CFLAGS"
191
LIBS="$apr_pthsv_LIBS"
195
dnl APR_CHECK_SIGWAIT_ONE_ARG
197
AC_DEFUN(APR_CHECK_SIGWAIT_ONE_ARG,[
198
AC_CACHE_CHECK(whether sigwait takes one argument,ac_cv_sigwait_one_arg,[
200
#if defined(__NETBSD__) || defined(DARWIN)
201
/* When using the unproven-pthreads package, we need to pull in this
202
* header to get a prototype for sigwait(). Else things will fail later
203
* on. XXX Should probably be fixed in the unproven-pthreads package.
204
* Darwin is declaring sigwait() in the wrong place as well.
214
ac_cv_sigwait_one_arg=yes
216
ac_cv_sigwait_one_arg=no
218
if test "$ac_cv_sigwait_one_arg" = "yes"; then
219
AC_DEFINE(SIGWAIT_TAKES_ONE_ARG,1,[ ])
223
dnl Check for recursive mutex support (per SUSv3).
224
AC_DEFUN([APR_CHECK_PTHREAD_RECURSIVE_MUTEX], [
225
AC_CACHE_CHECK([for recursive mutex support], [apr_cv_mutex_recursive],
226
[AC_TRY_RUN([#include <sys/types.h>
231
pthread_mutexattr_t attr;
234
exit (pthread_mutexattr_init(&attr)
235
|| pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)
236
|| pthread_mutex_init(&m, &attr));
237
}], [apr_cv_mutex_recursive=yes], [apr_cv_mutex_recursive=no],
238
[apr_cv_mutex_recursive=no])])
240
if test "$apr_cv_mutex_recursive" = "yes"; then
241
AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE], 1,
242
[Define if recursive pthread mutexes are available])
246
dnl Check for robust process-shared mutex support
247
AC_DEFUN([APR_CHECK_PTHREAD_ROBUST_SHARED_MUTEX], [
248
AC_CACHE_CHECK([for robust cross-process mutex support],
249
[apr_cv_mutex_robust_shared],
251
#include <sys/types.h>
255
int main(int argc, char **argv)
257
pthread_mutex_t mutex;
258
pthread_mutexattr_t attr;
260
if (pthread_mutexattr_init(&attr))
262
if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))
264
if (pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP))
266
if (pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT))
268
if (pthread_mutex_init(&mutex, &attr))
270
if (pthread_mutexattr_destroy(&attr))
272
if (pthread_mutex_destroy(&mutex))
276
}], [apr_cv_mutex_robust_shared=yes], [apr_cv_mutex_robust_shared=no])])
278
if test "$apr_cv_mutex_robust_shared" = "yes"; then
279
AC_DEFINE([HAVE_PTHREAD_MUTEX_ROBUST], 1,
280
[Define if cross-process robust mutexes are available])