1 /* Copyright (C) 2002-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
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>
33 # include <bits/pthread_stack_min-dynamic.h>
39 PTHREAD_CREATE_JOINABLE
,
40 #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
41 PTHREAD_CREATE_DETACHED
42 #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
49 PTHREAD_MUTEX_TIMED_NP
,
50 PTHREAD_MUTEX_RECURSIVE_NP
,
51 PTHREAD_MUTEX_ERRORCHECK_NP
,
52 PTHREAD_MUTEX_ADAPTIVE_NP
53 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
55 PTHREAD_MUTEX_NORMAL
= PTHREAD_MUTEX_TIMED_NP
,
56 PTHREAD_MUTEX_RECURSIVE
= PTHREAD_MUTEX_RECURSIVE_NP
,
57 PTHREAD_MUTEX_ERRORCHECK
= PTHREAD_MUTEX_ERRORCHECK_NP
,
58 PTHREAD_MUTEX_DEFAULT
= PTHREAD_MUTEX_NORMAL
61 /* For compatibility. */
62 , PTHREAD_MUTEX_FAST_NP
= PTHREAD_MUTEX_TIMED_NP
68 /* Robust mutex or not flags. */
71 PTHREAD_MUTEX_STALLED
,
72 PTHREAD_MUTEX_STALLED_NP
= PTHREAD_MUTEX_STALLED
,
74 PTHREAD_MUTEX_ROBUST_NP
= PTHREAD_MUTEX_ROBUST
79 #if defined __USE_POSIX199506 || defined __USE_UNIX98
80 /* Mutex protocols. */
90 #define PTHREAD_MUTEX_INITIALIZER \
91 { { __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_TIMED_NP) } }
93 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
94 { { __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_RECURSIVE_NP) } }
95 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
96 { { __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_ERRORCHECK_NP) } }
97 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
98 { { __PTHREAD_MUTEX_INITIALIZER (PTHREAD_MUTEX_ADAPTIVE_NP) } }
102 /* Read-write lock types. */
103 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
106 PTHREAD_RWLOCK_PREFER_READER_NP
,
107 PTHREAD_RWLOCK_PREFER_WRITER_NP
,
108 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
,
109 PTHREAD_RWLOCK_DEFAULT_NP
= PTHREAD_RWLOCK_PREFER_READER_NP
113 /* Read-write lock initializers. */
114 # define PTHREAD_RWLOCK_INITIALIZER \
115 { { __PTHREAD_RWLOCK_INITIALIZER (PTHREAD_RWLOCK_DEFAULT_NP) } }
117 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
118 { { __PTHREAD_RWLOCK_INITIALIZER (PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) } }
120 #endif /* Unix98 or XOpen2K */
123 /* Scheduler inheritance. */
126 PTHREAD_INHERIT_SCHED
,
127 #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
128 PTHREAD_EXPLICIT_SCHED
129 #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
133 /* Scope handling. */
136 PTHREAD_SCOPE_SYSTEM
,
137 #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
138 PTHREAD_SCOPE_PROCESS
139 #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
143 /* Process shared or private flag. */
146 PTHREAD_PROCESS_PRIVATE
,
147 #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
148 PTHREAD_PROCESS_SHARED
149 #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
154 /* Conditional variable handling. */
155 #define PTHREAD_COND_INITIALIZER { { {0}, {0}, {0, 0}, {0, 0}, 0, 0, {0, 0} } }
158 /* Cleanup buffers */
159 struct _pthread_cleanup_buffer
161 void (*__routine
) (void *); /* Function to call. */
162 void *__arg
; /* Its argument. */
163 int __canceltype
; /* Saved cancellation type. */
164 struct _pthread_cleanup_buffer
*__prev
; /* Chaining of cleanup functions. */
170 PTHREAD_CANCEL_ENABLE
,
171 #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
172 PTHREAD_CANCEL_DISABLE
173 #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
177 PTHREAD_CANCEL_DEFERRED
,
178 #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
179 PTHREAD_CANCEL_ASYNCHRONOUS
180 #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
182 #define PTHREAD_CANCELED ((void *) -1)
185 /* Single execution handling. */
186 #define PTHREAD_ONCE_INIT 0
190 /* Value returned by 'pthread_barrier_wait' for one of the threads after
191 the required number of threads have called this function.
192 -1 is distinct from 0 and all errno constants */
193 # define PTHREAD_BARRIER_SERIAL_THREAD -1
199 /* Create a new thread, starting with execution of START-ROUTINE
200 getting passed ARG. Creation attributed come from ATTR. The new
201 handle is stored in *NEWTHREAD. */
202 extern int pthread_create (pthread_t
*__restrict __newthread
,
203 const pthread_attr_t
*__restrict __attr
,
204 void *(*__start_routine
) (void *),
205 void *__restrict __arg
) __THROWNL
__nonnull ((1, 3));
207 /* Terminate calling thread.
209 The registered cleanup handlers are called via exception handling
210 so we cannot mark this function with __THROW.*/
211 extern void pthread_exit (void *__retval
) __attribute__ ((__noreturn__
));
213 /* Make calling thread wait for termination of the thread TH. The
214 exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
217 This function is a cancellation point and therefore not marked with
219 extern int pthread_join (pthread_t __th
, void **__thread_return
);
222 /* Check whether thread TH has terminated. If yes return the status of
223 the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
224 extern int pthread_tryjoin_np (pthread_t __th
, void **__thread_return
) __THROW
;
226 # ifndef __USE_TIME_BITS64
227 /* Make calling thread wait for termination of the thread TH, but only
228 until TIMEOUT. The exit status of the thread is stored in
229 *THREAD_RETURN, if THREAD_RETURN is not NULL.
231 This function is a cancellation point and therefore not marked with
233 extern int pthread_timedjoin_np (pthread_t __th
, void **__thread_return
,
234 const struct timespec
*__abstime
);
236 /* Make calling thread wait for termination of the thread TH, but only
237 until TIMEOUT measured against the clock specified by CLOCKID. The
238 exit status of the thread is stored in *THREAD_RETURN, if
239 THREAD_RETURN is not NULL.
241 This function is a cancellation point and therefore not marked with
243 extern int pthread_clockjoin_np (pthread_t __th
, void **__thread_return
,
245 const struct timespec
*__abstime
);
248 extern int __REDIRECT (pthread_timedjoin_np
,
249 (pthread_t __th
, void **__thread_return
,
250 const struct timespec
*__abstime
),
251 __pthread_timedjoin_np64
);
253 extern int __REDIRECT (pthread_clockjoin_np
,
254 (pthread_t __th
, void **__thread_return
,
256 const struct timespec
*__abstime
),
257 __pthread_clockjoin_np64
);
259 # define pthread_timedjoin_np __pthread_timedjoin_np64
260 # define pthread_clockjoin_np __pthread_clockjoin_np64
265 /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
266 The resources of TH will therefore be freed immediately when it
267 terminates, instead of waiting for another thread to perform PTHREAD_JOIN
269 extern int pthread_detach (pthread_t __th
) __THROW
;
272 /* Obtain the identifier of the current thread. */
273 extern pthread_t
pthread_self (void) __THROW
__attribute__ ((__const__
));
275 /* Compare two thread identifiers. */
276 extern int pthread_equal (pthread_t __thread1
, pthread_t __thread2
)
277 __THROW
__attribute__ ((__const__
));
280 /* Thread attribute handling. */
282 /* Initialize thread attribute *ATTR with default attributes
283 (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
284 no user-provided stack). */
285 extern int pthread_attr_init (pthread_attr_t
*__attr
) __THROW
__nonnull ((1));
287 /* Destroy thread attribute *ATTR. */
288 extern int pthread_attr_destroy (pthread_attr_t
*__attr
)
289 __THROW
__nonnull ((1));
291 /* Get detach state attribute. */
292 extern int pthread_attr_getdetachstate (const pthread_attr_t
*__attr
,
294 __THROW
__nonnull ((1, 2));
296 /* Set detach state attribute. */
297 extern int pthread_attr_setdetachstate (pthread_attr_t
*__attr
,
299 __THROW
__nonnull ((1));
302 /* Get the size of the guard area created for stack overflow protection. */
303 extern int pthread_attr_getguardsize (const pthread_attr_t
*__attr
,
305 __THROW
__nonnull ((1, 2));
307 /* Set the size of the guard area created for stack overflow protection. */
308 extern int pthread_attr_setguardsize (pthread_attr_t
*__attr
,
310 __THROW
__nonnull ((1));
313 /* Return in *PARAM the scheduling parameters of *ATTR. */
314 extern int pthread_attr_getschedparam (const pthread_attr_t
*__restrict __attr
,
315 struct sched_param
*__restrict __param
)
316 __THROW
__nonnull ((1, 2));
318 /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
319 extern int pthread_attr_setschedparam (pthread_attr_t
*__restrict __attr
,
320 const struct sched_param
*__restrict
321 __param
) __THROW
__nonnull ((1, 2));
323 /* Return in *POLICY the scheduling policy of *ATTR. */
324 extern int pthread_attr_getschedpolicy (const pthread_attr_t
*__restrict
325 __attr
, int *__restrict __policy
)
326 __THROW
__nonnull ((1, 2));
328 /* Set scheduling policy in *ATTR according to POLICY. */
329 extern int pthread_attr_setschedpolicy (pthread_attr_t
*__attr
, int __policy
)
330 __THROW
__nonnull ((1));
332 /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
333 extern int pthread_attr_getinheritsched (const pthread_attr_t
*__restrict
334 __attr
, int *__restrict __inherit
)
335 __THROW
__nonnull ((1, 2));
337 /* Set scheduling inheritance mode in *ATTR according to INHERIT. */
338 extern int pthread_attr_setinheritsched (pthread_attr_t
*__attr
,
340 __THROW
__nonnull ((1));
343 /* Return in *SCOPE the scheduling contention scope of *ATTR. */
344 extern int pthread_attr_getscope (const pthread_attr_t
*__restrict __attr
,
345 int *__restrict __scope
)
346 __THROW
__nonnull ((1, 2));
348 /* Set scheduling contention scope in *ATTR according to SCOPE. */
349 extern int pthread_attr_setscope (pthread_attr_t
*__attr
, int __scope
)
350 __THROW
__nonnull ((1));
352 /* Return the previously set address for the stack. */
353 extern int pthread_attr_getstackaddr (const pthread_attr_t
*__restrict
354 __attr
, void **__restrict __stackaddr
)
355 __THROW
__nonnull ((1, 2)) __attribute_deprecated__
;
357 /* Set the starting address of the stack of the thread to be created.
358 Depending on whether the stack grows up or down the value must either
359 be higher or lower than all the address in the memory block. The
360 minimal size of the block must be PTHREAD_STACK_MIN. */
361 extern int pthread_attr_setstackaddr (pthread_attr_t
*__attr
,
363 __THROW
__nonnull ((1)) __attribute_deprecated__
;
365 /* Return the currently used minimal stack size. */
366 extern int pthread_attr_getstacksize (const pthread_attr_t
*__restrict
367 __attr
, size_t *__restrict __stacksize
)
368 __THROW
__nonnull ((1, 2));
370 /* Add information about the minimum stack size needed for the thread
371 to be started. This size must never be less than PTHREAD_STACK_MIN
372 and must also not exceed the system limits. */
373 extern int pthread_attr_setstacksize (pthread_attr_t
*__attr
,
375 __THROW
__nonnull ((1));
378 /* Return the previously set address for the stack. */
379 extern int pthread_attr_getstack (const pthread_attr_t
*__restrict __attr
,
380 void **__restrict __stackaddr
,
381 size_t *__restrict __stacksize
)
382 __THROW
__nonnull ((1, 2, 3));
384 /* The following two interfaces are intended to replace the last two. They
385 require setting the address as well as the size since only setting the
386 address will make the implementation on some architectures impossible. */
387 extern int pthread_attr_setstack (pthread_attr_t
*__attr
, void *__stackaddr
,
388 size_t __stacksize
) __THROW
__nonnull ((1));
392 /* Thread created with attribute ATTR will be limited to run only on
393 the processors represented in CPUSET. */
394 extern int pthread_attr_setaffinity_np (pthread_attr_t
*__attr
,
396 const cpu_set_t
*__cpuset
)
397 __THROW
__nonnull ((1, 3));
399 /* Get bit set in CPUSET representing the processors threads created with
401 extern int pthread_attr_getaffinity_np (const pthread_attr_t
*__attr
,
404 __THROW
__nonnull ((1, 3));
406 /* Get the default attributes used by pthread_create in this process. */
407 extern int pthread_getattr_default_np (pthread_attr_t
*__attr
)
408 __THROW
__nonnull ((1));
410 /* Store *SIGMASK as the signal mask for the new thread in *ATTR. */
411 extern int pthread_attr_setsigmask_np (pthread_attr_t
*__attr
,
412 const __sigset_t
*sigmask
);
414 /* Store the signal mask of *ATTR in *SIGMASK. If there is no signal
415 mask stored, return PTHREAD_ATTR_NOSIGMASK_NP. Return zero on
417 extern int pthread_attr_getsigmask_np (const pthread_attr_t
*__attr
,
418 __sigset_t
*sigmask
);
420 /* Special return value from pthread_attr_getsigmask_np if the signal
421 mask has not been set. */
422 #define PTHREAD_ATTR_NO_SIGMASK_NP (-1)
424 /* Set the default attributes to be used by pthread_create in this
426 extern int pthread_setattr_default_np (const pthread_attr_t
*__attr
)
427 __THROW
__nonnull ((1));
429 /* Initialize thread attribute *ATTR with attributes corresponding to the
430 already running thread TH. It shall be called on uninitialized ATTR
431 and destroyed with pthread_attr_destroy when no longer needed. */
432 extern int pthread_getattr_np (pthread_t __th
, pthread_attr_t
*__attr
)
433 __THROW
__nonnull ((2));
437 /* Functions for scheduling control. */
439 /* Set the scheduling parameters for TARGET_THREAD according to POLICY
441 extern int pthread_setschedparam (pthread_t __target_thread
, int __policy
,
442 const struct sched_param
*__param
)
443 __THROW
__nonnull ((3));
445 /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
446 extern int pthread_getschedparam (pthread_t __target_thread
,
447 int *__restrict __policy
,
448 struct sched_param
*__restrict __param
)
449 __THROW
__nonnull ((2, 3));
451 /* Set the scheduling priority for TARGET_THREAD. */
452 extern int pthread_setschedprio (pthread_t __target_thread
, int __prio
)
457 /* Get thread name visible in the kernel and its interfaces. */
458 extern int pthread_getname_np (pthread_t __target_thread
, char *__buf
,
460 __THROW
__nonnull ((2));
462 /* Set thread name visible in the kernel and its interfaces. */
463 extern int pthread_setname_np (pthread_t __target_thread
, const char *__name
)
464 __THROW
__nonnull ((2));
469 /* Determine level of concurrency. */
470 extern int pthread_getconcurrency (void) __THROW
;
472 /* Set new concurrency level to LEVEL. */
473 extern int pthread_setconcurrency (int __level
) __THROW
;
477 extern int pthread_yield (void) __THROW
;
478 # ifdef __REDIRECT_NTH
479 extern int __REDIRECT_NTH (pthread_yield
, (void), sched_yield
)
480 __attribute_deprecated_msg__ ("\
481 pthread_yield is deprecated, use sched_yield instead");
483 # define pthread_yield sched_yield
487 /* Limit specified thread TH to run only on the processors represented
489 extern int pthread_setaffinity_np (pthread_t __th
, size_t __cpusetsize
,
490 const cpu_set_t
*__cpuset
)
491 __THROW
__nonnull ((3));
493 /* Get bit set in CPUSET representing the processors TH can run on. */
494 extern int pthread_getaffinity_np (pthread_t __th
, size_t __cpusetsize
,
496 __THROW
__nonnull ((3));
500 /* Functions for handling initialization. */
502 /* Guarantee that the initialization function INIT_ROUTINE will be called
503 only once, even if pthread_once is executed several times with the
504 same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
505 extern variable initialized to PTHREAD_ONCE_INIT.
507 The initialization functions might throw exception which is why
508 this function is not marked with __THROW. */
509 extern int pthread_once (pthread_once_t
*__once_control
,
510 void (*__init_routine
) (void)) __nonnull ((1, 2));
513 /* Functions for handling cancellation.
515 Note that these functions are explicitly not marked to not throw an
516 exception in C++ code. If cancellation is implemented by unwinding
517 this is necessary to have the compiler generate the unwind information. */
519 /* Set cancelability state of current thread to STATE, returning old
520 state in *OLDSTATE if OLDSTATE is not NULL. */
521 extern int pthread_setcancelstate (int __state
, int *__oldstate
);
523 /* Set cancellation state of current thread to TYPE, returning the old
524 type in *OLDTYPE if OLDTYPE is not NULL. */
525 extern int pthread_setcanceltype (int __type
, int *__oldtype
);
527 /* Cancel THREAD immediately or at the next possibility. */
528 extern int pthread_cancel (pthread_t __th
);
530 /* Test for pending cancellation for the current thread and terminate
531 the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
533 extern void pthread_testcancel (void);
536 /* Cancellation handling with integration into exception handling. */
538 struct __cancel_jmp_buf_tag
540 __jmp_buf __cancel_jmp_buf
;
541 int __mask_was_saved
;
546 struct __cancel_jmp_buf_tag __cancel_jmp_buf
[1];
548 } __pthread_unwind_buf_t
__attribute__ ((__aligned__
));
550 /* No special attributes by default. */
551 #ifndef __cleanup_fct_attribute
552 # define __cleanup_fct_attribute
556 /* Structure to hold the cleanup handler information. */
557 struct __pthread_cleanup_frame
559 void (*__cancel_routine
) (void *);
565 #if defined __GNUC__ && defined __EXCEPTIONS
567 /* Class to handle cancellation handler invocation. */
568 class __pthread_cleanup_class
570 void (*__cancel_routine
) (void *);
576 __pthread_cleanup_class (void (*__fct
) (void *), void *__arg
)
577 : __cancel_routine (__fct
), __cancel_arg (__arg
), __do_it (1) { }
578 ~__pthread_cleanup_class () { if (__do_it
) __cancel_routine (__cancel_arg
); }
579 void __setdoit (int __newval
) { __do_it
= __newval
; }
580 void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
,
582 void __restore () const { pthread_setcanceltype (__cancel_type
, 0); }
585 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
586 when the thread is canceled or calls pthread_exit. ROUTINE will also
587 be called with arguments ARG when the matching pthread_cleanup_pop
588 is executed with non-zero EXECUTE argument.
590 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
591 be used in matching pairs at the same nesting level of braces. */
592 # define pthread_cleanup_push(routine, arg) \
594 __pthread_cleanup_class __clframe (routine, arg)
596 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
597 If EXECUTE is non-zero, the handler function is called. */
598 # define pthread_cleanup_pop(execute) \
599 __clframe.__setdoit (execute); \
603 /* Install a cleanup handler as pthread_cleanup_push does, but also
604 saves the current cancellation type and sets it to deferred
606 # define pthread_cleanup_push_defer_np(routine, arg) \
608 __pthread_cleanup_class __clframe (routine, arg); \
611 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
612 restores the cancellation type that was in effect when the matching
613 pthread_cleanup_push_defer was called. */
614 # define pthread_cleanup_pop_restore_np(execute) \
615 __clframe.__restore (); \
616 __clframe.__setdoit (execute); \
620 /* Function called to call the cleanup handler. As an extern inline
621 function the compiler is free to decide inlining the change when
622 needed or fall back on the copy which must exist somewhere
625 __pthread_cleanup_routine (struct __pthread_cleanup_frame
*__frame
)
627 if (__frame
->__do_it
)
628 __frame
->__cancel_routine (__frame
->__cancel_arg
);
631 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
632 when the thread is canceled or calls pthread_exit. ROUTINE will also
633 be called with arguments ARG when the matching pthread_cleanup_pop
634 is executed with non-zero EXECUTE argument.
636 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
637 be used in matching pairs at the same nesting level of braces. */
638 # define pthread_cleanup_push(routine, arg) \
640 struct __pthread_cleanup_frame __clframe \
641 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
642 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
645 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
646 If EXECUTE is non-zero, the handler function is called. */
647 # define pthread_cleanup_pop(execute) \
648 __clframe.__do_it = (execute); \
652 /* Install a cleanup handler as pthread_cleanup_push does, but also
653 saves the current cancellation type and sets it to deferred
655 # define pthread_cleanup_push_defer_np(routine, arg) \
657 struct __pthread_cleanup_frame __clframe \
658 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
659 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
661 (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \
662 &__clframe.__cancel_type)
664 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
665 restores the cancellation type that was in effect when the matching
666 pthread_cleanup_push_defer was called. */
667 # define pthread_cleanup_pop_restore_np(execute) \
668 (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \
669 __clframe.__do_it = (execute); \
674 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
675 when the thread is canceled or calls pthread_exit. ROUTINE will also
676 be called with arguments ARG when the matching pthread_cleanup_pop
677 is executed with non-zero EXECUTE argument.
679 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
680 be used in matching pairs at the same nesting level of braces. */
681 # define pthread_cleanup_push(routine, arg) \
683 __pthread_unwind_buf_t __cancel_buf; \
684 void (*__cancel_routine) (void *) = (routine); \
685 void *__cancel_arg = (arg); \
686 int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \
688 if (__glibc_unlikely (__not_first_call)) \
690 __cancel_routine (__cancel_arg); \
691 __pthread_unwind_next (&__cancel_buf); \
695 __pthread_register_cancel (&__cancel_buf); \
697 extern void __pthread_register_cancel (__pthread_unwind_buf_t
*__buf
)
698 __cleanup_fct_attribute
;
700 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
701 If EXECUTE is non-zero, the handler function is called. */
702 # define pthread_cleanup_pop(execute) \
703 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
705 __pthread_unregister_cancel (&__cancel_buf); \
707 __cancel_routine (__cancel_arg); \
709 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t
*__buf
)
710 __cleanup_fct_attribute
;
713 /* Install a cleanup handler as pthread_cleanup_push does, but also
714 saves the current cancellation type and sets it to deferred
716 # define pthread_cleanup_push_defer_np(routine, arg) \
718 __pthread_unwind_buf_t __cancel_buf; \
719 void (*__cancel_routine) (void *) = (routine); \
720 void *__cancel_arg = (arg); \
721 int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \
723 if (__glibc_unlikely (__not_first_call)) \
725 __cancel_routine (__cancel_arg); \
726 __pthread_unwind_next (&__cancel_buf); \
730 __pthread_register_cancel_defer (&__cancel_buf); \
732 extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t
*__buf
)
733 __cleanup_fct_attribute
;
735 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
736 restores the cancellation type that was in effect when the matching
737 pthread_cleanup_push_defer was called. */
738 # define pthread_cleanup_pop_restore_np(execute) \
739 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
741 __pthread_unregister_cancel_restore (&__cancel_buf); \
743 __cancel_routine (__cancel_arg); \
745 extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t
*__buf
)
746 __cleanup_fct_attribute
;
749 /* Internal interface to initiate cleanup. */
750 extern void __pthread_unwind_next (__pthread_unwind_buf_t
*__buf
)
751 __cleanup_fct_attribute
__attribute__ ((__noreturn__
))
753 __attribute__ ((__weak__
))
758 /* Function used in the macros. Calling __sigsetjmp, with its first
759 argument declared as an array, results in a -Wstringop-overflow
760 warning from GCC 11 because struct pthread_unwind_buf is smaller
761 than jmp_buf. The calls from the macros have __SAVEMASK set to 0,
762 so nothing beyond the common prefix is used and this warning is a
763 false positive. Use an alias with its first argument declared to
764 use the type in the macros if possible to avoid this warning. */
765 #if __GNUC_PREREQ (11, 0)
766 extern int __REDIRECT_NTHNL (__sigsetjmp_cancel
,
767 (struct __cancel_jmp_buf_tag __env
[1],
769 __sigsetjmp
) __attribute_returns_twice__
;
771 # define __sigsetjmp_cancel(env, savemask) \
772 __sigsetjmp ((struct __jmp_buf_tag *) (void *) (env), (savemask))
773 extern int __sigsetjmp (struct __jmp_buf_tag __env
[1],
774 int __savemask
) __THROWNL
;
778 /* Mutex handling. */
780 /* Initialize a mutex. */
781 extern int pthread_mutex_init (pthread_mutex_t
*__mutex
,
782 const pthread_mutexattr_t
*__mutexattr
)
783 __THROW
__nonnull ((1));
785 /* Destroy a mutex. */
786 extern int pthread_mutex_destroy (pthread_mutex_t
*__mutex
)
787 __THROW
__nonnull ((1));
789 /* Try locking a mutex. */
790 extern int pthread_mutex_trylock (pthread_mutex_t
*__mutex
)
791 __THROWNL
__nonnull ((1));
794 extern int pthread_mutex_lock (pthread_mutex_t
*__mutex
)
795 __THROWNL
__nonnull ((1));
798 /* Wait until lock becomes available, or specified time passes. */
799 # ifndef __USE_TIME_BITS64
800 extern int pthread_mutex_timedlock (pthread_mutex_t
*__restrict __mutex
,
801 const struct timespec
*__restrict
802 __abstime
) __THROWNL
__nonnull ((1, 2));
804 # ifdef __REDIRECT_NTHNL
805 extern int __REDIRECT_NTHNL (pthread_mutex_timedlock
,
806 (pthread_mutex_t
*__restrict __mutex
,
807 const struct timespec
*__restrict __abstime
),
808 __pthread_mutex_timedlock64
) __nonnull ((1, 2));
810 # define pthread_mutex_timedlock __pthread_mutex_timedlock64
816 # ifndef __USE_TIME_BITS64
817 extern int pthread_mutex_clocklock (pthread_mutex_t
*__restrict __mutex
,
819 const struct timespec
*__restrict
820 __abstime
) __THROWNL
__nonnull ((1, 3));
822 # ifdef __REDIRECT_NTHNL
823 extern int __REDIRECT_NTHNL (pthread_mutex_clocklock
,
824 (pthread_mutex_t
*__restrict __mutex
,
826 const struct timespec
*__restrict __abstime
),
827 __pthread_mutex_clocklock64
) __nonnull ((1, 3));
829 # define pthread_mutex_clocklock __pthread_mutex_clocklock64
834 /* Unlock a mutex. */
835 extern int pthread_mutex_unlock (pthread_mutex_t
*__mutex
)
836 __THROWNL
__nonnull ((1));
839 /* Get the priority ceiling of MUTEX. */
840 extern int pthread_mutex_getprioceiling (const pthread_mutex_t
*
842 int *__restrict __prioceiling
)
843 __THROW
__nonnull ((1, 2));
845 /* Set the priority ceiling of MUTEX to PRIOCEILING, return old
846 priority ceiling value in *OLD_CEILING. */
847 extern int pthread_mutex_setprioceiling (pthread_mutex_t
*__restrict __mutex
,
849 int *__restrict __old_ceiling
)
850 __THROW
__nonnull ((1, 3));
853 #ifdef __USE_XOPEN2K8
854 /* Declare the state protected by MUTEX as consistent. */
855 extern int pthread_mutex_consistent (pthread_mutex_t
*__mutex
)
856 __THROW
__nonnull ((1));
858 # ifdef __REDIRECT_NTH
859 extern int __REDIRECT_NTH (pthread_mutex_consistent_np
, (pthread_mutex_t
*),
860 pthread_mutex_consistent
) __nonnull ((1))
861 __attribute_deprecated_msg__ ("\
862 pthread_mutex_consistent_np is deprecated, use pthread_mutex_consistent");
864 # define pthread_mutex_consistent_np pthread_mutex_consistent
870 /* Functions for handling mutex attributes. */
872 /* Initialize mutex attribute object ATTR with default attributes
873 (kind is PTHREAD_MUTEX_TIMED_NP). */
874 extern int pthread_mutexattr_init (pthread_mutexattr_t
*__attr
)
875 __THROW
__nonnull ((1));
877 /* Destroy mutex attribute object ATTR. */
878 extern int pthread_mutexattr_destroy (pthread_mutexattr_t
*__attr
)
879 __THROW
__nonnull ((1));
881 /* Get the process-shared flag of the mutex attribute ATTR. */
882 extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t
*
884 int *__restrict __pshared
)
885 __THROW
__nonnull ((1, 2));
887 /* Set the process-shared flag of the mutex attribute ATTR. */
888 extern int pthread_mutexattr_setpshared (pthread_mutexattr_t
*__attr
,
890 __THROW
__nonnull ((1));
892 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
893 /* Return in *KIND the mutex kind attribute in *ATTR. */
894 extern int pthread_mutexattr_gettype (const pthread_mutexattr_t
*__restrict
895 __attr
, int *__restrict __kind
)
896 __THROW
__nonnull ((1, 2));
898 /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
899 PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
900 PTHREAD_MUTEX_DEFAULT). */
901 extern int pthread_mutexattr_settype (pthread_mutexattr_t
*__attr
, int __kind
)
902 __THROW
__nonnull ((1));
905 /* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */
906 extern int pthread_mutexattr_getprotocol (const pthread_mutexattr_t
*
908 int *__restrict __protocol
)
909 __THROW
__nonnull ((1, 2));
911 /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
912 PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */
913 extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t
*__attr
,
915 __THROW
__nonnull ((1));
917 /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */
918 extern int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t
*
920 int *__restrict __prioceiling
)
921 __THROW
__nonnull ((1, 2));
923 /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */
924 extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t
*__attr
,
926 __THROW
__nonnull ((1));
929 /* Get the robustness flag of the mutex attribute ATTR. */
930 extern int pthread_mutexattr_getrobust (const pthread_mutexattr_t
*__attr
,
932 __THROW
__nonnull ((1, 2));
934 # ifdef __REDIRECT_NTH
935 extern int __REDIRECT_NTH (pthread_mutexattr_getrobust_np
,
936 (pthread_mutexattr_t
*, int *),
937 pthread_mutexattr_getrobust
) __nonnull ((1))
938 __attribute_deprecated_msg__ ("\
939 pthread_mutexattr_getrobust_np is deprecated, use pthread_mutexattr_getrobust");
941 # define pthread_mutexattr_getrobust_np pthread_mutexattr_getrobust
945 /* Set the robustness flag of the mutex attribute ATTR. */
946 extern int pthread_mutexattr_setrobust (pthread_mutexattr_t
*__attr
,
948 __THROW
__nonnull ((1));
950 # ifdef __REDIRECT_NTH
951 extern int __REDIRECT_NTH (pthread_mutexattr_setrobust_np
,
952 (pthread_mutexattr_t
*, int),
953 pthread_mutexattr_setrobust
) __nonnull ((1))
954 __attribute_deprecated_msg__ ("\
955 pthread_mutexattr_setrobust_np is deprecated, use pthread_mutexattr_setrobust");
957 # define pthread_mutexattr_setrobust_np pthread_mutexattr_setrobust
962 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
963 /* Functions for handling read-write locks. */
965 /* Initialize read-write lock RWLOCK using attributes ATTR, or use
966 the default values if later is NULL. */
967 extern int pthread_rwlock_init (pthread_rwlock_t
*__restrict __rwlock
,
968 const pthread_rwlockattr_t
*__restrict
969 __attr
) __THROW
__nonnull ((1));
971 /* Destroy read-write lock RWLOCK. */
972 extern int pthread_rwlock_destroy (pthread_rwlock_t
*__rwlock
)
973 __THROW
__nonnull ((1));
975 /* Acquire read lock for RWLOCK. */
976 extern int pthread_rwlock_rdlock (pthread_rwlock_t
*__rwlock
)
977 __THROWNL
__nonnull ((1));
979 /* Try to acquire read lock for RWLOCK. */
980 extern int pthread_rwlock_tryrdlock (pthread_rwlock_t
*__rwlock
)
981 __THROWNL
__nonnull ((1));
983 # ifdef __USE_XOPEN2K
984 /* Try to acquire read lock for RWLOCK or return after specfied time. */
985 # ifndef __USE_TIME_BITS64
986 extern int pthread_rwlock_timedrdlock (pthread_rwlock_t
*__restrict __rwlock
,
987 const struct timespec
*__restrict
988 __abstime
) __THROWNL
__nonnull ((1, 2));
990 # ifdef __REDIRECT_NTHNL
991 extern int __REDIRECT_NTHNL (pthread_rwlock_timedrdlock
,
992 (pthread_rwlock_t
*__restrict __rwlock
,
993 const struct timespec
*__restrict __abstime
),
994 __pthread_rwlock_timedrdlock64
)
997 # define pthread_rwlock_timedrdlock __pthread_rwlock_timedrdlock64
1003 # ifndef __USE_TIME_BITS64
1004 extern int pthread_rwlock_clockrdlock (pthread_rwlock_t
*__restrict __rwlock
,
1005 clockid_t __clockid
,
1006 const struct timespec
*__restrict
1007 __abstime
) __THROWNL
__nonnull ((1, 3));
1009 # ifdef __REDIRECT_NTHNL
1010 extern int __REDIRECT_NTHNL (pthread_rwlock_clockrdlock
,
1011 (pthread_rwlock_t
*__restrict __rwlock
,
1012 clockid_t __clockid
,
1013 const struct timespec
*__restrict __abstime
),
1014 __pthread_rwlock_clockrdlock64
)
1017 # define pthread_rwlock_clockrdlock __pthread_rwlock_clockrdlock64
1022 /* Acquire write lock for RWLOCK. */
1023 extern int pthread_rwlock_wrlock (pthread_rwlock_t
*__rwlock
)
1024 __THROWNL
__nonnull ((1));
1026 /* Try to acquire write lock for RWLOCK. */
1027 extern int pthread_rwlock_trywrlock (pthread_rwlock_t
*__rwlock
)
1028 __THROWNL
__nonnull ((1));
1030 # ifdef __USE_XOPEN2K
1031 /* Try to acquire write lock for RWLOCK or return after specfied time. */
1032 # ifndef __USE_TIME_BITS64
1033 extern int pthread_rwlock_timedwrlock (pthread_rwlock_t
*__restrict __rwlock
,
1034 const struct timespec
*__restrict
1035 __abstime
) __THROWNL
__nonnull ((1, 2));
1037 # ifdef __REDIRECT_NTHNL
1038 extern int __REDIRECT_NTHNL (pthread_rwlock_timedwrlock
,
1039 (pthread_rwlock_t
*__restrict __rwlock
,
1040 const struct timespec
*__restrict __abstime
),
1041 __pthread_rwlock_timedwrlock64
)
1044 # define pthread_rwlock_timedwrlock __pthread_rwlock_timedwrlock64
1050 # ifndef __USE_TIME_BITS64
1051 extern int pthread_rwlock_clockwrlock (pthread_rwlock_t
*__restrict __rwlock
,
1052 clockid_t __clockid
,
1053 const struct timespec
*__restrict
1054 __abstime
) __THROWNL
__nonnull ((1, 3));
1057 # ifdef __REDIRECT_NTHNL
1058 extern int __REDIRECT_NTHNL (pthread_rwlock_clockwrlock
,
1059 (pthread_rwlock_t
*__restrict __rwlock
,
1060 clockid_t __clockid
,
1061 const struct timespec
*__restrict __abstime
),
1062 __pthread_rwlock_clockwrlock64
)
1065 # define pthread_rwlock_clockwrlock __pthread_rwlock_clockwrlock64
1070 /* Unlock RWLOCK. */
1071 extern int pthread_rwlock_unlock (pthread_rwlock_t
*__rwlock
)
1072 __THROWNL
__nonnull ((1));
1075 /* Functions for handling read-write lock attributes. */
1077 /* Initialize attribute object ATTR with default values. */
1078 extern int pthread_rwlockattr_init (pthread_rwlockattr_t
*__attr
)
1079 __THROW
__nonnull ((1));
1081 /* Destroy attribute object ATTR. */
1082 extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t
*__attr
)
1083 __THROW
__nonnull ((1));
1085 /* Return current setting of process-shared attribute of ATTR in PSHARED. */
1086 extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t
*
1088 int *__restrict __pshared
)
1089 __THROW
__nonnull ((1, 2));
1091 /* Set process-shared attribute of ATTR to PSHARED. */
1092 extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t
*__attr
,
1094 __THROW
__nonnull ((1));
1096 /* Return current setting of reader/writer preference. */
1097 extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t
*
1099 int *__restrict __pref
)
1100 __THROW
__nonnull ((1, 2));
1102 /* Set reader/write preference. */
1103 extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t
*__attr
,
1104 int __pref
) __THROW
__nonnull ((1));
1108 /* Functions for handling conditional variables. */
1110 /* Initialize condition variable COND using attributes ATTR, or use
1111 the default values if later is NULL. */
1112 extern int pthread_cond_init (pthread_cond_t
*__restrict __cond
,
1113 const pthread_condattr_t
*__restrict __cond_attr
)
1114 __THROW
__nonnull ((1));
1116 /* Destroy condition variable COND. */
1117 extern int pthread_cond_destroy (pthread_cond_t
*__cond
)
1118 __THROW
__nonnull ((1));
1120 /* Wake up one thread waiting for condition variable COND. */
1121 extern int pthread_cond_signal (pthread_cond_t
*__cond
)
1122 __THROWNL
__nonnull ((1));
1124 /* Wake up all threads waiting for condition variables COND. */
1125 extern int pthread_cond_broadcast (pthread_cond_t
*__cond
)
1126 __THROWNL
__nonnull ((1));
1128 /* Wait for condition variable COND to be signaled or broadcast.
1129 MUTEX is assumed to be locked before.
1131 This function is a cancellation point and therefore not marked with
1133 extern int pthread_cond_wait (pthread_cond_t
*__restrict __cond
,
1134 pthread_mutex_t
*__restrict __mutex
)
1137 /* Wait for condition variable COND to be signaled or broadcast until
1138 ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an
1139 absolute time specification; zero is the beginning of the epoch
1140 (00:00:00 GMT, January 1, 1970).
1142 This function is a cancellation point and therefore not marked with
1144 # ifndef __USE_TIME_BITS64
1145 extern int pthread_cond_timedwait (pthread_cond_t
*__restrict __cond
,
1146 pthread_mutex_t
*__restrict __mutex
,
1147 const struct timespec
*__restrict __abstime
)
1148 __nonnull ((1, 2, 3));
1151 extern int __REDIRECT (pthread_cond_timedwait
,
1152 (pthread_cond_t
*__restrict __cond
,
1153 pthread_mutex_t
*__restrict __mutex
,
1154 const struct timespec
*__restrict __abstime
),
1155 __pthread_cond_timedwait64
)
1156 __nonnull ((1, 2, 3));
1158 # define pthread_cond_timedwait __pthread_cond_timedwait64
1163 /* Wait for condition variable COND to be signaled or broadcast until
1164 ABSTIME measured by the specified clock. MUTEX is assumed to be
1165 locked before. CLOCK is the clock to use. ABSTIME is an absolute
1166 time specification against CLOCK's epoch.
1168 This function is a cancellation point and therefore not marked with
1170 # ifndef __USE_TIME_BITS64
1171 extern int pthread_cond_clockwait (pthread_cond_t
*__restrict __cond
,
1172 pthread_mutex_t
*__restrict __mutex
,
1173 __clockid_t __clock_id
,
1174 const struct timespec
*__restrict __abstime
)
1175 __nonnull ((1, 2, 4));
1178 extern int __REDIRECT (pthread_cond_clockwait
,
1179 (pthread_cond_t
*__restrict __cond
,
1180 pthread_mutex_t
*__restrict __mutex
,
1181 __clockid_t __clock_id
,
1182 const struct timespec
*__restrict __abstime
),
1183 __pthread_cond_clockwait64
)
1184 __nonnull ((1, 2, 4));
1186 # define pthread_cond_clockwait __pthread_cond_clockwait64
1191 /* Functions for handling condition variable attributes. */
1193 /* Initialize condition variable attribute ATTR. */
1194 extern int pthread_condattr_init (pthread_condattr_t
*__attr
)
1195 __THROW
__nonnull ((1));
1197 /* Destroy condition variable attribute ATTR. */
1198 extern int pthread_condattr_destroy (pthread_condattr_t
*__attr
)
1199 __THROW
__nonnull ((1));
1201 /* Get the process-shared flag of the condition variable attribute ATTR. */
1202 extern int pthread_condattr_getpshared (const pthread_condattr_t
*
1204 int *__restrict __pshared
)
1205 __THROW
__nonnull ((1, 2));
1207 /* Set the process-shared flag of the condition variable attribute ATTR. */
1208 extern int pthread_condattr_setpshared (pthread_condattr_t
*__attr
,
1209 int __pshared
) __THROW
__nonnull ((1));
1211 #ifdef __USE_XOPEN2K
1212 /* Get the clock selected for the condition variable attribute ATTR. */
1213 extern int pthread_condattr_getclock (const pthread_condattr_t
*
1215 __clockid_t
*__restrict __clock_id
)
1216 __THROW
__nonnull ((1, 2));
1218 /* Set the clock selected for the condition variable attribute ATTR. */
1219 extern int pthread_condattr_setclock (pthread_condattr_t
*__attr
,
1220 __clockid_t __clock_id
)
1221 __THROW
__nonnull ((1));
1225 #ifdef __USE_XOPEN2K
1226 /* Functions to handle spinlocks. */
1228 /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can
1229 be shared between different processes. */
1230 extern int pthread_spin_init (pthread_spinlock_t
*__lock
, int __pshared
)
1231 __THROW
__nonnull ((1));
1233 /* Destroy the spinlock LOCK. */
1234 extern int pthread_spin_destroy (pthread_spinlock_t
*__lock
)
1235 __THROW
__nonnull ((1));
1237 /* Wait until spinlock LOCK is retrieved. */
1238 extern int pthread_spin_lock (pthread_spinlock_t
*__lock
)
1239 __THROWNL
__nonnull ((1));
1241 /* Try to lock spinlock LOCK. */
1242 extern int pthread_spin_trylock (pthread_spinlock_t
*__lock
)
1243 __THROWNL
__nonnull ((1));
1245 /* Release spinlock LOCK. */
1246 extern int pthread_spin_unlock (pthread_spinlock_t
*__lock
)
1247 __THROWNL
__nonnull ((1));
1250 /* Functions to handle barriers. */
1252 /* Initialize BARRIER with the attributes in ATTR. The barrier is
1253 opened when COUNT waiters arrived. */
1254 extern int pthread_barrier_init (pthread_barrier_t
*__restrict __barrier
,
1255 const pthread_barrierattr_t
*__restrict
1256 __attr
, unsigned int __count
)
1257 __THROW
__nonnull ((1));
1259 /* Destroy a previously dynamically initialized barrier BARRIER. */
1260 extern int pthread_barrier_destroy (pthread_barrier_t
*__barrier
)
1261 __THROW
__nonnull ((1));
1263 /* Wait on barrier BARRIER. */
1264 extern int pthread_barrier_wait (pthread_barrier_t
*__barrier
)
1265 __THROWNL
__nonnull ((1));
1268 /* Initialize barrier attribute ATTR. */
1269 extern int pthread_barrierattr_init (pthread_barrierattr_t
*__attr
)
1270 __THROW
__nonnull ((1));
1272 /* Destroy previously dynamically initialized barrier attribute ATTR. */
1273 extern int pthread_barrierattr_destroy (pthread_barrierattr_t
*__attr
)
1274 __THROW
__nonnull ((1));
1276 /* Get the process-shared flag of the barrier attribute ATTR. */
1277 extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t
*
1279 int *__restrict __pshared
)
1280 __THROW
__nonnull ((1, 2));
1282 /* Set the process-shared flag of the barrier attribute ATTR. */
1283 extern int pthread_barrierattr_setpshared (pthread_barrierattr_t
*__attr
,
1285 __THROW
__nonnull ((1));
1289 /* Functions for handling thread-specific data. */
1291 /* Create a key value identifying a location in the thread-specific
1292 data area. Each thread maintains a distinct thread-specific data
1293 area. DESTR_FUNCTION, if non-NULL, is called with the value
1294 associated to that key when the key is destroyed.
1295 DESTR_FUNCTION is not called if the value associated is NULL when
1296 the key is destroyed. */
1297 extern int pthread_key_create (pthread_key_t
*__key
,
1298 void (*__destr_function
) (void *))
1299 __THROW
__nonnull ((1));
1302 extern int pthread_key_delete (pthread_key_t __key
) __THROW
;
1304 /* Return current value of the thread-specific data slot identified by KEY. */
1305 extern void *pthread_getspecific (pthread_key_t __key
) __THROW
;
1307 /* Store POINTER in the thread-specific data slot identified by KEY. */
1308 extern int pthread_setspecific (pthread_key_t __key
,
1309 const void *__pointer
)
1310 __THROW
__attr_access_none (2);
1313 #ifdef __USE_XOPEN2K
1314 /* Get ID of CPU-time clock for thread THREAD_ID. */
1315 extern int pthread_getcpuclockid (pthread_t __thread_id
,
1316 __clockid_t
*__clock_id
)
1317 __THROW
__nonnull ((2));
1321 /* Install handlers to be called when a new process is created with FORK.
1322 The PREPARE handler is called in the parent process just before performing
1323 FORK. The PARENT handler is called in the parent process just after FORK.
1324 The CHILD handler is called in the child process. Each of the three
1325 handlers can be NULL, meaning that no handler needs to be called at that
1327 PTHREAD_ATFORK can be called several times, in which case the PREPARE
1328 handlers are called in LIFO order (last added with PTHREAD_ATFORK,
1329 first called before FORK), and the PARENT and CHILD handlers are called
1330 in FIFO (first added, first called). */
1332 extern int pthread_atfork (void (*__prepare
) (void),
1333 void (*__parent
) (void),
1334 void (*__child
) (void)) __THROW
;
1337 #ifdef __USE_EXTERN_INLINES
1338 /* Optimizations. */
1340 __NTH (pthread_equal (pthread_t __thread1
, pthread_t __thread2
))
1342 return __thread1
== __thread2
;
1348 #endif /* pthread.h */