Fixed dtrace building.
[m6w6/libmemcached] / m4 / pandora_pthread.m4
1 dnl -*- mode: m4; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 dnl vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 dnl
4 dnl pandora-build: A pedantic build system
5 dnl Copyright (C) 2009 Sun Microsystems, Inc.
6 dnl This file is free software; Sun Microsystems
7 dnl gives unlimited permission to copy and/or distribute it,
8 dnl with or without modifications, as long as this notice is preserved.
9 dnl
10 dnl From Monty Taylor
11
12
13 dnl --------------------------------------------------------------------
14 dnl Check for libpthread
15 dnl --------------------------------------------------------------------
16
17 AC_DEFUN([PANDORA_PTHREAD_YIELD],[
18 AC_REQUIRE([ACX_PTHREAD])
19
20 save_CFLAGS="${CFLAGS}"
21 save_CXXFLAGS="${CXXFLAGS}"
22 CFLAGS="${PTHREAD_CFLAGS} ${CFLAGS}"
23 CXXFLAGS="${PTHREAD_CFLAGS} ${CXXFLAGS}"
24 dnl Some OSes like Mac OS X have that as a replacement for pthread_yield()
25 AC_CHECK_FUNCS(pthread_yield_np)
26 AC_CACHE_CHECK([if pthread_yield takes zero arguments],
27 [pandora_cv_pthread_yield_zero_arg],
28 [AC_LINK_IFELSE([
29 AC_LANG_PROGRAM([[
30 #include <pthread.h>
31 ]],[[
32 pthread_yield();
33 ]])],
34 [pandora_cv_pthread_yield_zero_arg=yes],
35 [pandora_cv_pthread_yield_zero_arg=no])])
36 AS_IF([test "$pandora_cv_pthread_yield_zero_arg" = "yes"],[
37 AC_DEFINE([HAVE_PTHREAD_YIELD_ZERO_ARG], [1],
38 [pthread_yield that doesn't take any arguments])
39 ])
40
41 AC_CACHE_CHECK([if pthread_yield takes one argument],
42 [pandora_cv_pthread_yield_one_arg],
43 [AC_LINK_IFELSE([
44 AC_LANG_PROGRAM([[
45 #include <pthread.h>
46 ]],[[
47 pthread_yield(0);
48 ]])],
49 [pandora_cv_pthread_yield_one_arg=yes],
50 [pandora_cv_pthread_yield_one_arg=no])])
51 AS_IF([test "$pandora_cv_pthread_yield_one_arg" = "yes"],[
52 AC_DEFINE([HAVE_PTHREAD_YIELD_ONE_ARG], [1],
53 [pthread_yield function with one argument])
54 ])
55
56 AC_CHECK_FUNCS(pthread_attr_getstacksize pthread_attr_setprio \
57 pthread_attr_setschedparam \
58 pthread_attr_setstacksize pthread_condattr_create pthread_getsequence_np \
59 pthread_key_delete pthread_rwlock_rdlock pthread_setprio \
60 pthread_setprio_np pthread_setschedparam pthread_sigmask \
61 pthread_attr_create rwlock_init
62 )
63
64
65
66 # Check definition of pthread_getspecific
67 AC_CACHE_CHECK([args to pthread_getspecific], [pandora_cv_getspecific_args],
68 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
69 #if !defined(_REENTRANT)
70 #define _REENTRANT
71 #endif
72 #ifndef _POSIX_PTHREAD_SEMANTICS
73 #define _POSIX_PTHREAD_SEMANTICS
74 #endif
75 #include <pthread.h>
76 ]], [[
77 void *pthread_getspecific(pthread_key_t key);
78 pthread_getspecific((pthread_key_t) NULL);
79 ]])],
80 [pandora_cv_getspecific_args=POSIX],
81 [pandora_cv_getspecific_args=other])])
82 if test "$pandora_cv_getspecific_args" = "other"
83 then
84 AC_DEFINE([HAVE_NONPOSIX_PTHREAD_GETSPECIFIC], [1],
85 [For some non posix threads])
86 fi
87
88 # Check definition of pthread_mutex_init
89 AC_CACHE_CHECK([args to pthread_mutex_init], [pandora_cv_mutex_init_args],
90 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
91 #ifndef _REENTRANT
92 #define _REENTRANT
93 #endif
94 #ifndef _POSIX_PTHREAD_SEMANTICS
95 #define _POSIX_PTHREAD_SEMANTICS
96 #endif
97 #include <pthread.h> ]], [[
98 pthread_mutexattr_t attr;
99 pthread_mutex_t mp;
100 pthread_mutex_init(&mp,&attr); ]])],
101 [pandora_cv_mutex_init_args=POSIX],
102 [pandora_cv_mutex_init_args=other])])
103 if test "$pandora_cv_mutex_init_args" = "other"
104 then
105 AC_DEFINE([HAVE_NONPOSIX_PTHREAD_MUTEX_INIT], [1],
106 [For some non posix threads])
107 fi
108 #---END:
109
110 #---START: Used in for client configure
111 # Check definition of readdir_r
112 AC_CACHE_CHECK([args to readdir_r], [pandora_cv_readdir_r],
113 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
114 #ifndef _REENTRANT
115 #define _REENTRANT
116 #endif
117 #ifndef _POSIX_PTHREAD_SEMANTICS
118 #define _POSIX_PTHREAD_SEMANTICS
119 #endif
120 #include <pthread.h>
121 #include <dirent.h>]], [[ int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
122 readdir_r((DIR *) NULL, (struct dirent *) NULL, (struct dirent **) NULL); ]])],
123 [pandora_cv_readdir_r=POSIX],
124 [pandora_cv_readdir_r=other])])
125 if test "$pandora_cv_readdir_r" = "POSIX"
126 then
127 AC_DEFINE([HAVE_READDIR_R], [1], [POSIX readdir_r])
128 fi
129
130 # Check definition of posix sigwait()
131 AC_CACHE_CHECK([style of sigwait], [pandora_cv_sigwait],
132 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
133 #ifndef _REENTRANT
134 #define _REENTRANT
135 #endif
136 #ifndef _POSIX_PTHREAD_SEMANTICS
137 #define _POSIX_PTHREAD_SEMANTICS
138 #endif
139 #include <pthread.h>
140 #include <signal.h>
141 ]], [[
142 #ifndef _AIX
143 sigset_t set;
144 int sig;
145 sigwait(&set,&sig);
146 #endif
147 ]])],
148 [pandora_cv_sigwait=POSIX],
149 [pandora_cv_sigwait=other])])
150 if test "$pandora_cv_sigwait" = "POSIX"
151 then
152 AC_DEFINE([HAVE_SIGWAIT], [1], [POSIX sigwait])
153 fi
154
155 if test "$pandora_cv_sigwait" != "POSIX"
156 then
157 unset pandora_cv_sigwait
158 # Check definition of posix sigwait()
159 AC_CACHE_CHECK([style of sigwait], [pandora_cv_sigwait],
160 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
161 #ifndef _REENTRANT
162 #define _REENTRANT
163 #endif
164 #ifndef _POSIX_PTHREAD_SEMANTICS
165 #define _POSIX_PTHREAD_SEMANTICS
166 #endif
167 #include <pthread.h>
168 #include <signal.h>
169 ]], [[
170 sigset_t set;
171 int sig;
172 sigwait(&set);
173 ]])],
174 [pandora_cv_sigwait=NONPOSIX],
175 [pandora_cv_sigwait=other])])
176 if test "$pandora_cv_sigwait" = "NONPOSIX"
177 then
178 AC_DEFINE([HAVE_NONPOSIX_SIGWAIT], [1], [sigwait with one argument])
179 fi
180 fi
181 #---END:
182
183 # Check if pthread_attr_setscope() exists
184 AC_CACHE_CHECK([for pthread_attr_setscope], [pandora_cv_pthread_attr_setscope],
185 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
186 #ifndef _REENTRANT
187 #define _REENTRANT
188 #endif
189 #ifndef _POSIX_PTHREAD_SEMANTICS
190 #define _POSIX_PTHREAD_SEMANTICS
191 #endif
192 #include <pthread.h>
193 ]], [[
194 pthread_attr_t thr_attr;
195 pthread_attr_setscope(&thr_attr,0);
196 ]])],
197 [pandora_cv_pthread_attr_setscope=yes],
198 [pandora_cv_pthread_attr_setscope=no])])
199 if test "$pandora_cv_pthread_attr_setscope" = "yes"
200 then
201 AC_DEFINE([HAVE_PTHREAD_ATTR_SETSCOPE], [1], [pthread_attr_setscope])
202 fi
203
204
205 AC_CACHE_CHECK([if pthread_yield takes zero arguments], ac_cv_pthread_yield_zero_arg,
206 [AC_TRY_LINK([#define _GNU_SOURCE
207 #include <pthread.h>
208 #ifdef __cplusplus
209 extern "C"
210 #endif
211 ],
212 [
213 pthread_yield();
214 ], ac_cv_pthread_yield_zero_arg=yes, ac_cv_pthread_yield_zero_arg=yeso)])
215 if test "$ac_cv_pthread_yield_zero_arg" = "yes"
216 then
217 AC_DEFINE([HAVE_PTHREAD_YIELD_ZERO_ARG], [1],
218 [pthread_yield that doesn't take any arguments])
219 fi
220 AC_CACHE_CHECK([if pthread_yield takes 1 argument], ac_cv_pthread_yield_one_arg,
221 [AC_TRY_LINK([#define _GNU_SOURCE
222 #include <pthread.h>
223 #ifdef __cplusplus
224 extern "C"
225 #endif
226 ],
227 [
228 pthread_yield(0);
229 ], ac_cv_pthread_yield_one_arg=yes, ac_cv_pthread_yield_one_arg=no)])
230 if test "$ac_cv_pthread_yield_one_arg" = "yes"
231 then
232 AC_DEFINE([HAVE_PTHREAD_YIELD_ONE_ARG], [1],
233 [pthread_yield function with one argument])
234 fi
235
236 CFLAGS="${save_CFLAGS}"
237 CXXFLAGS="${save_CXXFLAGS}"
238 ])
239
240
241 AC_DEFUN([_PANDORA_SEARCH_PTHREAD],[
242 AC_REQUIRE([ACX_PTHREAD])
243 LIBS="${PTHREAD_LIBS} ${LIBS}"
244 AM_CFLAGS="${PTHREAD_CFLAGS} ${AM_CFLAGS}"
245 AM_CXXFLAGS="${PTHREAD_CFLAGS} ${AM_CXXFLAGS}"
246 PANDORA_PTHREAD_YIELD
247 ])
248
249
250 AC_DEFUN([PANDORA_HAVE_PTHREAD],[
251 AC_REQUIRE([_PANDORA_SEARCH_PTHREAD])
252 ])
253
254 AC_DEFUN([PANDORA_REQUIRE_PTHREAD],[
255 AC_REQUIRE([PANDORA_HAVE_PTHREAD])
256 AS_IF([test "x$acx_pthread_ok" != "xyes"],[
257 AC_MSG_ERROR(could not find libpthread)])
258 ])