upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / build / apr_threads.m4
1 dnl -----------------------------------------------------------------
2 dnl apr_threads.m4: APR's autoconf macros for testing thread support
3 dnl
4
5 dnl
6 dnl APR_CHECK_PTHREADS_H([ ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
7 dnl
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.
12 dnl
13 AC_DEFUN(APR_CHECK_PTHREADS_H, [
14   if test "$GCC" = "yes"; then
15     SAVE_FL="$CPPFLAGS"
16     CPPFLAGS="$CPPFLAGS -w"
17     AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
18     CPPFLAGS="$SAVE_FL"
19   else
20     AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
21   fi
22 ])dnl
23
24
25 dnl
26 dnl APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS
27 dnl
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,[
30 AC_TRY_COMPILE([
31 #include <pthread.h>
32 ],[
33 pthread_key_t key;
34 void *tmp;
35 pthread_getspecific(key,&tmp);
36 ],[
37     ac_cv_pthread_getspecific_two_args=yes
38 ],[
39     ac_cv_pthread_getspecific_two_args=no
40 ])
41 ])
42
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])
45 fi
46 ])dnl
47
48
49 dnl
50 dnl APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG
51 dnl
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,[
54 AC_TRY_COMPILE([
55 #include <pthread.h>
56 ],[
57 pthread_attr_t *attr;
58 pthread_attr_getdetachstate(attr);
59 ],[
60     ac_cv_pthread_attr_getdetachstate_one_arg=yes
61 ],[
62     ac_cv_pthread_attr_getdetachstate_one_arg=no
63 ])
64 ])
65
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])
68 fi
69 ])dnl
70
71
72 dnl
73 dnl APR_PTHREADS_TRY_RUN(actions-if-success)
74 dnl
75 dnl Try running a program which uses pthreads, executing the
76 dnl actions-if-success commands on success.
77 dnl
78 AC_DEFUN(APR_PTHREADS_TRY_RUN, [
79 AC_TRY_RUN( [
80 #include <pthread.h>
81 #include <stddef.h>
82
83 void *thread_routine(void *data) {
84     return data;
85 }
86
87 int main() {
88     pthread_t thd;
89     pthread_mutexattr_t mattr;
90     pthread_once_t once_init = PTHREAD_ONCE_INIT;
91     int data = 1;
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])
95
96 if test $apr_p_t_r = yes; then
97   $1
98 fi
99
100 ])dnl
101
102
103 dnl
104 dnl APR_PTHREADS_CHECK()
105 dnl
106 dnl Try to find a way to enable POSIX threads.  Sets the 
107 dnl pthreads_working variable to "yes" on success.
108 dnl
109 AC_DEFUN(APR_PTHREADS_CHECK,[
110
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"
118       break
119     ])
120  done
121  CFLAGS=$apr_ptc_cflags
122 ])
123
124 if test -n "$apr_cv_pthreads_cflags"; then
125    pthreads_working=yes
126    if test "x$apr_cv_pthreads_cflags" != "xnone"; then
127      APR_ADDTO(CFLAGS,[$apr_cv_pthreads_cflags])
128    fi
129 fi
130
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.
136
137 AC_CACHE_CHECK([for LIBS needed for pthreads], [apr_cv_pthreads_lib], [
138   apr_ptc_libs=$LIBS
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
143       break
144     ])
145   done
146   LIBS=$apr_ptc_libs
147 ])
148
149 if test -n "$apr_cv_pthreads_lib"; then
150    pthreads_working=yes
151    APR_ADDTO(LIBS,[$apr_cv_pthreads_lib])
152 fi
153
154 if test "$pthreads_working" = "yes"; then
155   threads_result="POSIX Threads found"
156 else
157   threads_result="POSIX Threads not found"
158 fi
159 ])dnl
160
161 dnl
162 dnl APR_PTHREADS_CHECK_SAVE
163 dnl APR_PTHREADS_CHECK_RESTORE
164 dnl
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.
168 dnl
169 AC_DEFUN(APR_PTHREADS_CHECK_SAVE, [
170   apr_pthsv_CFLAGS="$CFLAGS"
171   apr_pthsv_LIBS="$LIBS"
172 ])dnl
173
174 AC_DEFUN(APR_PTHREADS_CHECK_RESTORE, [
175   CFLAGS="$apr_pthsv_CFLAGS"
176   LIBS="$apr_pthsv_LIBS"
177 ])dnl
178
179 dnl
180 dnl APR_CHECK_SIGWAIT_ONE_ARG
181 dnl
182 AC_DEFUN(APR_CHECK_SIGWAIT_ONE_ARG,[
183   AC_CACHE_CHECK(whether sigwait takes one argument,ac_cv_sigwait_one_arg,[
184   AC_TRY_COMPILE([
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.
190      */
191 #include <pthread.h>
192 #endif
193 #include <signal.h>
194 ],[
195   sigset_t set;
196  
197   sigwait(&set);
198 ],[
199   ac_cv_sigwait_one_arg=yes
200 ],[
201   ac_cv_sigwait_one_arg=no
202 ])])
203   if test "$ac_cv_sigwait_one_arg" = "yes"; then
204     AC_DEFINE(SIGWAIT_TAKES_ONE_ARG,1,[ ])
205   fi
206 ])
207
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>
212 #include <pthread.h>
213 #include <stdlib.h>
214
215 int main() {
216     pthread_mutexattr_t attr;
217     pthread_mutex_t m;
218
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])])
224
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])
228 fi
229 ])
230
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],
235 [AC_TRY_RUN([
236 #include <sys/types.h>
237 #include <pthread.h>
238 #include <stdlib.h>
239
240 int main(int argc, char **argv)
241 {
242     pthread_mutex_t mutex;
243     pthread_mutexattr_t attr;
244
245     if (pthread_mutexattr_init(&attr))
246         exit(1);
247     if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))
248         exit(2);
249     if (pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP))
250         exit(3);
251     if (pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT))
252         exit(4);
253     if (pthread_mutex_init(&mutex, &attr))
254         exit(5);
255     if (pthread_mutexattr_destroy(&attr))
256         exit(6);
257     if (pthread_mutex_destroy(&mutex))
258         exit(7);
259
260     exit(0);
261 }], [apr_cv_mutex_robust_shared=yes], [apr_cv_mutex_robust_shared=no])])
262
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])
266 fi
267 ])