exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / threads.in.h
blob06bc9b78df30bf4e4bf74be625b5202292e7d450
1 /* An ISO C 11 compatible <threads.h>.
3 Copyright (C) 2019-2024 Free Software Foundation, Inc.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
23 #if defined _GL_ALREADY_INCLUDING_THREADS_H
24 /* Special invocation convention:
25 - On Android we have a sequence of nested includes
26 <threads.h> -> <android/legacy_threads_inlines.h>
27 -> <bits/threads_inlines.h> -> "threads.h"
28 In this situation, the functions are not yet declared, therefore we cannot
29 provide the C++ aliases. */
31 #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_THREADS_H@
33 #else
34 /* Normal invocation convention. */
36 #ifndef _@GUARD_PREFIX@_THREADS_H
38 #define _GL_ALREADY_INCLUDING_THREADS_H
40 /* The include_next requires a split double-inclusion guard. */
41 #if @HAVE_THREADS_H@
42 # @INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_THREADS_H@
43 #endif
45 #undef _GL_ALREADY_INCLUDING_THREADS_H
47 #ifndef _@GUARD_PREFIX@_THREADS_H
48 #define _@GUARD_PREFIX@_THREADS_H
50 /* This file uses _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, _Thread_local,
51 HAVE_RAW_DECL_*. */
52 #if !_GL_CONFIG_H_INCLUDED
53 #error "Please include config.h first."
54 #endif
56 #if !@HAVE_THREADS_H@
58 # include <time.h>
60 # if defined _WIN32 && ! defined __CYGWIN__
61 /* Use Windows threads. */
63 # define WIN32_LEAN_AND_MEAN /* avoid including junk */
64 # include <windows.h>
66 # else
67 /* Use POSIX threads. */
69 # include <pthread.h>
71 # endif
73 #endif
75 /* The __attribute__ feature is available in gcc versions 2.5 and later.
76 The attribute __pure__ was added in gcc 2.96. */
77 #ifndef _GL_ATTRIBUTE_PURE
78 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
79 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
80 # else
81 # define _GL_ATTRIBUTE_PURE /* empty */
82 # endif
83 #endif
85 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
87 /* The definition of _Noreturn is copied here. */
89 /* The definition of _GL_ARG_NONNULL is copied here. */
91 /* The definition of _GL_WARN_ON_USE is copied here. */
94 /* Storage class specifier for thread-local storage. */
95 #ifdef _AIX
96 /* The macro definition from AIX 7.1..7.2 <threads.h> is unusable, because
97 its expansion ends in a semicolon. */
98 # undef thread_local
99 #endif
100 #if !@HAVE_THREADS_H@ || !defined thread_local
101 # define thread_local _Thread_local
102 #endif
103 /* Define the macro thread_local if and only if it actually works. */
104 #if !@HAVE_THREAD_LOCAL@
105 # undef thread_local
106 #endif
109 /* =========== ISO C 11 7.26.5 Thread functions =========== */
111 #if !@HAVE_THREADS_H@
113 /* Return codes. */
114 enum
116 thrd_success = 0,
117 thrd_timedout = 1,
118 thrd_busy = 2,
119 thrd_nomem = 3,
120 thrd_error = 4
123 # if defined _WIN32 && ! defined __CYGWIN__
124 /* Use Windows threads. */
126 # include "windows-thread.h"
128 typedef glwthread_thread_t thrd_t;
130 # else
131 /* Use POSIX threads. */
133 typedef pthread_t thrd_t;
135 # endif
137 #endif
139 #if @BROKEN_THRD_START_T@
140 /* Need to override thrd_start_t, to make thrd_create work. */
141 # define thrd_start_t rpl_thrd_start_t
142 #endif
143 #if @BROKEN_THRD_START_T@ || @BROKEN_THRD_JOIN@
144 /* Need to override thrd_t, to make thrd_join work. */
145 struct thrd_with_exitcode
147 thrd_t volatile tid;
148 int volatile detached;
149 int volatile exitcode;
151 typedef struct thrd_with_exitcode *rpl_thrd_t;
152 # define thrd_t rpl_thrd_t
153 #endif
154 /* Type of the main function of a thread. */
155 #if !@HAVE_THREADS_H@ || @BROKEN_THRD_START_T@
156 typedef int (* thrd_start_t) (void *);
157 #endif
159 #if @GNULIB_THRD@
160 # if @REPLACE_THRD_CREATE@
161 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
162 # define thrd_create rpl_thrd_create
163 # endif
164 _GL_FUNCDECL_RPL (thrd_create, int, (thrd_t *, thrd_start_t, void *)
165 _GL_ARG_NONNULL ((1, 2)));
166 _GL_CXXALIAS_RPL (thrd_create, int, (thrd_t *, thrd_start_t, void *));
167 # else
168 # if !@HAVE_THREADS_H@
169 _GL_FUNCDECL_SYS (thrd_create, int, (thrd_t *, thrd_start_t, void *)
170 _GL_ARG_NONNULL ((1, 2)));
171 # endif
172 _GL_CXXALIAS_SYS (thrd_create, int, (thrd_t *, thrd_start_t, void *));
173 # endif
174 _GL_CXXALIASWARN (thrd_create);
175 #elif defined GNULIB_POSIXCHECK
176 # undef thrd_create
177 # if HAVE_RAW_DECL_THRD_CREATE
178 _GL_WARN_ON_USE (thrd_create, "thrd_create is unportable - "
179 "use gnulib module thrd for portability");
180 # endif
181 #endif
183 #if @GNULIB_THRD@
184 # if @REPLACE_THRD_CURRENT@
185 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
186 # define thrd_current rpl_thrd_current
187 # endif
188 _GL_FUNCDECL_RPL (thrd_current, thrd_t, (void) _GL_ATTRIBUTE_PURE);
189 _GL_CXXALIAS_RPL (thrd_current, thrd_t, (void));
190 # else
191 # if !@HAVE_THREADS_H@
192 _GL_FUNCDECL_SYS (thrd_current, thrd_t, (void) _GL_ATTRIBUTE_PURE);
193 # endif
194 _GL_CXXALIAS_SYS (thrd_current, thrd_t, (void));
195 # endif
196 _GL_CXXALIASWARN (thrd_current);
197 #elif defined GNULIB_POSIXCHECK
198 # undef thrd_current
199 # if HAVE_RAW_DECL_THRD_CURRENT
200 _GL_WARN_ON_USE (thrd_current, "thrd_current is unportable - "
201 "use gnulib module thrd for portability");
202 # endif
203 #endif
205 #if @GNULIB_THRD@
206 # if @REPLACE_THRD_EQUAL@
207 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
208 # define thrd_equal rpl_thrd_equal
209 # endif
210 _GL_FUNCDECL_RPL (thrd_equal, int, (thrd_t, thrd_t) _GL_ATTRIBUTE_PURE);
211 _GL_CXXALIAS_RPL (thrd_equal, int, (thrd_t, thrd_t));
212 # else
213 # if !@HAVE_THREADS_H@
214 _GL_FUNCDECL_SYS (thrd_equal, int, (thrd_t, thrd_t) _GL_ATTRIBUTE_PURE);
215 # endif
216 _GL_CXXALIAS_SYS (thrd_equal, int, (thrd_t, thrd_t));
217 # endif
218 _GL_CXXALIASWARN (thrd_equal);
219 #elif defined GNULIB_POSIXCHECK
220 # undef thrd_equal
221 # if HAVE_RAW_DECL_THRD_EQUAL
222 _GL_WARN_ON_USE (thrd_equal, "thrd_equal is unportable - "
223 "use gnulib module thrd for portability");
224 # endif
225 #endif
227 #if @GNULIB_THRD@
228 # if @REPLACE_THRD_SLEEP@
229 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
230 # define thrd_sleep rpl_thrd_sleep
231 # endif
232 _GL_FUNCDECL_RPL (thrd_sleep, int,
233 (const struct timespec *, struct timespec *)
234 _GL_ARG_NONNULL ((1)));
235 _GL_CXXALIAS_RPL (thrd_sleep, int,
236 (const struct timespec *, struct timespec *));
237 # else
238 # if !@HAVE_THREADS_H@
239 _GL_FUNCDECL_SYS (thrd_sleep, int,
240 (const struct timespec *, struct timespec *)
241 _GL_ARG_NONNULL ((1)));
242 # endif
243 _GL_CXXALIAS_SYS (thrd_sleep, int,
244 (const struct timespec *, struct timespec *));
245 # endif
246 _GL_CXXALIASWARN (thrd_sleep);
247 #elif defined GNULIB_POSIXCHECK
248 # undef thrd_sleep
249 # if HAVE_RAW_DECL_THRD_SLEEP
250 _GL_WARN_ON_USE (thrd_sleep, "thrd_sleep is unportable - "
251 "use gnulib module thrd for portability");
252 # endif
253 #endif
255 #if @GNULIB_THRD@
256 # if @REPLACE_THRD_YIELD@
257 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
258 # define thrd_yield rpl_thrd_yield
259 # endif
260 _GL_FUNCDECL_RPL (thrd_yield, void, (void));
261 _GL_CXXALIAS_RPL (thrd_yield, void, (void));
262 # else
263 # if !@HAVE_THREADS_H@
264 _GL_FUNCDECL_SYS (thrd_yield, void, (void));
265 # endif
266 _GL_CXXALIAS_SYS (thrd_yield, void, (void));
267 # endif
268 _GL_CXXALIASWARN (thrd_yield);
269 #elif defined GNULIB_POSIXCHECK
270 # undef thrd_yield
271 # if HAVE_RAW_DECL_THRD_YIELD
272 _GL_WARN_ON_USE (thrd_yield, "thrd_yield is unportable - "
273 "use gnulib module thrd for portability");
274 # endif
275 #endif
277 #if @GNULIB_THRD@
278 # if @REPLACE_THRD_DETACH@
279 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
280 # define thrd_detach rpl_thrd_detach
281 # endif
282 _GL_FUNCDECL_RPL (thrd_detach, int, (thrd_t));
283 _GL_CXXALIAS_RPL (thrd_detach, int, (thrd_t));
284 # else
285 # if !@HAVE_THREADS_H@
286 _GL_FUNCDECL_SYS (thrd_detach, int, (thrd_t));
287 # endif
288 _GL_CXXALIAS_SYS (thrd_detach, int, (thrd_t));
289 # endif
290 _GL_CXXALIASWARN (thrd_detach);
291 #elif defined GNULIB_POSIXCHECK
292 # undef thrd_detach
293 # if HAVE_RAW_DECL_THRD_DETACH
294 _GL_WARN_ON_USE (thrd_detach, "thrd_detach is unportable - "
295 "use gnulib module thrd for portability");
296 # endif
297 #endif
299 #if @GNULIB_THRD@
300 # if @REPLACE_THRD_JOIN@
301 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
302 # define thrd_join rpl_thrd_join
303 # endif
304 _GL_FUNCDECL_RPL (thrd_join, int, (thrd_t, int *));
305 _GL_CXXALIAS_RPL (thrd_join, int, (thrd_t, int *));
306 # else
307 # if !@HAVE_THREADS_H@
308 _GL_FUNCDECL_SYS (thrd_join, int, (thrd_t, int *));
309 # endif
310 _GL_CXXALIAS_SYS (thrd_join, int, (thrd_t, int *));
311 # endif
312 _GL_CXXALIASWARN (thrd_join);
313 #elif defined GNULIB_POSIXCHECK
314 # undef thrd_join
315 # if HAVE_RAW_DECL_THRD_JOIN
316 _GL_WARN_ON_USE (thrd_join, "thrd_join is unportable - "
317 "use gnulib module thrd for portability");
318 # endif
319 #endif
321 #if @GNULIB_THRD@
322 # if @REPLACE_THRD_EXIT@
323 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
324 # define thrd_exit rpl_thrd_exit
325 # endif
326 _GL_FUNCDECL_RPL (thrd_exit, _Noreturn void, (int));
327 _GL_CXXALIAS_RPL (thrd_exit, void, (int));
328 # else
329 # if !@HAVE_THREADS_H@
330 _GL_FUNCDECL_SYS (thrd_exit, _Noreturn void, (int));
331 # endif
332 /* Need to cast because of AIX with xlclang++. */
333 _GL_CXXALIAS_SYS_CAST (thrd_exit, void, (int));
334 # endif
335 _GL_CXXALIASWARN (thrd_exit);
336 #elif defined GNULIB_POSIXCHECK
337 # undef thrd_exit
338 # if HAVE_RAW_DECL_THRD_EXIT
339 _GL_WARN_ON_USE (thrd_exit, "thrd_exit is unportable - "
340 "use gnulib module thrd for portability");
341 # endif
342 #endif
345 /* =========== ISO C 11 7.26.4 Mutex functions =========== */
347 #if !@HAVE_THREADS_H@
349 /* Types of mutexes. */
350 enum
352 mtx_plain = 0,
353 mtx_timed = 1,
354 mtx_recursive = 2
357 # if defined _WIN32 && ! defined __CYGWIN__
358 /* Use Windows threads. */
360 # include "windows-mutex.h"
361 # include "windows-recmutex.h"
362 # include "windows-timedmutex.h"
363 # include "windows-timedrecmutex.h"
365 typedef struct
367 int type;
368 union
370 glwthread_mutex_t u_mutex;
371 glwthread_recmutex_t u_recmutex;
372 glwthread_timedmutex_t u_timedmutex;
373 glwthread_timedrecmutex_t u_timedrecmutex;
377 mtx_t;
379 # else
380 /* Use POSIX threads. */
382 typedef pthread_mutex_t mtx_t;
384 # endif
386 #endif
388 #if @GNULIB_MTX@
389 # if @REPLACE_MTX_INIT@
390 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
391 # define mtx_init rpl_mtx_init
392 # endif
393 _GL_FUNCDECL_RPL (mtx_init, int, (mtx_t *, int) _GL_ARG_NONNULL ((1)));
394 _GL_CXXALIAS_RPL (mtx_init, int, (mtx_t *, int));
395 # else
396 # if !@HAVE_THREADS_H@
397 _GL_FUNCDECL_SYS (mtx_init, int, (mtx_t *, int) _GL_ARG_NONNULL ((1)));
398 # endif
399 _GL_CXXALIAS_SYS (mtx_init, int, (mtx_t *, int));
400 # endif
401 _GL_CXXALIASWARN (mtx_init);
402 #elif defined GNULIB_POSIXCHECK
403 # undef mtx_init
404 # if HAVE_RAW_DECL_MTX_INIT
405 _GL_WARN_ON_USE (mtx_init, "mtx_init is unportable - "
406 "use gnulib module mtx for portability");
407 # endif
408 #endif
410 #if @GNULIB_MTX@
411 # if @REPLACE_MTX_LOCK@
412 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
413 # define mtx_lock rpl_mtx_lock
414 # endif
415 _GL_FUNCDECL_RPL (mtx_lock, int, (mtx_t *) _GL_ARG_NONNULL ((1)));
416 _GL_CXXALIAS_RPL (mtx_lock, int, (mtx_t *));
417 # else
418 # if !@HAVE_THREADS_H@
419 _GL_FUNCDECL_SYS (mtx_lock, int, (mtx_t *) _GL_ARG_NONNULL ((1)));
420 # endif
421 _GL_CXXALIAS_SYS (mtx_lock, int, (mtx_t *));
422 # endif
423 _GL_CXXALIASWARN (mtx_lock);
424 #elif defined GNULIB_POSIXCHECK
425 # undef mtx_lock
426 # if HAVE_RAW_DECL_MTX_LOCK
427 _GL_WARN_ON_USE (mtx_lock, "mtx_lock is unportable - "
428 "use gnulib module mtx for portability");
429 # endif
430 #endif
432 #if @GNULIB_MTX@
433 # if @REPLACE_MTX_TRYLOCK@
434 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
435 # define mtx_trylock rpl_mtx_trylock
436 # endif
437 _GL_FUNCDECL_RPL (mtx_trylock, int, (mtx_t *) _GL_ARG_NONNULL ((1)));
438 _GL_CXXALIAS_RPL (mtx_trylock, int, (mtx_t *));
439 # else
440 # if !@HAVE_THREADS_H@
441 _GL_FUNCDECL_SYS (mtx_trylock, int, (mtx_t *) _GL_ARG_NONNULL ((1)));
442 # endif
443 _GL_CXXALIAS_SYS (mtx_trylock, int, (mtx_t *));
444 # endif
445 _GL_CXXALIASWARN (mtx_trylock);
446 #elif defined GNULIB_POSIXCHECK
447 # undef mtx_trylock
448 # if HAVE_RAW_DECL_MTX_TRYLOCK
449 _GL_WARN_ON_USE (mtx_trylock, "mtx_trylock is unportable - "
450 "use gnulib module mtx for portability");
451 # endif
452 #endif
454 #if @GNULIB_MTX@
455 # if @REPLACE_MTX_TIMEDLOCK@
456 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
457 # define mtx_timedlock rpl_mtx_timedlock
458 # endif
459 _GL_FUNCDECL_RPL (mtx_timedlock, int, (mtx_t *, const struct timespec *)
460 _GL_ARG_NONNULL ((1, 2)));
461 _GL_CXXALIAS_RPL (mtx_timedlock, int, (mtx_t *, const struct timespec *));
462 # else
463 # if !@HAVE_THREADS_H@
464 _GL_FUNCDECL_SYS (mtx_timedlock, int, (mtx_t *, const struct timespec *)
465 _GL_ARG_NONNULL ((1, 2)));
466 # endif
467 _GL_CXXALIAS_SYS (mtx_timedlock, int, (mtx_t *, const struct timespec *));
468 # endif
469 _GL_CXXALIASWARN (mtx_timedlock);
470 #elif defined GNULIB_POSIXCHECK
471 # undef mtx_timedlock
472 # if HAVE_RAW_DECL_MTX_TIMEDLOCK
473 _GL_WARN_ON_USE (mtx_timedlock, "mtx_timedlock is unportable - "
474 "use gnulib module mtx for portability");
475 # endif
476 #endif
478 #if @GNULIB_MTX@
479 # if @REPLACE_MTX_UNLOCK@
480 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
481 # define mtx_unlock rpl_mtx_unlock
482 # endif
483 _GL_FUNCDECL_RPL (mtx_unlock, int, (mtx_t *) _GL_ARG_NONNULL ((1)));
484 _GL_CXXALIAS_RPL (mtx_unlock, int, (mtx_t *));
485 # else
486 # if !@HAVE_THREADS_H@
487 _GL_FUNCDECL_SYS (mtx_unlock, int, (mtx_t *) _GL_ARG_NONNULL ((1)));
488 # endif
489 _GL_CXXALIAS_SYS (mtx_unlock, int, (mtx_t *));
490 # endif
491 _GL_CXXALIASWARN (mtx_unlock);
492 #elif defined GNULIB_POSIXCHECK
493 # undef mtx_unlock
494 # if HAVE_RAW_DECL_MTX_UNLOCK
495 _GL_WARN_ON_USE (mtx_unlock, "mtx_unlock is unportable - "
496 "use gnulib module mtx for portability");
497 # endif
498 #endif
500 #if @GNULIB_MTX@
501 # if @REPLACE_MTX_DESTROY@
502 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
503 # define mtx_destroy rpl_mtx_destroy
504 # endif
505 _GL_FUNCDECL_RPL (mtx_destroy, void, (mtx_t *) _GL_ARG_NONNULL ((1)));
506 _GL_CXXALIAS_RPL (mtx_destroy, void, (mtx_t *));
507 # else
508 # if !@HAVE_THREADS_H@
509 _GL_FUNCDECL_SYS (mtx_destroy, void, (mtx_t *) _GL_ARG_NONNULL ((1)));
510 # endif
511 _GL_CXXALIAS_SYS (mtx_destroy, void, (mtx_t *));
512 # endif
513 _GL_CXXALIASWARN (mtx_destroy);
514 #elif defined GNULIB_POSIXCHECK
515 # undef mtx_destroy
516 # if HAVE_RAW_DECL_MTX_DESTROY
517 _GL_WARN_ON_USE (mtx_destroy, "mtx_destroy is unportable - "
518 "use gnulib module mtx for portability");
519 # endif
520 #endif
523 /* =========== ISO C 11 7.26.2 Initialization functions =========== */
525 #if !@HAVE_THREADS_H@
527 /* Type that contains a flag for use by call_once. */
528 # if defined _WIN32 && ! defined __CYGWIN__
529 /* Use Windows threads. */
531 # include "windows-once.h"
533 typedef glwthread_once_t once_flag;
534 # define ONCE_FLAG_INIT GLWTHREAD_ONCE_INIT
536 # else
537 /* Use POSIX threads. */
539 typedef pthread_once_t once_flag;
540 # define ONCE_FLAG_INIT PTHREAD_ONCE_INIT
542 # endif
544 #endif
546 #if @GNULIB_CALL_ONCE@
547 # if @REPLACE_CALL_ONCE@
548 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
549 # define call_once rpl_call_once
550 # endif
551 _GL_FUNCDECL_RPL (call_once, void, (once_flag *, void (*) (void))
552 _GL_ARG_NONNULL ((1, 2)));
553 _GL_CXXALIAS_RPL (call_once, void, (once_flag *, void (*) (void)));
554 # else
555 # if !@HAVE_THREADS_H@
556 _GL_FUNCDECL_SYS (call_once, void, (once_flag *, void (*) (void))
557 _GL_ARG_NONNULL ((1, 2)));
558 # endif
559 _GL_CXXALIAS_SYS_CAST (call_once, void, (once_flag *, void (*) (void)));
560 # endif
561 _GL_CXXALIASWARN (call_once);
562 #elif defined GNULIB_POSIXCHECK
563 # undef call_once
564 # if HAVE_RAW_DECL_CALL_ONCE
565 _GL_WARN_ON_USE (call_once, "call_once is unportable - "
566 "use gnulib module call_once for portability");
567 # endif
568 #endif
571 /* =========== ISO C 11 7.26.3 Condition variable functions =========== */
573 #if !@HAVE_THREADS_H@
575 # if defined _WIN32 && ! defined __CYGWIN__
576 /* Use Windows threads. */
578 # include "windows-cond.h"
580 typedef glwthread_cond_t cnd_t;
582 # else
583 /* Use POSIX threads. */
585 typedef pthread_cond_t cnd_t;
587 # endif
589 #endif
591 #if @GNULIB_CND@
592 # if @REPLACE_CND_INIT@
593 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
594 # define cnd_init rpl_cnd_init
595 # endif
596 _GL_FUNCDECL_RPL (cnd_init, int, (cnd_t *) _GL_ARG_NONNULL ((1)));
597 _GL_CXXALIAS_RPL (cnd_init, int, (cnd_t *));
598 # else
599 # if !@HAVE_THREADS_H@
600 _GL_FUNCDECL_SYS (cnd_init, int, (cnd_t *) _GL_ARG_NONNULL ((1)));
601 # endif
602 _GL_CXXALIAS_SYS (cnd_init, int, (cnd_t *));
603 # endif
604 _GL_CXXALIASWARN (cnd_init);
605 #elif defined GNULIB_POSIXCHECK
606 # undef cnd_init
607 # if HAVE_RAW_DECL_CND_INIT
608 _GL_WARN_ON_USE (cnd_init, "cnd_init is unportable - "
609 "use gnulib module cnd for portability");
610 # endif
611 #endif
613 #if @GNULIB_CND@
614 # if @REPLACE_CND_WAIT@
615 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
616 # define cnd_wait rpl_cnd_wait
617 # endif
618 _GL_FUNCDECL_RPL (cnd_wait, int, (cnd_t *, mtx_t *) _GL_ARG_NONNULL ((1, 2)));
619 _GL_CXXALIAS_RPL (cnd_wait, int, (cnd_t *, mtx_t *));
620 # else
621 # if !@HAVE_THREADS_H@
622 _GL_FUNCDECL_SYS (cnd_wait, int, (cnd_t *, mtx_t *) _GL_ARG_NONNULL ((1, 2)));
623 # endif
624 _GL_CXXALIAS_SYS (cnd_wait, int, (cnd_t *, mtx_t *));
625 # endif
626 _GL_CXXALIASWARN (cnd_wait);
627 #elif defined GNULIB_POSIXCHECK
628 # undef cnd_wait
629 # if HAVE_RAW_DECL_CND_WAIT
630 _GL_WARN_ON_USE (cnd_wait, "cnd_wait is unportable - "
631 "use gnulib module cnd for portability");
632 # endif
633 #endif
635 #if @GNULIB_CND@
636 # if @REPLACE_CND_TIMEDWAIT@
637 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
638 # define cnd_timedwait rpl_cnd_timedwait
639 # endif
640 _GL_FUNCDECL_RPL (cnd_timedwait, int,
641 (cnd_t *, mtx_t *, const struct timespec *)
642 _GL_ARG_NONNULL ((1, 2, 3)));
643 _GL_CXXALIAS_RPL (cnd_timedwait, int,
644 (cnd_t *, mtx_t *, const struct timespec *));
645 # else
646 # if !@HAVE_THREADS_H@
647 _GL_FUNCDECL_SYS (cnd_timedwait, int,
648 (cnd_t *, mtx_t *, const struct timespec *)
649 _GL_ARG_NONNULL ((1, 2, 3)));
650 # endif
651 _GL_CXXALIAS_SYS (cnd_timedwait, int,
652 (cnd_t *, mtx_t *, const struct timespec *));
653 # endif
654 _GL_CXXALIASWARN (cnd_timedwait);
655 #elif defined GNULIB_POSIXCHECK
656 # undef cnd_timedwait
657 # if HAVE_RAW_DECL_CND_TIMEDWAIT
658 _GL_WARN_ON_USE (cnd_timedwait, "cnd_timedwait is unportable - "
659 "use gnulib module cnd for portability");
660 # endif
661 #endif
663 #if @GNULIB_CND@
664 # if @REPLACE_CND_SIGNAL@
665 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
666 # define cnd_signal rpl_cnd_signal
667 # endif
668 _GL_FUNCDECL_RPL (cnd_signal, int, (cnd_t *) _GL_ARG_NONNULL ((1)));
669 _GL_CXXALIAS_RPL (cnd_signal, int, (cnd_t *));
670 # else
671 # if !@HAVE_THREADS_H@
672 _GL_FUNCDECL_SYS (cnd_signal, int, (cnd_t *) _GL_ARG_NONNULL ((1)));
673 # endif
674 _GL_CXXALIAS_SYS (cnd_signal, int, (cnd_t *));
675 # endif
676 _GL_CXXALIASWARN (cnd_signal);
677 #elif defined GNULIB_POSIXCHECK
678 # undef cnd_signal
679 # if HAVE_RAW_DECL_CND_SIGNAL
680 _GL_WARN_ON_USE (cnd_signal, "cnd_signal is unportable - "
681 "use gnulib module cnd for portability");
682 # endif
683 #endif
685 #if @GNULIB_CND@
686 # if @REPLACE_CND_BROADCAST@
687 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
688 # define cnd_broadcast rpl_cnd_broadcast
689 # endif
690 _GL_FUNCDECL_RPL (cnd_broadcast, int, (cnd_t *) _GL_ARG_NONNULL ((1)));
691 _GL_CXXALIAS_RPL (cnd_broadcast, int, (cnd_t *));
692 # else
693 # if !@HAVE_THREADS_H@
694 _GL_FUNCDECL_SYS (cnd_broadcast, int, (cnd_t *) _GL_ARG_NONNULL ((1)));
695 # endif
696 _GL_CXXALIAS_SYS (cnd_broadcast, int, (cnd_t *));
697 # endif
698 _GL_CXXALIASWARN (cnd_broadcast);
699 #elif defined GNULIB_POSIXCHECK
700 # undef cnd_broadcast
701 # if HAVE_RAW_DECL_CND_BROADCAST
702 _GL_WARN_ON_USE (cnd_broadcast, "cnd_broadcast is unportable - "
703 "use gnulib module cnd for portability");
704 # endif
705 #endif
707 #if @GNULIB_CND@
708 # if @REPLACE_CND_DESTROY@
709 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
710 # define cnd_destroy rpl_cnd_destroy
711 # endif
712 _GL_FUNCDECL_RPL (cnd_destroy, void, (cnd_t *) _GL_ARG_NONNULL ((1)));
713 _GL_CXXALIAS_RPL (cnd_destroy, void, (cnd_t *));
714 # else
715 # if !@HAVE_THREADS_H@
716 _GL_FUNCDECL_SYS (cnd_destroy, void, (cnd_t *) _GL_ARG_NONNULL ((1)));
717 # endif
718 _GL_CXXALIAS_SYS (cnd_destroy, void, (cnd_t *));
719 # endif
720 _GL_CXXALIASWARN (cnd_destroy);
721 #elif defined GNULIB_POSIXCHECK
722 # undef cnd_destroy
723 # if HAVE_RAW_DECL_CND_DESTROY
724 _GL_WARN_ON_USE (cnd_destroy, "cnd_destroy is unportable - "
725 "use gnulib module cnd for portability");
726 # endif
727 #endif
730 /* =========== ISO C 11 7.26.6 Thread-specific storage functions =========== */
732 #if !@HAVE_THREADS_H@
734 # if defined _WIN32 && ! defined __CYGWIN__
735 /* Use Windows threads. */
737 # include "windows-tls.h"
739 typedef glwthread_tls_key_t tss_t;
740 # define TSS_DTOR_ITERATIONS GLWTHREAD_DESTRUCTOR_ITERATIONS
742 # else
743 /* Use POSIX threads. */
745 # include <limits.h>
747 typedef pthread_key_t tss_t;
749 # endif
751 /* Type for the destructor of a thread-specific storage pointer. */
752 typedef void (*tss_dtor_t) (void *);
754 #endif
756 /* AIX 7.1 <threads.h> does not define TSS_DTOR_ITERATIONS. */
757 #ifndef TSS_DTOR_ITERATIONS
758 # ifdef PTHREAD_DESTRUCTOR_ITERATIONS
759 # define TSS_DTOR_ITERATIONS PTHREAD_DESTRUCTOR_ITERATIONS
760 # else
761 /* IRIX 6.5 does not define PTHREAD_DESTRUCTOR_ITERATIONS.
762 This value is a wild guess. */
763 # define TSS_DTOR_ITERATIONS 1
764 # endif
765 #endif
767 #if @GNULIB_TSS@
768 # if @REPLACE_TSS_CREATE@
769 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
770 # define tss_create rpl_tss_create
771 # endif
772 _GL_FUNCDECL_RPL (tss_create, int, (tss_t *, tss_dtor_t) _GL_ARG_NONNULL ((1)));
773 _GL_CXXALIAS_RPL (tss_create, int, (tss_t *, tss_dtor_t));
774 # else
775 # if !@HAVE_THREADS_H@
776 _GL_FUNCDECL_SYS (tss_create, int, (tss_t *, tss_dtor_t) _GL_ARG_NONNULL ((1)));
777 # endif
778 _GL_CXXALIAS_SYS (tss_create, int, (tss_t *, tss_dtor_t));
779 # endif
780 _GL_CXXALIASWARN (tss_create);
781 #elif defined GNULIB_POSIXCHECK
782 # undef tss_create
783 # if HAVE_RAW_DECL_TSS_CREATE
784 _GL_WARN_ON_USE (tss_create, "tss_create is unportable - "
785 "use gnulib module tss for portability");
786 # endif
787 #endif
789 #if @GNULIB_TSS@
790 # if @REPLACE_TSS_SET@
791 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
792 # define tss_set rpl_tss_set
793 # endif
794 _GL_FUNCDECL_RPL (tss_set, int, (tss_t, void *));
795 _GL_CXXALIAS_RPL (tss_set, int, (tss_t, void *));
796 # else
797 # if !@HAVE_THREADS_H@
798 _GL_FUNCDECL_SYS (tss_set, int, (tss_t, void *));
799 # endif
800 _GL_CXXALIAS_SYS (tss_set, int, (tss_t, void *));
801 # endif
802 _GL_CXXALIASWARN (tss_set);
803 #elif defined GNULIB_POSIXCHECK
804 # undef tss_set
805 # if HAVE_RAW_DECL_TSS_SET
806 _GL_WARN_ON_USE (tss_set, "tss_set is unportable - "
807 "use gnulib module tss for portability");
808 # endif
809 #endif
811 #if @GNULIB_TSS@
812 # if @REPLACE_TSS_GET@
813 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
814 # define tss_get rpl_tss_get
815 # endif
816 _GL_FUNCDECL_RPL (tss_get, void *, (tss_t));
817 _GL_CXXALIAS_RPL (tss_get, void *, (tss_t));
818 # else
819 # if !@HAVE_THREADS_H@
820 _GL_FUNCDECL_SYS (tss_get, void *, (tss_t));
821 # endif
822 _GL_CXXALIAS_SYS (tss_get, void *, (tss_t));
823 # endif
824 _GL_CXXALIASWARN (tss_get);
825 #elif defined GNULIB_POSIXCHECK
826 # undef tss_get
827 # if HAVE_RAW_DECL_TSS_GET
828 _GL_WARN_ON_USE (tss_get, "tss_get is unportable - "
829 "use gnulib module tss for portability");
830 # endif
831 #endif
833 #if @GNULIB_TSS@
834 # if @REPLACE_TSS_DELETE@
835 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
836 # define tss_delete rpl_tss_delete
837 # endif
838 _GL_FUNCDECL_RPL (tss_delete, void, (tss_t));
839 _GL_CXXALIAS_RPL (tss_delete, void, (tss_t));
840 # else
841 # if !@HAVE_THREADS_H@
842 _GL_FUNCDECL_SYS (tss_delete, void, (tss_t));
843 # endif
844 _GL_CXXALIAS_SYS (tss_delete, void, (tss_t));
845 # endif
846 _GL_CXXALIASWARN (tss_delete);
847 #elif defined GNULIB_POSIXCHECK
848 # undef tss_delete
849 # if HAVE_RAW_DECL_TSS_DELETE
850 _GL_WARN_ON_USE (tss_delete, "tss_delete is unportable - "
851 "use gnulib module tss for portability");
852 # endif
853 #endif
856 #endif /* _@GUARD_PREFIX@_THREADS_H */
857 #endif /* _@GUARD_PREFIX@_THREADS_H */
858 #endif