]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/nptl/pthread.h
nptl: Move pthread_yield into libc, as a compatibility symbol
[thirdparty/glibc.git] / sysdeps / nptl / pthread.h
1 /* Copyright (C) 2002-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18 #ifndef _PTHREAD_H
19 #define _PTHREAD_H 1
20
21 #include <features.h>
22 #include <sched.h>
23 #include <time.h>
24
25 #include <bits/endian.h>
26 #include <bits/pthreadtypes.h>
27 #include <bits/setjmp.h>
28 #include <bits/wordsize.h>
29 #include <bits/types/struct_timespec.h>
30 #include <bits/types/__sigset_t.h>
31 #include <bits/types/struct___jmp_buf_tag.h>
32
33
34 /* Detach state. */
35 enum
36 {
37 PTHREAD_CREATE_JOINABLE,
38 #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
39 PTHREAD_CREATE_DETACHED
40 #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
41 };
42
43
44 /* Mutex types. */
45 enum
46 {
47 PTHREAD_MUTEX_TIMED_NP,
48 PTHREAD_MUTEX_RECURSIVE_NP,
49 PTHREAD_MUTEX_ERRORCHECK_NP,
50 PTHREAD_MUTEX_ADAPTIVE_NP
51 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
52 ,
53 PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
54 PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
55 PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
56 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
57 #endif
58 #ifdef __USE_GNU
59 /* For compatibility. */
60 , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP
61 #endif
62 };
63
64
65 #ifdef __USE_XOPEN2K
66 /* Robust mutex or not flags. */
67 enum
68 {
69 PTHREAD_MUTEX_STALLED,
70 PTHREAD_MUTEX_STALLED_NP = PTHREAD_MUTEX_STALLED,
71 PTHREAD_MUTEX_ROBUST,
72 PTHREAD_MUTEX_ROBUST_NP = PTHREAD_MUTEX_ROBUST
73 };
74 #endif
75
76
77 #if defined __USE_POSIX199506 || defined __USE_UNIX98
78 /* Mutex protocols. */
79 enum
80 {
81 PTHREAD_PRIO_NONE,
82 PTHREAD_PRIO_INHERIT,
83 PTHREAD_PRIO_PROTECT
84 };
85 #endif
86
87
88 #define PTHREAD_MUTEX_INITIALIZER \
89 { { __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_TIMED_NP) } }
90 #ifdef __USE_GNU
91 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
92 { { __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_RECURSIVE_NP) } }
93 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
94 { { __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_ERRORCHECK_NP) } }
95 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
96 { { __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_ADAPTIVE_NP) } }
97 #endif
98
99
100 /* Read-write lock types. */
101 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
102 enum
103 {
104 PTHREAD_RWLOCK_PREFER_READER_NP,
105 PTHREAD_RWLOCK_PREFER_WRITER_NP,
106 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
107 PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP
108 };
109
110
111 /* Read-write lock initializers. */
112 # define PTHREAD_RWLOCK_INITIALIZER \
113 { { __PTHREAD_RWLOCK_INITIALIZER (PTHREAD_RWLOCK_DEFAULT_NP) } }
114 # ifdef __USE_GNU
115 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
116 { { __PTHREAD_RWLOCK_INITIALIZER (PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) } }
117 # endif
118 #endif /* Unix98 or XOpen2K */
119
120
121 /* Scheduler inheritance. */
122 enum
123 {
124 PTHREAD_INHERIT_SCHED,
125 #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
126 PTHREAD_EXPLICIT_SCHED
127 #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
128 };
129
130
131 /* Scope handling. */
132 enum
133 {
134 PTHREAD_SCOPE_SYSTEM,
135 #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
136 PTHREAD_SCOPE_PROCESS
137 #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
138 };
139
140
141 /* Process shared or private flag. */
142 enum
143 {
144 PTHREAD_PROCESS_PRIVATE,
145 #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
146 PTHREAD_PROCESS_SHARED
147 #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
148 };
149
150
151
152 /* Conditional variable handling. */
153 #define PTHREAD_COND_INITIALIZER { { {0}, {0}, {0, 0}, {0, 0}, 0, 0, {0, 0} } }
154
155
156 /* Cleanup buffers */
157 struct _pthread_cleanup_buffer
158 {
159 void (*__routine) (void *); /* Function to call. */
160 void *__arg; /* Its argument. */
161 int __canceltype; /* Saved cancellation type. */
162 struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */
163 };
164
165 /* Cancellation */
166 enum
167 {
168 PTHREAD_CANCEL_ENABLE,
169 #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
170 PTHREAD_CANCEL_DISABLE
171 #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
172 };
173 enum
174 {
175 PTHREAD_CANCEL_DEFERRED,
176 #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
177 PTHREAD_CANCEL_ASYNCHRONOUS
178 #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
179 };
180 #define PTHREAD_CANCELED ((void *) -1)
181
182
183 /* Single execution handling. */
184 #define PTHREAD_ONCE_INIT 0
185
186
187 #ifdef __USE_XOPEN2K
188 /* Value returned by 'pthread_barrier_wait' for one of the threads after
189 the required number of threads have called this function.
190 -1 is distinct from 0 and all errno constants */
191 # define PTHREAD_BARRIER_SERIAL_THREAD -1
192 #endif
193
194
195 __BEGIN_DECLS
196
197 /* Create a new thread, starting with execution of START-ROUTINE
198 getting passed ARG. Creation attributed come from ATTR. The new
199 handle is stored in *NEWTHREAD. */
200 extern int pthread_create (pthread_t *__restrict __newthread,
201 const pthread_attr_t *__restrict __attr,
202 void *(*__start_routine) (void *),
203 void *__restrict __arg) __THROWNL __nonnull ((1, 3));
204
205 /* Terminate calling thread.
206
207 The registered cleanup handlers are called via exception handling
208 so we cannot mark this function with __THROW.*/
209 extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
210
211 /* Make calling thread wait for termination of the thread TH. The
212 exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
213 is not NULL.
214
215 This function is a cancellation point and therefore not marked with
216 __THROW. */
217 extern int pthread_join (pthread_t __th, void **__thread_return);
218
219 #ifdef __USE_GNU
220 /* Check whether thread TH has terminated. If yes return the status of
221 the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
222 extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
223
224 /* Make calling thread wait for termination of the thread TH, but only
225 until TIMEOUT. The exit status of the thread is stored in
226 *THREAD_RETURN, if THREAD_RETURN is not NULL.
227
228 This function is a cancellation point and therefore not marked with
229 __THROW. */
230 extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
231 const struct timespec *__abstime);
232
233 /* Make calling thread wait for termination of the thread TH, but only
234 until TIMEOUT measured against the clock specified by CLOCKID. The
235 exit status of the thread is stored in *THREAD_RETURN, if
236 THREAD_RETURN is not NULL.
237
238 This function is a cancellation point and therefore not marked with
239 __THROW. */
240 extern int pthread_clockjoin_np (pthread_t __th, void **__thread_return,
241 clockid_t __clockid,
242 const struct timespec *__abstime);
243 #endif
244
245 /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
246 The resources of TH will therefore be freed immediately when it
247 terminates, instead of waiting for another thread to perform PTHREAD_JOIN
248 on it. */
249 extern int pthread_detach (pthread_t __th) __THROW;
250
251
252 /* Obtain the identifier of the current thread. */
253 extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__));
254
255 /* Compare two thread identifiers. */
256 extern int pthread_equal (pthread_t __thread1, pthread_t __thread2)
257 __THROW __attribute__ ((__const__));
258
259
260 /* Thread attribute handling. */
261
262 /* Initialize thread attribute *ATTR with default attributes
263 (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
264 no user-provided stack). */
265 extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1));
266
267 /* Destroy thread attribute *ATTR. */
268 extern int pthread_attr_destroy (pthread_attr_t *__attr)
269 __THROW __nonnull ((1));
270
271 /* Get detach state attribute. */
272 extern int pthread_attr_getdetachstate (const pthread_attr_t *__attr,
273 int *__detachstate)
274 __THROW __nonnull ((1, 2));
275
276 /* Set detach state attribute. */
277 extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
278 int __detachstate)
279 __THROW __nonnull ((1));
280
281
282 /* Get the size of the guard area created for stack overflow protection. */
283 extern int pthread_attr_getguardsize (const pthread_attr_t *__attr,
284 size_t *__guardsize)
285 __THROW __nonnull ((1, 2));
286
287 /* Set the size of the guard area created for stack overflow protection. */
288 extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
289 size_t __guardsize)
290 __THROW __nonnull ((1));
291
292
293 /* Return in *PARAM the scheduling parameters of *ATTR. */
294 extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict __attr,
295 struct sched_param *__restrict __param)
296 __THROW __nonnull ((1, 2));
297
298 /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
299 extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
300 const struct sched_param *__restrict
301 __param) __THROW __nonnull ((1, 2));
302
303 /* Return in *POLICY the scheduling policy of *ATTR. */
304 extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict
305 __attr, int *__restrict __policy)
306 __THROW __nonnull ((1, 2));
307
308 /* Set scheduling policy in *ATTR according to POLICY. */
309 extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
310 __THROW __nonnull ((1));
311
312 /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
313 extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict
314 __attr, int *__restrict __inherit)
315 __THROW __nonnull ((1, 2));
316
317 /* Set scheduling inheritance mode in *ATTR according to INHERIT. */
318 extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
319 int __inherit)
320 __THROW __nonnull ((1));
321
322
323 /* Return in *SCOPE the scheduling contention scope of *ATTR. */
324 extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr,
325 int *__restrict __scope)
326 __THROW __nonnull ((1, 2));
327
328 /* Set scheduling contention scope in *ATTR according to SCOPE. */
329 extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
330 __THROW __nonnull ((1));
331
332 /* Return the previously set address for the stack. */
333 extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict
334 __attr, void **__restrict __stackaddr)
335 __THROW __nonnull ((1, 2)) __attribute_deprecated__;
336
337 /* Set the starting address of the stack of the thread to be created.
338 Depending on whether the stack grows up or down the value must either
339 be higher or lower than all the address in the memory block. The
340 minimal size of the block must be PTHREAD_STACK_MIN. */
341 extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
342 void *__stackaddr)
343 __THROW __nonnull ((1)) __attribute_deprecated__;
344
345 /* Return the currently used minimal stack size. */
346 extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict
347 __attr, size_t *__restrict __stacksize)
348 __THROW __nonnull ((1, 2));
349
350 /* Add information about the minimum stack size needed for the thread
351 to be started. This size must never be less than PTHREAD_STACK_MIN
352 and must also not exceed the system limits. */
353 extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
354 size_t __stacksize)
355 __THROW __nonnull ((1));
356
357 #ifdef __USE_XOPEN2K
358 /* Return the previously set address for the stack. */
359 extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr,
360 void **__restrict __stackaddr,
361 size_t *__restrict __stacksize)
362 __THROW __nonnull ((1, 2, 3));
363
364 /* The following two interfaces are intended to replace the last two. They
365 require setting the address as well as the size since only setting the
366 address will make the implementation on some architectures impossible. */
367 extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
368 size_t __stacksize) __THROW __nonnull ((1));
369 #endif
370
371 #ifdef __USE_GNU
372 /* Thread created with attribute ATTR will be limited to run only on
373 the processors represented in CPUSET. */
374 extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr,
375 size_t __cpusetsize,
376 const cpu_set_t *__cpuset)
377 __THROW __nonnull ((1, 3));
378
379 /* Get bit set in CPUSET representing the processors threads created with
380 ATTR can run on. */
381 extern int pthread_attr_getaffinity_np (const pthread_attr_t *__attr,
382 size_t __cpusetsize,
383 cpu_set_t *__cpuset)
384 __THROW __nonnull ((1, 3));
385
386 /* Get the default attributes used by pthread_create in this process. */
387 extern int pthread_getattr_default_np (pthread_attr_t *__attr)
388 __THROW __nonnull ((1));
389
390 /* Store *SIGMASK as the signal mask for the new thread in *ATTR. */
391 extern int pthread_attr_setsigmask_np (pthread_attr_t *__attr,
392 const __sigset_t *sigmask);
393
394 /* Store the signal mask of *ATTR in *SIGMASK. If there is no signal
395 mask stored, return PTHREAD_ATTR_NOSIGMASK_NP. Return zero on
396 success. */
397 extern int pthread_attr_getsigmask_np (const pthread_attr_t *__attr,
398 __sigset_t *sigmask);
399
400 /* Special return value from pthread_attr_getsigmask_np if the signal
401 mask has not been set. */
402 #define PTHREAD_ATTR_NO_SIGMASK_NP (-1)
403
404 /* Set the default attributes to be used by pthread_create in this
405 process. */
406 extern int pthread_setattr_default_np (const pthread_attr_t *__attr)
407 __THROW __nonnull ((1));
408
409 /* Initialize thread attribute *ATTR with attributes corresponding to the
410 already running thread TH. It shall be called on uninitialized ATTR
411 and destroyed with pthread_attr_destroy when no longer needed. */
412 extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
413 __THROW __nonnull ((2));
414 #endif
415
416
417 /* Functions for scheduling control. */
418
419 /* Set the scheduling parameters for TARGET_THREAD according to POLICY
420 and *PARAM. */
421 extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
422 const struct sched_param *__param)
423 __THROW __nonnull ((3));
424
425 /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
426 extern int pthread_getschedparam (pthread_t __target_thread,
427 int *__restrict __policy,
428 struct sched_param *__restrict __param)
429 __THROW __nonnull ((2, 3));
430
431 /* Set the scheduling priority for TARGET_THREAD. */
432 extern int pthread_setschedprio (pthread_t __target_thread, int __prio)
433 __THROW;
434
435
436 #ifdef __USE_GNU
437 /* Get thread name visible in the kernel and its interfaces. */
438 extern int pthread_getname_np (pthread_t __target_thread, char *__buf,
439 size_t __buflen)
440 __THROW __nonnull ((2));
441
442 /* Set thread name visible in the kernel and its interfaces. */
443 extern int pthread_setname_np (pthread_t __target_thread, const char *__name)
444 __THROW __nonnull ((2));
445 #endif
446
447
448 #ifdef __USE_UNIX98
449 /* Determine level of concurrency. */
450 extern int pthread_getconcurrency (void) __THROW;
451
452 /* Set new concurrency level to LEVEL. */
453 extern int pthread_setconcurrency (int __level) __THROW;
454 #endif
455
456 #ifdef __USE_GNU
457 extern int pthread_yield (void) __THROW;
458 # ifdef __REDIRECT_NTH
459 extern int __REDIRECT_NTH (pthread_yield, (void), sched_yield)
460 __attribute_deprecated_msg__ ("\
461 pthread_yield is deprecated, use sched_yield instead");
462 # else
463 # define pthread_yield sched_yield
464 # endif
465
466
467 /* Limit specified thread TH to run only on the processors represented
468 in CPUSET. */
469 extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
470 const cpu_set_t *__cpuset)
471 __THROW __nonnull ((3));
472
473 /* Get bit set in CPUSET representing the processors TH can run on. */
474 extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
475 cpu_set_t *__cpuset)
476 __THROW __nonnull ((3));
477 #endif
478
479
480 /* Functions for handling initialization. */
481
482 /* Guarantee that the initialization function INIT_ROUTINE will be called
483 only once, even if pthread_once is executed several times with the
484 same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
485 extern variable initialized to PTHREAD_ONCE_INIT.
486
487 The initialization functions might throw exception which is why
488 this function is not marked with __THROW. */
489 extern int pthread_once (pthread_once_t *__once_control,
490 void (*__init_routine) (void)) __nonnull ((1, 2));
491
492
493 /* Functions for handling cancellation.
494
495 Note that these functions are explicitly not marked to not throw an
496 exception in C++ code. If cancellation is implemented by unwinding
497 this is necessary to have the compiler generate the unwind information. */
498
499 /* Set cancelability state of current thread to STATE, returning old
500 state in *OLDSTATE if OLDSTATE is not NULL. */
501 extern int pthread_setcancelstate (int __state, int *__oldstate);
502
503 /* Set cancellation state of current thread to TYPE, returning the old
504 type in *OLDTYPE if OLDTYPE is not NULL. */
505 extern int pthread_setcanceltype (int __type, int *__oldtype);
506
507 /* Cancel THREAD immediately or at the next possibility. */
508 extern int pthread_cancel (pthread_t __th);
509
510 /* Test for pending cancellation for the current thread and terminate
511 the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
512 cancelled. */
513 extern void pthread_testcancel (void);
514
515
516 /* Cancellation handling with integration into exception handling. */
517
518 struct __cancel_jmp_buf_tag
519 {
520 __jmp_buf __cancel_jmp_buf;
521 int __mask_was_saved;
522 };
523
524 typedef struct
525 {
526 struct __cancel_jmp_buf_tag __cancel_jmp_buf[1];
527 void *__pad[4];
528 } __pthread_unwind_buf_t __attribute__ ((__aligned__));
529
530 /* No special attributes by default. */
531 #ifndef __cleanup_fct_attribute
532 # define __cleanup_fct_attribute
533 #endif
534
535
536 /* Structure to hold the cleanup handler information. */
537 struct __pthread_cleanup_frame
538 {
539 void (*__cancel_routine) (void *);
540 void *__cancel_arg;
541 int __do_it;
542 int __cancel_type;
543 };
544
545 #if defined __GNUC__ && defined __EXCEPTIONS
546 # ifdef __cplusplus
547 /* Class to handle cancellation handler invocation. */
548 class __pthread_cleanup_class
549 {
550 void (*__cancel_routine) (void *);
551 void *__cancel_arg;
552 int __do_it;
553 int __cancel_type;
554
555 public:
556 __pthread_cleanup_class (void (*__fct) (void *), void *__arg)
557 : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { }
558 ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); }
559 void __setdoit (int __newval) { __do_it = __newval; }
560 void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,
561 &__cancel_type); }
562 void __restore () const { pthread_setcanceltype (__cancel_type, 0); }
563 };
564
565 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
566 when the thread is canceled or calls pthread_exit. ROUTINE will also
567 be called with arguments ARG when the matching pthread_cleanup_pop
568 is executed with non-zero EXECUTE argument.
569
570 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
571 be used in matching pairs at the same nesting level of braces. */
572 # define pthread_cleanup_push(routine, arg) \
573 do { \
574 __pthread_cleanup_class __clframe (routine, arg)
575
576 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
577 If EXECUTE is non-zero, the handler function is called. */
578 # define pthread_cleanup_pop(execute) \
579 __clframe.__setdoit (execute); \
580 } while (0)
581
582 # ifdef __USE_GNU
583 /* Install a cleanup handler as pthread_cleanup_push does, but also
584 saves the current cancellation type and sets it to deferred
585 cancellation. */
586 # define pthread_cleanup_push_defer_np(routine, arg) \
587 do { \
588 __pthread_cleanup_class __clframe (routine, arg); \
589 __clframe.__defer ()
590
591 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
592 restores the cancellation type that was in effect when the matching
593 pthread_cleanup_push_defer was called. */
594 # define pthread_cleanup_pop_restore_np(execute) \
595 __clframe.__restore (); \
596 __clframe.__setdoit (execute); \
597 } while (0)
598 # endif
599 # else
600 /* Function called to call the cleanup handler. As an extern inline
601 function the compiler is free to decide inlining the change when
602 needed or fall back on the copy which must exist somewhere
603 else. */
604 __extern_inline void
605 __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
606 {
607 if (__frame->__do_it)
608 __frame->__cancel_routine (__frame->__cancel_arg);
609 }
610
611 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
612 when the thread is canceled or calls pthread_exit. ROUTINE will also
613 be called with arguments ARG when the matching pthread_cleanup_pop
614 is executed with non-zero EXECUTE argument.
615
616 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
617 be used in matching pairs at the same nesting level of braces. */
618 # define pthread_cleanup_push(routine, arg) \
619 do { \
620 struct __pthread_cleanup_frame __clframe \
621 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
622 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
623 .__do_it = 1 };
624
625 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
626 If EXECUTE is non-zero, the handler function is called. */
627 # define pthread_cleanup_pop(execute) \
628 __clframe.__do_it = (execute); \
629 } while (0)
630
631 # ifdef __USE_GNU
632 /* Install a cleanup handler as pthread_cleanup_push does, but also
633 saves the current cancellation type and sets it to deferred
634 cancellation. */
635 # define pthread_cleanup_push_defer_np(routine, arg) \
636 do { \
637 struct __pthread_cleanup_frame __clframe \
638 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
639 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
640 .__do_it = 1 }; \
641 (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \
642 &__clframe.__cancel_type)
643
644 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
645 restores the cancellation type that was in effect when the matching
646 pthread_cleanup_push_defer was called. */
647 # define pthread_cleanup_pop_restore_np(execute) \
648 (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \
649 __clframe.__do_it = (execute); \
650 } while (0)
651 # endif
652 # endif
653 #else
654 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
655 when the thread is canceled or calls pthread_exit. ROUTINE will also
656 be called with arguments ARG when the matching pthread_cleanup_pop
657 is executed with non-zero EXECUTE argument.
658
659 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
660 be used in matching pairs at the same nesting level of braces. */
661 # define pthread_cleanup_push(routine, arg) \
662 do { \
663 __pthread_unwind_buf_t __cancel_buf; \
664 void (*__cancel_routine) (void *) = (routine); \
665 void *__cancel_arg = (arg); \
666 int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \
667 0); \
668 if (__glibc_unlikely (__not_first_call)) \
669 { \
670 __cancel_routine (__cancel_arg); \
671 __pthread_unwind_next (&__cancel_buf); \
672 /* NOTREACHED */ \
673 } \
674 \
675 __pthread_register_cancel (&__cancel_buf); \
676 do {
677 extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
678 __cleanup_fct_attribute;
679
680 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
681 If EXECUTE is non-zero, the handler function is called. */
682 # define pthread_cleanup_pop(execute) \
683 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
684 } while (0); \
685 __pthread_unregister_cancel (&__cancel_buf); \
686 if (execute) \
687 __cancel_routine (__cancel_arg); \
688 } while (0)
689 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
690 __cleanup_fct_attribute;
691
692 # ifdef __USE_GNU
693 /* Install a cleanup handler as pthread_cleanup_push does, but also
694 saves the current cancellation type and sets it to deferred
695 cancellation. */
696 # define pthread_cleanup_push_defer_np(routine, arg) \
697 do { \
698 __pthread_unwind_buf_t __cancel_buf; \
699 void (*__cancel_routine) (void *) = (routine); \
700 void *__cancel_arg = (arg); \
701 int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \
702 0); \
703 if (__glibc_unlikely (__not_first_call)) \
704 { \
705 __cancel_routine (__cancel_arg); \
706 __pthread_unwind_next (&__cancel_buf); \
707 /* NOTREACHED */ \
708 } \
709 \
710 __pthread_register_cancel_defer (&__cancel_buf); \
711 do {
712 extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf)
713 __cleanup_fct_attribute;
714
715 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
716 restores the cancellation type that was in effect when the matching
717 pthread_cleanup_push_defer was called. */
718 # define pthread_cleanup_pop_restore_np(execute) \
719 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
720 } while (0); \
721 __pthread_unregister_cancel_restore (&__cancel_buf); \
722 if (execute) \
723 __cancel_routine (__cancel_arg); \
724 } while (0)
725 extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf)
726 __cleanup_fct_attribute;
727 # endif
728
729 /* Internal interface to initiate cleanup. */
730 extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
731 __cleanup_fct_attribute __attribute__ ((__noreturn__))
732 # ifndef SHARED
733 __attribute__ ((__weak__))
734 # endif
735 ;
736 #endif
737
738 /* Function used in the macros. Calling __sigsetjmp, with its first
739 argument declared as an array, results in a -Wstringop-overflow
740 warning from GCC 11 because struct pthread_unwind_buf is smaller
741 than jmp_buf. The calls from the macros have __SAVEMASK set to 0,
742 so nothing beyond the common prefix is used and this warning is a
743 false positive. Use an alias with its first argument declared to
744 use the type in the macros if possible to avoid this warning. */
745 #if __GNUC_PREREQ (11, 0)
746 extern int __REDIRECT_NTHNL (__sigsetjmp_cancel,
747 (struct __cancel_jmp_buf_tag __env[1],
748 int __savemask),
749 __sigsetjmp) __attribute_returns_twice__;
750 #else
751 # define __sigsetjmp_cancel(env, savemask) \
752 __sigsetjmp ((struct __jmp_buf_tag *) (void *) (env), (savemask))
753 extern int __sigsetjmp (struct __jmp_buf_tag __env[1],
754 int __savemask) __THROWNL;
755 #endif
756
757
758 /* Mutex handling. */
759
760 /* Initialize a mutex. */
761 extern int pthread_mutex_init (pthread_mutex_t *__mutex,
762 const pthread_mutexattr_t *__mutexattr)
763 __THROW __nonnull ((1));
764
765 /* Destroy a mutex. */
766 extern int pthread_mutex_destroy (pthread_mutex_t *__mutex)
767 __THROW __nonnull ((1));
768
769 /* Try locking a mutex. */
770 extern int pthread_mutex_trylock (pthread_mutex_t *__mutex)
771 __THROWNL __nonnull ((1));
772
773 /* Lock a mutex. */
774 extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
775 __THROWNL __nonnull ((1));
776
777 #ifdef __USE_XOPEN2K
778 /* Wait until lock becomes available, or specified time passes. */
779 extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
780 const struct timespec *__restrict
781 __abstime) __THROWNL __nonnull ((1, 2));
782 #endif
783
784 #ifdef __USE_GNU
785 extern int pthread_mutex_clocklock (pthread_mutex_t *__restrict __mutex,
786 clockid_t __clockid,
787 const struct timespec *__restrict
788 __abstime) __THROWNL __nonnull ((1, 3));
789 #endif
790
791 /* Unlock a mutex. */
792 extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
793 __THROWNL __nonnull ((1));
794
795
796 /* Get the priority ceiling of MUTEX. */
797 extern int pthread_mutex_getprioceiling (const pthread_mutex_t *
798 __restrict __mutex,
799 int *__restrict __prioceiling)
800 __THROW __nonnull ((1, 2));
801
802 /* Set the priority ceiling of MUTEX to PRIOCEILING, return old
803 priority ceiling value in *OLD_CEILING. */
804 extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex,
805 int __prioceiling,
806 int *__restrict __old_ceiling)
807 __THROW __nonnull ((1, 3));
808
809
810 #ifdef __USE_XOPEN2K8
811 /* Declare the state protected by MUTEX as consistent. */
812 extern int pthread_mutex_consistent (pthread_mutex_t *__mutex)
813 __THROW __nonnull ((1));
814 # ifdef __USE_GNU
815 # ifdef __REDIRECT_NTH
816 extern int __REDIRECT_NTH (pthread_mutex_consistent_np, (pthread_mutex_t *),
817 pthread_mutex_consistent) __nonnull ((1))
818 __attribute_deprecated_msg__ ("\
819 pthread_mutex_consistent_np is deprecated, use pthread_mutex_consistent");
820 # else
821 # define pthread_mutex_consistent_np pthread_mutex_consistent
822 # endif
823 # endif
824 #endif
825
826
827 /* Functions for handling mutex attributes. */
828
829 /* Initialize mutex attribute object ATTR with default attributes
830 (kind is PTHREAD_MUTEX_TIMED_NP). */
831 extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr)
832 __THROW __nonnull ((1));
833
834 /* Destroy mutex attribute object ATTR. */
835 extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr)
836 __THROW __nonnull ((1));
837
838 /* Get the process-shared flag of the mutex attribute ATTR. */
839 extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t *
840 __restrict __attr,
841 int *__restrict __pshared)
842 __THROW __nonnull ((1, 2));
843
844 /* Set the process-shared flag of the mutex attribute ATTR. */
845 extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
846 int __pshared)
847 __THROW __nonnull ((1));
848
849 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
850 /* Return in *KIND the mutex kind attribute in *ATTR. */
851 extern int pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict
852 __attr, int *__restrict __kind)
853 __THROW __nonnull ((1, 2));
854
855 /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
856 PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
857 PTHREAD_MUTEX_DEFAULT). */
858 extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
859 __THROW __nonnull ((1));
860 #endif
861
862 /* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */
863 extern int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *
864 __restrict __attr,
865 int *__restrict __protocol)
866 __THROW __nonnull ((1, 2));
867
868 /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
869 PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */
870 extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr,
871 int __protocol)
872 __THROW __nonnull ((1));
873
874 /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */
875 extern int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *
876 __restrict __attr,
877 int *__restrict __prioceiling)
878 __THROW __nonnull ((1, 2));
879
880 /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */
881 extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr,
882 int __prioceiling)
883 __THROW __nonnull ((1));
884
885 #ifdef __USE_XOPEN2K
886 /* Get the robustness flag of the mutex attribute ATTR. */
887 extern int pthread_mutexattr_getrobust (const pthread_mutexattr_t *__attr,
888 int *__robustness)
889 __THROW __nonnull ((1, 2));
890 # ifdef __USE_GNU
891 # ifdef __REDIRECT_NTH
892 extern int __REDIRECT_NTH (pthread_mutexattr_getrobust_np,
893 (pthread_mutex_t *, int *),
894 pthread_mutexattr_getrobust) __nonnull ((1))
895 __attribute_deprecated_msg__ ("\
896 pthread_mutexattr_getrobust_np is deprecated, use pthread_mutexattr_getrobust");
897 # else
898 # define pthread_mutexattr_getrobust_np pthread_mutexattr_getrobust
899 # endif
900 # endif
901
902 /* Set the robustness flag of the mutex attribute ATTR. */
903 extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr,
904 int __robustness)
905 __THROW __nonnull ((1));
906 # ifdef __USE_GNU
907 # ifdef __REDIRECT_NTH
908 extern int __REDIRECT_NTH (pthread_mutexattr_setrobust_np,
909 (pthread_mutex_t *, int),
910 pthread_mutexattr_setrobust) __nonnull ((1))
911 __attribute_deprecated_msg__ ("\
912 pthread_mutexattr_setrobust_np is deprecated, use pthread_mutexattr_setrobust");
913 # else
914 # define pthread_mutexattr_setrobust_np pthread_mutexattr_setrobust
915 # endif
916 # endif
917 #endif
918
919 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
920 /* Functions for handling read-write locks. */
921
922 /* Initialize read-write lock RWLOCK using attributes ATTR, or use
923 the default values if later is NULL. */
924 extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
925 const pthread_rwlockattr_t *__restrict
926 __attr) __THROW __nonnull ((1));
927
928 /* Destroy read-write lock RWLOCK. */
929 extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock)
930 __THROW __nonnull ((1));
931
932 /* Acquire read lock for RWLOCK. */
933 extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock)
934 __THROWNL __nonnull ((1));
935
936 /* Try to acquire read lock for RWLOCK. */
937 extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
938 __THROWNL __nonnull ((1));
939
940 # ifdef __USE_XOPEN2K
941 /* Try to acquire read lock for RWLOCK or return after specfied time. */
942 extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
943 const struct timespec *__restrict
944 __abstime) __THROWNL __nonnull ((1, 2));
945 # endif
946
947 # ifdef __USE_GNU
948 extern int pthread_rwlock_clockrdlock (pthread_rwlock_t *__restrict __rwlock,
949 clockid_t __clockid,
950 const struct timespec *__restrict
951 __abstime) __THROWNL __nonnull ((1, 3));
952 # endif
953
954 /* Acquire write lock for RWLOCK. */
955 extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
956 __THROWNL __nonnull ((1));
957
958 /* Try to acquire write lock for RWLOCK. */
959 extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
960 __THROWNL __nonnull ((1));
961
962 # ifdef __USE_XOPEN2K
963 /* Try to acquire write lock for RWLOCK or return after specfied time. */
964 extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
965 const struct timespec *__restrict
966 __abstime) __THROWNL __nonnull ((1, 2));
967 # endif
968
969 # ifdef __USE_GNU
970 extern int pthread_rwlock_clockwrlock (pthread_rwlock_t *__restrict __rwlock,
971 clockid_t __clockid,
972 const struct timespec *__restrict
973 __abstime) __THROWNL __nonnull ((1, 3));
974 # endif
975
976 /* Unlock RWLOCK. */
977 extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
978 __THROWNL __nonnull ((1));
979
980
981 /* Functions for handling read-write lock attributes. */
982
983 /* Initialize attribute object ATTR with default values. */
984 extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr)
985 __THROW __nonnull ((1));
986
987 /* Destroy attribute object ATTR. */
988 extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr)
989 __THROW __nonnull ((1));
990
991 /* Return current setting of process-shared attribute of ATTR in PSHARED. */
992 extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *
993 __restrict __attr,
994 int *__restrict __pshared)
995 __THROW __nonnull ((1, 2));
996
997 /* Set process-shared attribute of ATTR to PSHARED. */
998 extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
999 int __pshared)
1000 __THROW __nonnull ((1));
1001
1002 /* Return current setting of reader/writer preference. */
1003 extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t *
1004 __restrict __attr,
1005 int *__restrict __pref)
1006 __THROW __nonnull ((1, 2));
1007
1008 /* Set reader/write preference. */
1009 extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
1010 int __pref) __THROW __nonnull ((1));
1011 #endif
1012
1013
1014 /* Functions for handling conditional variables. */
1015
1016 /* Initialize condition variable COND using attributes ATTR, or use
1017 the default values if later is NULL. */
1018 extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
1019 const pthread_condattr_t *__restrict __cond_attr)
1020 __THROW __nonnull ((1));
1021
1022 /* Destroy condition variable COND. */
1023 extern int pthread_cond_destroy (pthread_cond_t *__cond)
1024 __THROW __nonnull ((1));
1025
1026 /* Wake up one thread waiting for condition variable COND. */
1027 extern int pthread_cond_signal (pthread_cond_t *__cond)
1028 __THROWNL __nonnull ((1));
1029
1030 /* Wake up all threads waiting for condition variables COND. */
1031 extern int pthread_cond_broadcast (pthread_cond_t *__cond)
1032 __THROWNL __nonnull ((1));
1033
1034 /* Wait for condition variable COND to be signaled or broadcast.
1035 MUTEX is assumed to be locked before.
1036
1037 This function is a cancellation point and therefore not marked with
1038 __THROW. */
1039 extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
1040 pthread_mutex_t *__restrict __mutex)
1041 __nonnull ((1, 2));
1042
1043 /* Wait for condition variable COND to be signaled or broadcast until
1044 ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an
1045 absolute time specification; zero is the beginning of the epoch
1046 (00:00:00 GMT, January 1, 1970).
1047
1048 This function is a cancellation point and therefore not marked with
1049 __THROW. */
1050 extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
1051 pthread_mutex_t *__restrict __mutex,
1052 const struct timespec *__restrict __abstime)
1053 __nonnull ((1, 2, 3));
1054
1055 # ifdef __USE_GNU
1056 /* Wait for condition variable COND to be signaled or broadcast until
1057 ABSTIME measured by the specified clock. MUTEX is assumed to be
1058 locked before. CLOCK is the clock to use. ABSTIME is an absolute
1059 time specification against CLOCK's epoch.
1060
1061 This function is a cancellation point and therefore not marked with
1062 __THROW. */
1063 extern int pthread_cond_clockwait (pthread_cond_t *__restrict __cond,
1064 pthread_mutex_t *__restrict __mutex,
1065 __clockid_t __clock_id,
1066 const struct timespec *__restrict __abstime)
1067 __nonnull ((1, 2, 4));
1068 # endif
1069
1070 /* Functions for handling condition variable attributes. */
1071
1072 /* Initialize condition variable attribute ATTR. */
1073 extern int pthread_condattr_init (pthread_condattr_t *__attr)
1074 __THROW __nonnull ((1));
1075
1076 /* Destroy condition variable attribute ATTR. */
1077 extern int pthread_condattr_destroy (pthread_condattr_t *__attr)
1078 __THROW __nonnull ((1));
1079
1080 /* Get the process-shared flag of the condition variable attribute ATTR. */
1081 extern int pthread_condattr_getpshared (const pthread_condattr_t *
1082 __restrict __attr,
1083 int *__restrict __pshared)
1084 __THROW __nonnull ((1, 2));
1085
1086 /* Set the process-shared flag of the condition variable attribute ATTR. */
1087 extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
1088 int __pshared) __THROW __nonnull ((1));
1089
1090 #ifdef __USE_XOPEN2K
1091 /* Get the clock selected for the condition variable attribute ATTR. */
1092 extern int pthread_condattr_getclock (const pthread_condattr_t *
1093 __restrict __attr,
1094 __clockid_t *__restrict __clock_id)
1095 __THROW __nonnull ((1, 2));
1096
1097 /* Set the clock selected for the condition variable attribute ATTR. */
1098 extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
1099 __clockid_t __clock_id)
1100 __THROW __nonnull ((1));
1101 #endif
1102
1103
1104 #ifdef __USE_XOPEN2K
1105 /* Functions to handle spinlocks. */
1106
1107 /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can
1108 be shared between different processes. */
1109 extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
1110 __THROW __nonnull ((1));
1111
1112 /* Destroy the spinlock LOCK. */
1113 extern int pthread_spin_destroy (pthread_spinlock_t *__lock)
1114 __THROW __nonnull ((1));
1115
1116 /* Wait until spinlock LOCK is retrieved. */
1117 extern int pthread_spin_lock (pthread_spinlock_t *__lock)
1118 __THROWNL __nonnull ((1));
1119
1120 /* Try to lock spinlock LOCK. */
1121 extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
1122 __THROWNL __nonnull ((1));
1123
1124 /* Release spinlock LOCK. */
1125 extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
1126 __THROWNL __nonnull ((1));
1127
1128
1129 /* Functions to handle barriers. */
1130
1131 /* Initialize BARRIER with the attributes in ATTR. The barrier is
1132 opened when COUNT waiters arrived. */
1133 extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
1134 const pthread_barrierattr_t *__restrict
1135 __attr, unsigned int __count)
1136 __THROW __nonnull ((1));
1137
1138 /* Destroy a previously dynamically initialized barrier BARRIER. */
1139 extern int pthread_barrier_destroy (pthread_barrier_t *__barrier)
1140 __THROW __nonnull ((1));
1141
1142 /* Wait on barrier BARRIER. */
1143 extern int pthread_barrier_wait (pthread_barrier_t *__barrier)
1144 __THROWNL __nonnull ((1));
1145
1146
1147 /* Initialize barrier attribute ATTR. */
1148 extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr)
1149 __THROW __nonnull ((1));
1150
1151 /* Destroy previously dynamically initialized barrier attribute ATTR. */
1152 extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr)
1153 __THROW __nonnull ((1));
1154
1155 /* Get the process-shared flag of the barrier attribute ATTR. */
1156 extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t *
1157 __restrict __attr,
1158 int *__restrict __pshared)
1159 __THROW __nonnull ((1, 2));
1160
1161 /* Set the process-shared flag of the barrier attribute ATTR. */
1162 extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
1163 int __pshared)
1164 __THROW __nonnull ((1));
1165 #endif
1166
1167
1168 /* Functions for handling thread-specific data. */
1169
1170 /* Create a key value identifying a location in the thread-specific
1171 data area. Each thread maintains a distinct thread-specific data
1172 area. DESTR_FUNCTION, if non-NULL, is called with the value
1173 associated to that key when the key is destroyed.
1174 DESTR_FUNCTION is not called if the value associated is NULL when
1175 the key is destroyed. */
1176 extern int pthread_key_create (pthread_key_t *__key,
1177 void (*__destr_function) (void *))
1178 __THROW __nonnull ((1));
1179
1180 /* Destroy KEY. */
1181 extern int pthread_key_delete (pthread_key_t __key) __THROW;
1182
1183 /* Return current value of the thread-specific data slot identified by KEY. */
1184 extern void *pthread_getspecific (pthread_key_t __key) __THROW;
1185
1186 /* Store POINTER in the thread-specific data slot identified by KEY. */
1187 extern int pthread_setspecific (pthread_key_t __key,
1188 const void *__pointer)
1189 __THROW __attr_access_none (2);
1190
1191
1192 #ifdef __USE_XOPEN2K
1193 /* Get ID of CPU-time clock for thread THREAD_ID. */
1194 extern int pthread_getcpuclockid (pthread_t __thread_id,
1195 __clockid_t *__clock_id)
1196 __THROW __nonnull ((2));
1197 #endif
1198
1199
1200 /* Install handlers to be called when a new process is created with FORK.
1201 The PREPARE handler is called in the parent process just before performing
1202 FORK. The PARENT handler is called in the parent process just after FORK.
1203 The CHILD handler is called in the child process. Each of the three
1204 handlers can be NULL, meaning that no handler needs to be called at that
1205 point.
1206 PTHREAD_ATFORK can be called several times, in which case the PREPARE
1207 handlers are called in LIFO order (last added with PTHREAD_ATFORK,
1208 first called before FORK), and the PARENT and CHILD handlers are called
1209 in FIFO (first added, first called). */
1210
1211 extern int pthread_atfork (void (*__prepare) (void),
1212 void (*__parent) (void),
1213 void (*__child) (void)) __THROW;
1214
1215
1216 #ifdef __USE_EXTERN_INLINES
1217 /* Optimizations. */
1218 __extern_inline int
1219 __NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2))
1220 {
1221 return __thread1 == __thread2;
1222 }
1223 #endif
1224
1225 __END_DECLS
1226
1227 #endif /* pthread.h */