~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/build/apr_threads.m4

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl -------------------------------------------------------- -*- autoconf -*-
 
2
dnl Copyright 2000-2005 The Apache Software Foundation
 
3
dnl
 
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
 
7
dnl
 
8
dnl     http://www.apache.org/licenses/LICENSE-2.0
 
9
dnl
 
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.
 
15
 
 
16
dnl -----------------------------------------------------------------
 
17
dnl apr_threads.m4: APR's autoconf macros for testing thread support
 
18
dnl
 
19
 
 
20
dnl
 
21
dnl APR_CHECK_PTHREADS_H([ ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
 
22
dnl
 
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.
 
27
dnl
 
28
AC_DEFUN(APR_CHECK_PTHREADS_H, [
 
29
  if test "$GCC" = "yes"; then
 
30
    SAVE_FL="$CPPFLAGS"
 
31
    CPPFLAGS="$CPPFLAGS -w"
 
32
    AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
 
33
    CPPFLAGS="$SAVE_FL"
 
34
  else
 
35
    AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
 
36
  fi
 
37
])dnl
 
38
 
 
39
 
 
40
dnl
 
41
dnl APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS
 
42
dnl
 
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,[
 
45
AC_TRY_COMPILE([
 
46
#include <pthread.h>
 
47
],[
 
48
pthread_key_t key;
 
49
void *tmp;
 
50
pthread_getspecific(key,&tmp);
 
51
],[
 
52
    ac_cv_pthread_getspecific_two_args=yes
 
53
],[
 
54
    ac_cv_pthread_getspecific_two_args=no
 
55
])
 
56
])
 
57
 
 
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])
 
60
fi
 
61
])dnl
 
62
 
 
63
 
 
64
dnl
 
65
dnl APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG
 
66
dnl
 
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,[
 
69
AC_TRY_COMPILE([
 
70
#include <pthread.h>
 
71
],[
 
72
pthread_attr_t *attr;
 
73
pthread_attr_getdetachstate(attr);
 
74
],[
 
75
    ac_cv_pthread_attr_getdetachstate_one_arg=yes
 
76
],[
 
77
    ac_cv_pthread_attr_getdetachstate_one_arg=no
 
78
])
 
79
])
 
80
 
 
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])
 
83
fi
 
84
])dnl
 
85
 
 
86
 
 
87
dnl
 
88
dnl APR_PTHREADS_TRY_RUN(actions-if-success)
 
89
dnl
 
90
dnl Try running a program which uses pthreads, executing the
 
91
dnl actions-if-success commands on success.
 
92
dnl
 
93
AC_DEFUN(APR_PTHREADS_TRY_RUN, [
 
94
AC_TRY_RUN( [
 
95
#include <pthread.h>
 
96
#include <stddef.h>
 
97
 
 
98
void *thread_routine(void *data) {
 
99
    return data;
 
100
}
 
101
 
 
102
int main() {
 
103
    pthread_t thd;
 
104
    pthread_mutexattr_t mattr;
 
105
    pthread_once_t once_init = PTHREAD_ONCE_INIT;
 
106
    int data = 1;
 
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])
 
110
 
 
111
if test $apr_p_t_r = yes; then
 
112
  $1
 
113
fi
 
114
 
 
115
])dnl
 
116
 
 
117
 
 
118
dnl
 
119
dnl APR_PTHREADS_CHECK()
 
120
dnl
 
121
dnl Try to find a way to enable POSIX threads.  Sets the 
 
122
dnl pthreads_working variable to "yes" on success.
 
123
dnl
 
124
AC_DEFUN(APR_PTHREADS_CHECK,[
 
125
 
 
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"
 
133
      break
 
134
    ])
 
135
 done
 
136
 CFLAGS=$apr_ptc_cflags
 
137
])
 
138
 
 
139
if test -n "$apr_cv_pthreads_cflags"; then
 
140
   pthreads_working=yes
 
141
   if test "x$apr_cv_pthreads_cflags" != "xnone"; then
 
142
     APR_ADDTO(CFLAGS,[$apr_cv_pthreads_cflags])
 
143
   fi
 
144
fi
 
145
 
 
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.
 
151
 
 
152
AC_CACHE_CHECK([for LIBS needed for pthreads], [apr_cv_pthreads_lib], [
 
153
  apr_ptc_libs=$LIBS
 
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
 
158
      break
 
159
    ])
 
160
  done
 
161
  LIBS=$apr_ptc_libs
 
162
])
 
163
 
 
164
if test -n "$apr_cv_pthreads_lib"; then
 
165
   pthreads_working=yes
 
166
   APR_ADDTO(LIBS,[$apr_cv_pthreads_lib])
 
167
fi
 
168
 
 
169
if test "$pthreads_working" = "yes"; then
 
170
  threads_result="POSIX Threads found"
 
171
else
 
172
  threads_result="POSIX Threads not found"
 
173
fi
 
174
])dnl
 
175
 
 
176
dnl
 
177
dnl APR_PTHREADS_CHECK_SAVE
 
178
dnl APR_PTHREADS_CHECK_RESTORE
 
179
dnl
 
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.
 
183
dnl
 
184
AC_DEFUN(APR_PTHREADS_CHECK_SAVE, [
 
185
  apr_pthsv_CFLAGS="$CFLAGS"
 
186
  apr_pthsv_LIBS="$LIBS"
 
187
])dnl
 
188
 
 
189
AC_DEFUN(APR_PTHREADS_CHECK_RESTORE, [
 
190
  CFLAGS="$apr_pthsv_CFLAGS"
 
191
  LIBS="$apr_pthsv_LIBS"
 
192
])dnl
 
193
 
 
194
dnl
 
195
dnl APR_CHECK_SIGWAIT_ONE_ARG
 
196
dnl
 
197
AC_DEFUN(APR_CHECK_SIGWAIT_ONE_ARG,[
 
198
  AC_CACHE_CHECK(whether sigwait takes one argument,ac_cv_sigwait_one_arg,[
 
199
  AC_TRY_COMPILE([
 
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.
 
205
     */
 
206
#include <pthread.h>
 
207
#endif
 
208
#include <signal.h>
 
209
],[
 
210
  sigset_t set;
 
211
 
 
212
  sigwait(&set);
 
213
],[
 
214
  ac_cv_sigwait_one_arg=yes
 
215
],[
 
216
  ac_cv_sigwait_one_arg=no
 
217
])])
 
218
  if test "$ac_cv_sigwait_one_arg" = "yes"; then
 
219
    AC_DEFINE(SIGWAIT_TAKES_ONE_ARG,1,[ ])
 
220
  fi
 
221
])
 
222
 
 
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>
 
227
#include <pthread.h>
 
228
#include <stdlib.h>
 
229
 
 
230
int main() {
 
231
    pthread_mutexattr_t attr;
 
232
    pthread_mutex_t m;
 
233
 
 
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])])
 
239
 
 
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])
 
243
fi
 
244
])
 
245
 
 
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],
 
250
[AC_TRY_RUN([
 
251
#include <sys/types.h>
 
252
#include <pthread.h>
 
253
#include <stdlib.h>
 
254
 
 
255
int main(int argc, char **argv)
 
256
{
 
257
    pthread_mutex_t mutex;
 
258
    pthread_mutexattr_t attr;
 
259
 
 
260
    if (pthread_mutexattr_init(&attr))
 
261
        exit(1);
 
262
    if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))
 
263
        exit(2);
 
264
    if (pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP))
 
265
        exit(3);
 
266
    if (pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT))
 
267
        exit(4);
 
268
    if (pthread_mutex_init(&mutex, &attr))
 
269
        exit(5);
 
270
    if (pthread_mutexattr_destroy(&attr))
 
271
        exit(6);
 
272
    if (pthread_mutex_destroy(&mutex))
 
273
        exit(7);
 
274
 
 
275
    exit(0);
 
276
}], [apr_cv_mutex_robust_shared=yes], [apr_cv_mutex_robust_shared=no])])
 
277
 
 
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])
 
281
fi
 
282
])