3 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN_ONCE([gl_PTHREAD_H_PART1],
10 dnl Ensure to expand the default settings once only, before all statements
11 dnl that occur in other macros.
12 AC_REQUIRE([gl_PTHREAD_H_DEFAULTS])
14 AC_REQUIRE([AC_CANONICAL_HOST])
15 AC_REQUIRE([gl_PTHREADLIB])
17 gl_CHECK_NEXT_HEADERS([pthread.h])
18 if test $ac_cv_header_pthread_h = yes; then
20 dnl On mingw, if --enable-threads=windows or gl_AVOID_WINPTHREAD is used,
21 dnl ignore the <pthread.h> from the mingw-w64 winpthreads library.
22 m4_ifdef([gl_][THREADLIB], [
23 AC_REQUIRE([gl_][THREADLIB])
24 if { case "$host_os" in mingw* | windows*) true;; *) false;; esac; } \
25 && test $gl_threads_api = windows; then
32 AC_SUBST([HAVE_PTHREAD_H])
34 AC_CHECK_TYPES([pthread_t, pthread_spinlock_t], [], [],
39 if test $ac_cv_type_pthread_t != yes; then
42 if test $ac_cv_type_pthread_spinlock_t != yes; then
43 HAVE_PTHREAD_SPINLOCK_T=0
47 AC_DEFUN([gl_PTHREAD_H],
49 AC_REQUIRE([gl_PTHREAD_H_PART1])
51 dnl Set HAVE_PTHREAD_SPIN_INIT, REPLACE_PTHREAD_SPIN_INIT.
54 dnl Constants may be defined as C preprocessor macros or as enum items.
56 AC_CACHE_CHECK([for PTHREAD_CREATE_DETACHED],
57 [gl_cv_const_PTHREAD_CREATE_DETACHED],
60 [[#include <pthread.h>
61 int x = PTHREAD_CREATE_DETACHED;
64 [gl_cv_const_PTHREAD_CREATE_DETACHED=yes],
65 [gl_cv_const_PTHREAD_CREATE_DETACHED=no])
67 if test $gl_cv_const_PTHREAD_CREATE_DETACHED != yes; then
68 HAVE_PTHREAD_CREATE_DETACHED=0
71 AC_CACHE_CHECK([for PTHREAD_MUTEX_RECURSIVE],
72 [gl_cv_const_PTHREAD_MUTEX_RECURSIVE],
75 [[#include <pthread.h>
76 int x = PTHREAD_MUTEX_RECURSIVE;
79 [gl_cv_const_PTHREAD_MUTEX_RECURSIVE=yes],
80 [gl_cv_const_PTHREAD_MUTEX_RECURSIVE=no])
82 if test $gl_cv_const_PTHREAD_MUTEX_RECURSIVE != yes; then
83 HAVE_PTHREAD_MUTEX_RECURSIVE=0
86 AC_CACHE_CHECK([for PTHREAD_MUTEX_ROBUST],
87 [gl_cv_const_PTHREAD_MUTEX_ROBUST],
90 [[#include <pthread.h>
91 int x = PTHREAD_MUTEX_ROBUST;
94 [gl_cv_const_PTHREAD_MUTEX_ROBUST=yes],
95 [gl_cv_const_PTHREAD_MUTEX_ROBUST=no])
97 if test $gl_cv_const_PTHREAD_MUTEX_ROBUST != yes; then
98 HAVE_PTHREAD_MUTEX_ROBUST=0
101 AC_CACHE_CHECK([for PTHREAD_PROCESS_SHARED],
102 [gl_cv_const_PTHREAD_PROCESS_SHARED],
105 [[#include <pthread.h>
106 int x = PTHREAD_PROCESS_SHARED;
109 [gl_cv_const_PTHREAD_PROCESS_SHARED=yes],
110 [gl_cv_const_PTHREAD_PROCESS_SHARED=no])
112 if test $gl_cv_const_PTHREAD_PROCESS_SHARED != yes; then
113 HAVE_PTHREAD_PROCESS_SHARED=0
116 dnl Check for declarations of anything we want to poison if the
117 dnl corresponding gnulib module is not in use, if it is not common
118 dnl enough to be declared everywhere.
119 gl_WARN_ON_USE_PREPARE([[#include <pthread.h>
121 pthread_create pthread_attr_init pthread_attr_getdetachstate
122 pthread_attr_setdetachstate pthread_attr_destroy pthread_self pthread_equal
123 pthread_detach pthread_join pthread_exit
125 pthread_mutex_init pthread_mutexattr_init pthread_mutexattr_gettype
126 pthread_mutexattr_settype pthread_mutexattr_getrobust
127 pthread_mutexattr_setrobust pthread_mutexattr_destroy pthread_mutex_lock
128 pthread_mutex_trylock pthread_mutex_timedlock pthread_mutex_unlock
129 pthread_mutex_destroy
130 pthread_rwlock_init pthread_rwlockattr_init pthread_rwlockattr_destroy
131 pthread_rwlock_rdlock pthread_rwlock_wrlock pthread_rwlock_tryrdlock
132 pthread_rwlock_trywrlock pthread_rwlock_timedrdlock
133 pthread_rwlock_timedwrlock pthread_rwlock_unlock pthread_rwlock_destroy
134 pthread_cond_init pthread_condattr_init pthread_condattr_destroy
135 pthread_cond_wait pthread_cond_timedwait pthread_cond_signal
136 pthread_cond_broadcast pthread_cond_destroy
137 pthread_key_create pthread_setspecific pthread_getspecific
139 pthread_spin_init pthread_spin_lock pthread_spin_trylock pthread_spin_unlock
140 pthread_spin_destroy])
142 AC_REQUIRE([AC_C_RESTRICT])
144 dnl For backward compatibility with gnulib versions <= 2019-07.
145 LIB_PTHREAD="$LIBPMULTITHREAD"
146 AC_SUBST([LIB_PTHREAD])
149 # gl_PTHREAD_MODULE_INDICATOR([modulename])
150 # sets the shell variable that indicates the presence of the given module
151 # to a C preprocessor expression that will evaluate to 1.
152 # This macro invocation must not occur in macros that are AC_REQUIREd.
153 AC_DEFUN([gl_PTHREAD_MODULE_INDICATOR],
155 dnl Ensure to expand the default settings once only.
156 gl_PTHREAD_H_REQUIRE_DEFAULTS
157 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
158 dnl Define it also as a C macro, for the benefit of the unit tests.
159 gl_MODULE_INDICATOR_FOR_TESTS([$1])
162 # Initializes the default values for AC_SUBSTed shell variables.
163 # This macro must not be AC_REQUIREd. It must only be invoked, and only
164 # outside of macros or in macros that are not AC_REQUIREd.
165 AC_DEFUN([gl_PTHREAD_H_REQUIRE_DEFAULTS],
167 m4_defun(GL_MODULE_INDICATOR_PREFIX[_PTHREAD_H_MODULE_INDICATOR_DEFAULTS], [
168 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTHREAD_THREAD])
169 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTHREAD_ONCE])
170 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTHREAD_MUTEX])
171 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTHREAD_RWLOCK])
172 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTHREAD_COND])
173 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTHREAD_TSS])
174 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTHREAD_SPIN])
175 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTHREAD_MUTEX_TIMEDLOCK])
177 m4_require(GL_MODULE_INDICATOR_PREFIX[_PTHREAD_H_MODULE_INDICATOR_DEFAULTS])
178 AC_REQUIRE([gl_PTHREAD_H_DEFAULTS])
181 AC_DEFUN([gl_PTHREAD_H_DEFAULTS],
183 dnl Assume proper GNU behavior unless another module says otherwise.
184 HAVE_PTHREAD_T=1; AC_SUBST([HAVE_PTHREAD_T])
185 HAVE_PTHREAD_SPINLOCK_T=1; AC_SUBST([HAVE_PTHREAD_SPINLOCK_T])
186 HAVE_PTHREAD_CREATE_DETACHED=1; AC_SUBST([HAVE_PTHREAD_CREATE_DETACHED])
187 HAVE_PTHREAD_MUTEX_RECURSIVE=1; AC_SUBST([HAVE_PTHREAD_MUTEX_RECURSIVE])
188 HAVE_PTHREAD_MUTEX_ROBUST=1; AC_SUBST([HAVE_PTHREAD_MUTEX_ROBUST])
189 HAVE_PTHREAD_PROCESS_SHARED=1; AC_SUBST([HAVE_PTHREAD_PROCESS_SHARED])
190 HAVE_PTHREAD_CREATE=1; AC_SUBST([HAVE_PTHREAD_CREATE])
191 HAVE_PTHREAD_ATTR_INIT=1; AC_SUBST([HAVE_PTHREAD_ATTR_INIT])
192 HAVE_PTHREAD_ATTR_GETDETACHSTATE=1; AC_SUBST([HAVE_PTHREAD_ATTR_GETDETACHSTATE])
193 HAVE_PTHREAD_ATTR_SETDETACHSTATE=1; AC_SUBST([HAVE_PTHREAD_ATTR_SETDETACHSTATE])
194 HAVE_PTHREAD_ATTR_DESTROY=1; AC_SUBST([HAVE_PTHREAD_ATTR_DESTROY])
195 HAVE_PTHREAD_SELF=1; AC_SUBST([HAVE_PTHREAD_SELF])
196 HAVE_PTHREAD_EQUAL=1; AC_SUBST([HAVE_PTHREAD_EQUAL])
197 HAVE_PTHREAD_DETACH=1; AC_SUBST([HAVE_PTHREAD_DETACH])
198 HAVE_PTHREAD_JOIN=1; AC_SUBST([HAVE_PTHREAD_JOIN])
199 HAVE_PTHREAD_EXIT=1; AC_SUBST([HAVE_PTHREAD_EXIT])
200 HAVE_PTHREAD_ONCE=1; AC_SUBST([HAVE_PTHREAD_ONCE])
201 HAVE_PTHREAD_MUTEX_INIT=1; AC_SUBST([HAVE_PTHREAD_MUTEX_INIT])
202 HAVE_PTHREAD_MUTEXATTR_INIT=1; AC_SUBST([HAVE_PTHREAD_MUTEXATTR_INIT])
203 HAVE_PTHREAD_MUTEXATTR_GETTYPE=1; AC_SUBST([HAVE_PTHREAD_MUTEXATTR_GETTYPE])
204 HAVE_PTHREAD_MUTEXATTR_SETTYPE=1; AC_SUBST([HAVE_PTHREAD_MUTEXATTR_SETTYPE])
205 HAVE_PTHREAD_MUTEXATTR_GETROBUST=1; AC_SUBST([HAVE_PTHREAD_MUTEXATTR_GETROBUST])
206 HAVE_PTHREAD_MUTEXATTR_SETROBUST=1; AC_SUBST([HAVE_PTHREAD_MUTEXATTR_SETROBUST])
207 HAVE_PTHREAD_MUTEXATTR_DESTROY=1; AC_SUBST([HAVE_PTHREAD_MUTEXATTR_DESTROY])
208 HAVE_PTHREAD_MUTEX_LOCK=1; AC_SUBST([HAVE_PTHREAD_MUTEX_LOCK])
209 HAVE_PTHREAD_MUTEX_TRYLOCK=1; AC_SUBST([HAVE_PTHREAD_MUTEX_TRYLOCK])
210 HAVE_PTHREAD_MUTEX_TIMEDLOCK=1; AC_SUBST([HAVE_PTHREAD_MUTEX_TIMEDLOCK])
211 HAVE_PTHREAD_MUTEX_UNLOCK=1; AC_SUBST([HAVE_PTHREAD_MUTEX_UNLOCK])
212 HAVE_PTHREAD_MUTEX_DESTROY=1; AC_SUBST([HAVE_PTHREAD_MUTEX_DESTROY])
213 HAVE_PTHREAD_RWLOCK_INIT=1; AC_SUBST([HAVE_PTHREAD_RWLOCK_INIT])
214 HAVE_PTHREAD_RWLOCKATTR_INIT=1; AC_SUBST([HAVE_PTHREAD_RWLOCKATTR_INIT])
215 HAVE_PTHREAD_RWLOCKATTR_DESTROY=1; AC_SUBST([HAVE_PTHREAD_RWLOCKATTR_DESTROY])
216 HAVE_PTHREAD_RWLOCK_RDLOCK=1; AC_SUBST([HAVE_PTHREAD_RWLOCK_RDLOCK])
217 HAVE_PTHREAD_RWLOCK_WRLOCK=1; AC_SUBST([HAVE_PTHREAD_RWLOCK_WRLOCK])
218 HAVE_PTHREAD_RWLOCK_TRYRDLOCK=1; AC_SUBST([HAVE_PTHREAD_RWLOCK_TRYRDLOCK])
219 HAVE_PTHREAD_RWLOCK_TRYWRLOCK=1; AC_SUBST([HAVE_PTHREAD_RWLOCK_TRYWRLOCK])
220 HAVE_PTHREAD_RWLOCK_TIMEDRDLOCK=1; AC_SUBST([HAVE_PTHREAD_RWLOCK_TIMEDRDLOCK])
221 HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK=1; AC_SUBST([HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK])
222 HAVE_PTHREAD_RWLOCK_UNLOCK=1; AC_SUBST([HAVE_PTHREAD_RWLOCK_UNLOCK])
223 HAVE_PTHREAD_RWLOCK_DESTROY=1; AC_SUBST([HAVE_PTHREAD_RWLOCK_DESTROY])
224 HAVE_PTHREAD_COND_INIT=1; AC_SUBST([HAVE_PTHREAD_COND_INIT])
225 HAVE_PTHREAD_CONDATTR_INIT=1; AC_SUBST([HAVE_PTHREAD_CONDATTR_INIT])
226 HAVE_PTHREAD_CONDATTR_DESTROY=1; AC_SUBST([HAVE_PTHREAD_CONDATTR_DESTROY])
227 HAVE_PTHREAD_COND_WAIT=1; AC_SUBST([HAVE_PTHREAD_COND_WAIT])
228 HAVE_PTHREAD_COND_TIMEDWAIT=1; AC_SUBST([HAVE_PTHREAD_COND_TIMEDWAIT])
229 HAVE_PTHREAD_COND_SIGNAL=1; AC_SUBST([HAVE_PTHREAD_COND_SIGNAL])
230 HAVE_PTHREAD_COND_BROADCAST=1; AC_SUBST([HAVE_PTHREAD_COND_BROADCAST])
231 HAVE_PTHREAD_COND_DESTROY=1; AC_SUBST([HAVE_PTHREAD_COND_DESTROY])
232 HAVE_PTHREAD_KEY_CREATE=1; AC_SUBST([HAVE_PTHREAD_KEY_CREATE])
233 HAVE_PTHREAD_SETSPECIFIC=1; AC_SUBST([HAVE_PTHREAD_SETSPECIFIC])
234 HAVE_PTHREAD_GETSPECIFIC=1; AC_SUBST([HAVE_PTHREAD_GETSPECIFIC])
235 HAVE_PTHREAD_KEY_DELETE=1; AC_SUBST([HAVE_PTHREAD_KEY_DELETE])
236 HAVE_PTHREAD_SPIN_INIT=1; AC_SUBST([HAVE_PTHREAD_SPIN_INIT])
237 HAVE_PTHREAD_SPIN_LOCK=1; AC_SUBST([HAVE_PTHREAD_SPIN_LOCK])
238 HAVE_PTHREAD_SPIN_TRYLOCK=1; AC_SUBST([HAVE_PTHREAD_SPIN_TRYLOCK])
239 HAVE_PTHREAD_SPIN_UNLOCK=1; AC_SUBST([HAVE_PTHREAD_SPIN_UNLOCK])
240 HAVE_PTHREAD_SPIN_DESTROY=1; AC_SUBST([HAVE_PTHREAD_SPIN_DESTROY])
241 REPLACE_PTHREAD_CREATE=0; AC_SUBST([REPLACE_PTHREAD_CREATE])
242 REPLACE_PTHREAD_ATTR_INIT=0; AC_SUBST([REPLACE_PTHREAD_ATTR_INIT])
243 REPLACE_PTHREAD_ATTR_GETDETACHSTATE=0; AC_SUBST([REPLACE_PTHREAD_ATTR_GETDETACHSTATE])
244 REPLACE_PTHREAD_ATTR_SETDETACHSTATE=0; AC_SUBST([REPLACE_PTHREAD_ATTR_SETDETACHSTATE])
245 REPLACE_PTHREAD_ATTR_DESTROY=0; AC_SUBST([REPLACE_PTHREAD_ATTR_DESTROY])
246 REPLACE_PTHREAD_SELF=0; AC_SUBST([REPLACE_PTHREAD_SELF])
247 REPLACE_PTHREAD_EQUAL=0; AC_SUBST([REPLACE_PTHREAD_EQUAL])
248 REPLACE_PTHREAD_DETACH=0; AC_SUBST([REPLACE_PTHREAD_DETACH])
249 REPLACE_PTHREAD_JOIN=0; AC_SUBST([REPLACE_PTHREAD_JOIN])
250 REPLACE_PTHREAD_EXIT=0; AC_SUBST([REPLACE_PTHREAD_EXIT])
251 REPLACE_PTHREAD_ONCE=0; AC_SUBST([REPLACE_PTHREAD_ONCE])
252 REPLACE_PTHREAD_MUTEX_INIT=0; AC_SUBST([REPLACE_PTHREAD_MUTEX_INIT])
253 REPLACE_PTHREAD_MUTEXATTR_INIT=0; AC_SUBST([REPLACE_PTHREAD_MUTEXATTR_INIT])
254 REPLACE_PTHREAD_MUTEXATTR_GETTYPE=0; AC_SUBST([REPLACE_PTHREAD_MUTEXATTR_GETTYPE])
255 REPLACE_PTHREAD_MUTEXATTR_SETTYPE=0; AC_SUBST([REPLACE_PTHREAD_MUTEXATTR_SETTYPE])
256 REPLACE_PTHREAD_MUTEXATTR_GETROBUST=0; AC_SUBST([REPLACE_PTHREAD_MUTEXATTR_GETROBUST])
257 REPLACE_PTHREAD_MUTEXATTR_SETROBUST=0; AC_SUBST([REPLACE_PTHREAD_MUTEXATTR_SETROBUST])
258 REPLACE_PTHREAD_MUTEXATTR_DESTROY=0; AC_SUBST([REPLACE_PTHREAD_MUTEXATTR_DESTROY])
259 REPLACE_PTHREAD_MUTEX_LOCK=0; AC_SUBST([REPLACE_PTHREAD_MUTEX_LOCK])
260 REPLACE_PTHREAD_MUTEX_TRYLOCK=0; AC_SUBST([REPLACE_PTHREAD_MUTEX_TRYLOCK])
261 REPLACE_PTHREAD_MUTEX_TIMEDLOCK=0; AC_SUBST([REPLACE_PTHREAD_MUTEX_TIMEDLOCK])
262 REPLACE_PTHREAD_MUTEX_UNLOCK=0; AC_SUBST([REPLACE_PTHREAD_MUTEX_UNLOCK])
263 REPLACE_PTHREAD_MUTEX_DESTROY=0; AC_SUBST([REPLACE_PTHREAD_MUTEX_DESTROY])
264 REPLACE_PTHREAD_RWLOCK_INIT=0; AC_SUBST([REPLACE_PTHREAD_RWLOCK_INIT])
265 REPLACE_PTHREAD_RWLOCKATTR_INIT=0; AC_SUBST([REPLACE_PTHREAD_RWLOCKATTR_INIT])
266 REPLACE_PTHREAD_RWLOCKATTR_DESTROY=0; AC_SUBST([REPLACE_PTHREAD_RWLOCKATTR_DESTROY])
267 REPLACE_PTHREAD_RWLOCK_RDLOCK=0; AC_SUBST([REPLACE_PTHREAD_RWLOCK_RDLOCK])
268 REPLACE_PTHREAD_RWLOCK_WRLOCK=0; AC_SUBST([REPLACE_PTHREAD_RWLOCK_WRLOCK])
269 REPLACE_PTHREAD_RWLOCK_TRYRDLOCK=0; AC_SUBST([REPLACE_PTHREAD_RWLOCK_TRYRDLOCK])
270 REPLACE_PTHREAD_RWLOCK_TRYWRLOCK=0; AC_SUBST([REPLACE_PTHREAD_RWLOCK_TRYWRLOCK])
271 REPLACE_PTHREAD_RWLOCK_TIMEDRDLOCK=0; AC_SUBST([REPLACE_PTHREAD_RWLOCK_TIMEDRDLOCK])
272 REPLACE_PTHREAD_RWLOCK_TIMEDWRLOCK=0; AC_SUBST([REPLACE_PTHREAD_RWLOCK_TIMEDWRLOCK])
273 REPLACE_PTHREAD_RWLOCK_UNLOCK=0; AC_SUBST([REPLACE_PTHREAD_RWLOCK_UNLOCK])
274 REPLACE_PTHREAD_RWLOCK_DESTROY=0; AC_SUBST([REPLACE_PTHREAD_RWLOCK_DESTROY])
275 REPLACE_PTHREAD_COND_INIT=0; AC_SUBST([REPLACE_PTHREAD_COND_INIT])
276 REPLACE_PTHREAD_CONDATTR_INIT=0; AC_SUBST([REPLACE_PTHREAD_CONDATTR_INIT])
277 REPLACE_PTHREAD_CONDATTR_DESTROY=0; AC_SUBST([REPLACE_PTHREAD_CONDATTR_DESTROY])
278 REPLACE_PTHREAD_COND_WAIT=0; AC_SUBST([REPLACE_PTHREAD_COND_WAIT])
279 REPLACE_PTHREAD_COND_TIMEDWAIT=0; AC_SUBST([REPLACE_PTHREAD_COND_TIMEDWAIT])
280 REPLACE_PTHREAD_COND_SIGNAL=0; AC_SUBST([REPLACE_PTHREAD_COND_SIGNAL])
281 REPLACE_PTHREAD_COND_BROADCAST=0; AC_SUBST([REPLACE_PTHREAD_COND_BROADCAST])
282 REPLACE_PTHREAD_COND_DESTROY=0; AC_SUBST([REPLACE_PTHREAD_COND_DESTROY])
283 REPLACE_PTHREAD_KEY_CREATE=0; AC_SUBST([REPLACE_PTHREAD_KEY_CREATE])
284 REPLACE_PTHREAD_SETSPECIFIC=0; AC_SUBST([REPLACE_PTHREAD_SETSPECIFIC])
285 REPLACE_PTHREAD_GETSPECIFIC=0; AC_SUBST([REPLACE_PTHREAD_GETSPECIFIC])
286 REPLACE_PTHREAD_KEY_DELETE=0; AC_SUBST([REPLACE_PTHREAD_KEY_DELETE])
287 REPLACE_PTHREAD_SPIN_INIT=0; AC_SUBST([REPLACE_PTHREAD_SPIN_INIT])
288 REPLACE_PTHREAD_SPIN_LOCK=0; AC_SUBST([REPLACE_PTHREAD_SPIN_LOCK])
289 REPLACE_PTHREAD_SPIN_TRYLOCK=0; AC_SUBST([REPLACE_PTHREAD_SPIN_TRYLOCK])
290 REPLACE_PTHREAD_SPIN_UNLOCK=0; AC_SUBST([REPLACE_PTHREAD_SPIN_UNLOCK])
291 REPLACE_PTHREAD_SPIN_DESTROY=0; AC_SUBST([REPLACE_PTHREAD_SPIN_DESTROY])