]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/nptl/pthread.h
Avoid -Wstringop-overflow warning in pthread_cleanup_push macros
[thirdparty/glibc.git] / sysdeps / nptl / pthread.h
1 /* Copyright (C) 2002-2020 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 /* Yield the processor to another thread or process.
458 This function is similar to the POSIX `sched_yield' function but
459 might be differently implemented in the case of a m-on-n thread
460 implementation. */
461 extern int pthread_yield (void) __THROW;
462
463
464 /* Limit specified thread TH to run only on the processors represented
465 in CPUSET. */
466 extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
467 const cpu_set_t *__cpuset)
468 __THROW __nonnull ((3));
469
470 /* Get bit set in CPUSET representing the processors TH can run on. */
471 extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
472 cpu_set_t *__cpuset)
473 __THROW __nonnull ((3));
474 #endif
475
476
477 /* Functions for handling initialization. */
478
479 /* Guarantee that the initialization function INIT_ROUTINE will be called
480 only once, even if pthread_once is executed several times with the
481 same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
482 extern variable initialized to PTHREAD_ONCE_INIT.
483
484 The initialization functions might throw exception which is why
485 this function is not marked with __THROW. */
486 extern int pthread_once (pthread_once_t *__once_control,
487 void (*__init_routine) (void)) __nonnull ((1, 2));
488
489
490 /* Functions for handling cancellation.
491
492 Note that these functions are explicitly not marked to not throw an
493 exception in C++ code. If cancellation is implemented by unwinding
494 this is necessary to have the compiler generate the unwind information. */
495
496 /* Set cancelability state of current thread to STATE, returning old
497 state in *OLDSTATE if OLDSTATE is not NULL. */
498 extern int pthread_setcancelstate (int __state, int *__oldstate);
499
500 /* Set cancellation state of current thread to TYPE, returning the old
501 type in *OLDTYPE if OLDTYPE is not NULL. */
502 extern int pthread_setcanceltype (int __type, int *__oldtype);
503
504 /* Cancel THREAD immediately or at the next possibility. */
505 extern int pthread_cancel (pthread_t __th);
506
507 /* Test for pending cancellation for the current thread and terminate
508 the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
509 cancelled. */
510 extern void pthread_testcancel (void);
511
512
513 /* Cancellation handling with integration into exception handling. */
514
515 struct __cancel_jmp_buf_tag
516 {
517 __jmp_buf __cancel_jmp_buf;
518 int __mask_was_saved;
519 };
520
521 typedef struct
522 {
523 struct __cancel_jmp_buf_tag __cancel_jmp_buf[1];
524 void *__pad[4];
525 } __pthread_unwind_buf_t __attribute__ ((__aligned__));
526
527 /* No special attributes by default. */
528 #ifndef __cleanup_fct_attribute
529 # define __cleanup_fct_attribute
530 #endif
531
532
533 /* Structure to hold the cleanup handler information. */
534 struct __pthread_cleanup_frame
535 {
536 void (*__cancel_routine) (void *);
537 void *__cancel_arg;
538 int __do_it;
539 int __cancel_type;
540 };
541
542 #if defined __GNUC__ && defined __EXCEPTIONS
543 # ifdef __cplusplus
544 /* Class to handle cancellation handler invocation. */
545 class __pthread_cleanup_class
546 {
547 void (*__cancel_routine) (void *);
548 void *__cancel_arg;
549 int __do_it;
550 int __cancel_type;
551
552 public:
553 __pthread_cleanup_class (void (*__fct) (void *), void *__arg)
554 : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { }
555 ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); }
556 void __setdoit (int __newval) { __do_it = __newval; }
557 void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,
558 &__cancel_type); }
559 void __restore () const { pthread_setcanceltype (__cancel_type, 0); }
560 };
561
562 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
563 when the thread is canceled or calls pthread_exit. ROUTINE will also
564 be called with arguments ARG when the matching pthread_cleanup_pop
565 is executed with non-zero EXECUTE argument.
566
567 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
568 be used in matching pairs at the same nesting level of braces. */
569 # define pthread_cleanup_push(routine, arg) \
570 do { \
571 __pthread_cleanup_class __clframe (routine, arg)
572
573 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
574 If EXECUTE is non-zero, the handler function is called. */
575 # define pthread_cleanup_pop(execute) \
576 __clframe.__setdoit (execute); \
577 } while (0)
578
579 # ifdef __USE_GNU
580 /* Install a cleanup handler as pthread_cleanup_push does, but also
581 saves the current cancellation type and sets it to deferred
582 cancellation. */
583 # define pthread_cleanup_push_defer_np(routine, arg) \
584 do { \
585 __pthread_cleanup_class __clframe (routine, arg); \
586 __clframe.__defer ()
587
588 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
589 restores the cancellation type that was in effect when the matching
590 pthread_cleanup_push_defer was called. */
591 # define pthread_cleanup_pop_restore_np(execute) \
592 __clframe.__restore (); \
593 __clframe.__setdoit (execute); \
594 } while (0)
595 # endif
596 # else
597 /* Function called to call the cleanup handler. As an extern inline
598 function the compiler is free to decide inlining the change when
599 needed or fall back on the copy which must exist somewhere
600 else. */
601 __extern_inline void
602 __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
603 {
604 if (__frame->__do_it)
605 __frame->__cancel_routine (__frame->__cancel_arg);
606 }
607
608 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
609 when the thread is canceled or calls pthread_exit. ROUTINE will also
610 be called with arguments ARG when the matching pthread_cleanup_pop
611 is executed with non-zero EXECUTE argument.
612
613 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
614 be used in matching pairs at the same nesting level of braces. */
615 # define pthread_cleanup_push(routine, arg) \
616 do { \
617 struct __pthread_cleanup_frame __clframe \
618 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
619 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
620 .__do_it = 1 };
621
622 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
623 If EXECUTE is non-zero, the handler function is called. */
624 # define pthread_cleanup_pop(execute) \
625 __clframe.__do_it = (execute); \
626 } while (0)
627
628 # ifdef __USE_GNU
629 /* Install a cleanup handler as pthread_cleanup_push does, but also
630 saves the current cancellation type and sets it to deferred
631 cancellation. */
632 # define pthread_cleanup_push_defer_np(routine, arg) \
633 do { \
634 struct __pthread_cleanup_frame __clframe \
635 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
636 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
637 .__do_it = 1 }; \
638 (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \
639 &__clframe.__cancel_type)
640
641 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
642 restores the cancellation type that was in effect when the matching
643 pthread_cleanup_push_defer was called. */
644 # define pthread_cleanup_pop_restore_np(execute) \
645 (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \
646 __clframe.__do_it = (execute); \
647 } while (0)
648 # endif
649 # endif
650 #else
651 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
652 when the thread is canceled or calls pthread_exit. ROUTINE will also
653 be called with arguments ARG when the matching pthread_cleanup_pop
654 is executed with non-zero EXECUTE argument.
655
656 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
657 be used in matching pairs at the same nesting level of braces. */
658 # define pthread_cleanup_push(routine, arg) \
659 do { \
660 __pthread_unwind_buf_t __cancel_buf; \
661 void (*__cancel_routine) (void *) = (routine); \
662 void *__cancel_arg = (arg); \
663 int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \
664 0); \
665 if (__glibc_unlikely (__not_first_call)) \
666 { \
667 __cancel_routine (__cancel_arg); \
668 __pthread_unwind_next (&__cancel_buf); \
669 /* NOTREACHED */ \
670 } \
671 \
672 __pthread_register_cancel (&__cancel_buf); \
673 do {
674 extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
675 __cleanup_fct_attribute;
676
677 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
678 If EXECUTE is non-zero, the handler function is called. */
679 # define pthread_cleanup_pop(execute) \
680 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
681 } while (0); \
682 __pthread_unregister_cancel (&__cancel_buf); \
683 if (execute) \
684 __cancel_routine (__cancel_arg); \
685 } while (0)
686 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
687 __cleanup_fct_attribute;
688
689 # ifdef __USE_GNU
690 /* Install a cleanup handler as pthread_cleanup_push does, but also
691 saves the current cancellation type and sets it to deferred
692 cancellation. */
693 # define pthread_cleanup_push_defer_np(routine, arg) \
694 do { \
695 __pthread_unwind_buf_t __cancel_buf; \
696 void (*__cancel_routine) (void *) = (routine); \
697 void *__cancel_arg = (arg); \
698 int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \
699 0); \
700 if (__glibc_unlikely (__not_first_call)) \
701 { \
702 __cancel_routine (__cancel_arg); \
703 __pthread_unwind_next (&__cancel_buf); \
704 /* NOTREACHED */ \
705 } \
706 \
707 __pthread_register_cancel_defer (&__cancel_buf); \
708 do {
709 extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf)
710 __cleanup_fct_attribute;
711
712 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
713 restores the cancellation type that was in effect when the matching
714 pthread_cleanup_push_defer was called. */
715 # define pthread_cleanup_pop_restore_np(execute) \
716 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
717 } while (0); \
718 __pthread_unregister_cancel_restore (&__cancel_buf); \
719 if (execute) \
720 __cancel_routine (__cancel_arg); \
721 } while (0)
722 extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf)
723 __cleanup_fct_attribute;
724 # endif
725
726 /* Internal interface to initiate cleanup. */
727 extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
728 __cleanup_fct_attribute __attribute__ ((__noreturn__))
729 # ifndef SHARED
730 __attribute__ ((__weak__))
731 # endif
732 ;
733 #endif
734
735 /* Function used in the macros. Calling __sigsetjmp, with its first
736 argument declared as an array, results in a -Wstringop-overflow
737 warning from GCC 11 because struct pthread_unwind_buf is smaller
738 than jmp_buf. The calls from the macros have __SAVEMASK set to 0,
739 so nothing beyond the common prefix is used and this warning is a
740 false positive. Use an alias with its first argument declared to
741 use the type in the macros if possible to avoid this warning. */
742 #if __GNUC_PREREQ (11, 0)
743 extern int __REDIRECT_NTHNL (__sigsetjmp_cancel,
744 (struct __cancel_jmp_buf_tag __env[1],
745 int __savemask),
746 __sigsetjmp) __attribute_returns_twice__;
747 #else
748 # define __sigsetjmp_cancel(env, savemask) \
749 __sigsetjmp ((struct __jmp_buf_tag *) (void *) (env), (savemask))
750 extern int __sigsetjmp (struct __jmp_buf_tag __env[1],
751 int __savemask) __THROWNL;
752 #endif
753
754
755 /* Mutex handling. */
756
757 /* Initialize a mutex. */
758 extern int pthread_mutex_init (pthread_mutex_t *__mutex,
759 const pthread_mutexattr_t *__mutexattr)
760 __THROW __nonnull ((1));
761
762 /* Destroy a mutex. */
763 extern int pthread_mutex_destroy (pthread_mutex_t *__mutex)
764 __THROW __nonnull ((1));
765
766 /* Try locking a mutex. */
767 extern int pthread_mutex_trylock (pthread_mutex_t *__mutex)
768 __THROWNL __nonnull ((1));
769
770 /* Lock a mutex. */
771 extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
772 __THROWNL __nonnull ((1));
773
774 #ifdef __USE_XOPEN2K
775 /* Wait until lock becomes available, or specified time passes. */
776 extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
777 const struct timespec *__restrict
778 __abstime) __THROWNL __nonnull ((1, 2));
779 #endif
780
781 #ifdef __USE_GNU
782 extern int pthread_mutex_clocklock (pthread_mutex_t *__restrict __mutex,
783 clockid_t __clockid,
784 const struct timespec *__restrict
785 __abstime) __THROWNL __nonnull ((1, 3));
786 #endif
787
788 /* Unlock a mutex. */
789 extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
790 __THROWNL __nonnull ((1));
791
792
793 /* Get the priority ceiling of MUTEX. */
794 extern int pthread_mutex_getprioceiling (const pthread_mutex_t *
795 __restrict __mutex,
796 int *__restrict __prioceiling)
797 __THROW __nonnull ((1, 2));
798
799 /* Set the priority ceiling of MUTEX to PRIOCEILING, return old
800 priority ceiling value in *OLD_CEILING. */
801 extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex,
802 int __prioceiling,
803 int *__restrict __old_ceiling)
804 __THROW __nonnull ((1, 3));
805
806
807 #ifdef __USE_XOPEN2K8
808 /* Declare the state protected by MUTEX as consistent. */
809 extern int pthread_mutex_consistent (pthread_mutex_t *__mutex)
810 __THROW __nonnull ((1));
811 # ifdef __USE_GNU
812 extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex)
813 __THROW __nonnull ((1));
814 # endif
815 #endif
816
817
818 /* Functions for handling mutex attributes. */
819
820 /* Initialize mutex attribute object ATTR with default attributes
821 (kind is PTHREAD_MUTEX_TIMED_NP). */
822 extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr)
823 __THROW __nonnull ((1));
824
825 /* Destroy mutex attribute object ATTR. */
826 extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr)
827 __THROW __nonnull ((1));
828
829 /* Get the process-shared flag of the mutex attribute ATTR. */
830 extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t *
831 __restrict __attr,
832 int *__restrict __pshared)
833 __THROW __nonnull ((1, 2));
834
835 /* Set the process-shared flag of the mutex attribute ATTR. */
836 extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
837 int __pshared)
838 __THROW __nonnull ((1));
839
840 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
841 /* Return in *KIND the mutex kind attribute in *ATTR. */
842 extern int pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict
843 __attr, int *__restrict __kind)
844 __THROW __nonnull ((1, 2));
845
846 /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
847 PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
848 PTHREAD_MUTEX_DEFAULT). */
849 extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
850 __THROW __nonnull ((1));
851 #endif
852
853 /* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */
854 extern int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *
855 __restrict __attr,
856 int *__restrict __protocol)
857 __THROW __nonnull ((1, 2));
858
859 /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
860 PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */
861 extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr,
862 int __protocol)
863 __THROW __nonnull ((1));
864
865 /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */
866 extern int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *
867 __restrict __attr,
868 int *__restrict __prioceiling)
869 __THROW __nonnull ((1, 2));
870
871 /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */
872 extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr,
873 int __prioceiling)
874 __THROW __nonnull ((1));
875
876 #ifdef __USE_XOPEN2K
877 /* Get the robustness flag of the mutex attribute ATTR. */
878 extern int pthread_mutexattr_getrobust (const pthread_mutexattr_t *__attr,
879 int *__robustness)
880 __THROW __nonnull ((1, 2));
881 # ifdef __USE_GNU
882 extern int pthread_mutexattr_getrobust_np (const pthread_mutexattr_t *__attr,
883 int *__robustness)
884 __THROW __nonnull ((1, 2));
885 # endif
886
887 /* Set the robustness flag of the mutex attribute ATTR. */
888 extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr,
889 int __robustness)
890 __THROW __nonnull ((1));
891 # ifdef __USE_GNU
892 extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr,
893 int __robustness)
894 __THROW __nonnull ((1));
895 # endif
896 #endif
897
898
899 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
900 /* Functions for handling read-write locks. */
901
902 /* Initialize read-write lock RWLOCK using attributes ATTR, or use
903 the default values if later is NULL. */
904 extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
905 const pthread_rwlockattr_t *__restrict
906 __attr) __THROW __nonnull ((1));
907
908 /* Destroy read-write lock RWLOCK. */
909 extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock)
910 __THROW __nonnull ((1));
911
912 /* Acquire read lock for RWLOCK. */
913 extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock)
914 __THROWNL __nonnull ((1));
915
916 /* Try to acquire read lock for RWLOCK. */
917 extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
918 __THROWNL __nonnull ((1));
919
920 # ifdef __USE_XOPEN2K
921 /* Try to acquire read lock for RWLOCK or return after specfied time. */
922 extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
923 const struct timespec *__restrict
924 __abstime) __THROWNL __nonnull ((1, 2));
925 # endif
926
927 # ifdef __USE_GNU
928 extern int pthread_rwlock_clockrdlock (pthread_rwlock_t *__restrict __rwlock,
929 clockid_t __clockid,
930 const struct timespec *__restrict
931 __abstime) __THROWNL __nonnull ((1, 3));
932 # endif
933
934 /* Acquire write lock for RWLOCK. */
935 extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
936 __THROWNL __nonnull ((1));
937
938 /* Try to acquire write lock for RWLOCK. */
939 extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
940 __THROWNL __nonnull ((1));
941
942 # ifdef __USE_XOPEN2K
943 /* Try to acquire write lock for RWLOCK or return after specfied time. */
944 extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
945 const struct timespec *__restrict
946 __abstime) __THROWNL __nonnull ((1, 2));
947 # endif
948
949 # ifdef __USE_GNU
950 extern int pthread_rwlock_clockwrlock (pthread_rwlock_t *__restrict __rwlock,
951 clockid_t __clockid,
952 const struct timespec *__restrict
953 __abstime) __THROWNL __nonnull ((1, 3));
954 # endif
955
956 /* Unlock RWLOCK. */
957 extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
958 __THROWNL __nonnull ((1));
959
960
961 /* Functions for handling read-write lock attributes. */
962
963 /* Initialize attribute object ATTR with default values. */
964 extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr)
965 __THROW __nonnull ((1));
966
967 /* Destroy attribute object ATTR. */
968 extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr)
969 __THROW __nonnull ((1));
970
971 /* Return current setting of process-shared attribute of ATTR in PSHARED. */
972 extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *
973 __restrict __attr,
974 int *__restrict __pshared)
975 __THROW __nonnull ((1, 2));
976
977 /* Set process-shared attribute of ATTR to PSHARED. */
978 extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
979 int __pshared)
980 __THROW __nonnull ((1));
981
982 /* Return current setting of reader/writer preference. */
983 extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t *
984 __restrict __attr,
985 int *__restrict __pref)
986 __THROW __nonnull ((1, 2));
987
988 /* Set reader/write preference. */
989 extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
990 int __pref) __THROW __nonnull ((1));
991 #endif
992
993
994 /* Functions for handling conditional variables. */
995
996 /* Initialize condition variable COND using attributes ATTR, or use
997 the default values if later is NULL. */
998 extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
999 const pthread_condattr_t *__restrict __cond_attr)
1000 __THROW __nonnull ((1));
1001
1002 /* Destroy condition variable COND. */
1003 extern int pthread_cond_destroy (pthread_cond_t *__cond)
1004 __THROW __nonnull ((1));
1005
1006 /* Wake up one thread waiting for condition variable COND. */
1007 extern int pthread_cond_signal (pthread_cond_t *__cond)
1008 __THROWNL __nonnull ((1));
1009
1010 /* Wake up all threads waiting for condition variables COND. */
1011 extern int pthread_cond_broadcast (pthread_cond_t *__cond)
1012 __THROWNL __nonnull ((1));
1013
1014 /* Wait for condition variable COND to be signaled or broadcast.
1015 MUTEX is assumed to be locked before.
1016
1017 This function is a cancellation point and therefore not marked with
1018 __THROW. */
1019 extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
1020 pthread_mutex_t *__restrict __mutex)
1021 __nonnull ((1, 2));
1022
1023 /* Wait for condition variable COND to be signaled or broadcast until
1024 ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an
1025 absolute time specification; zero is the beginning of the epoch
1026 (00:00:00 GMT, January 1, 1970).
1027
1028 This function is a cancellation point and therefore not marked with
1029 __THROW. */
1030 extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
1031 pthread_mutex_t *__restrict __mutex,
1032 const struct timespec *__restrict __abstime)
1033 __nonnull ((1, 2, 3));
1034
1035 # ifdef __USE_GNU
1036 /* Wait for condition variable COND to be signaled or broadcast until
1037 ABSTIME measured by the specified clock. MUTEX is assumed to be
1038 locked before. CLOCK is the clock to use. ABSTIME is an absolute
1039 time specification against CLOCK's epoch.
1040
1041 This function is a cancellation point and therefore not marked with
1042 __THROW. */
1043 extern int pthread_cond_clockwait (pthread_cond_t *__restrict __cond,
1044 pthread_mutex_t *__restrict __mutex,
1045 __clockid_t __clock_id,
1046 const struct timespec *__restrict __abstime)
1047 __nonnull ((1, 2, 4));
1048 # endif
1049
1050 /* Functions for handling condition variable attributes. */
1051
1052 /* Initialize condition variable attribute ATTR. */
1053 extern int pthread_condattr_init (pthread_condattr_t *__attr)
1054 __THROW __nonnull ((1));
1055
1056 /* Destroy condition variable attribute ATTR. */
1057 extern int pthread_condattr_destroy (pthread_condattr_t *__attr)
1058 __THROW __nonnull ((1));
1059
1060 /* Get the process-shared flag of the condition variable attribute ATTR. */
1061 extern int pthread_condattr_getpshared (const pthread_condattr_t *
1062 __restrict __attr,
1063 int *__restrict __pshared)
1064 __THROW __nonnull ((1, 2));
1065
1066 /* Set the process-shared flag of the condition variable attribute ATTR. */
1067 extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
1068 int __pshared) __THROW __nonnull ((1));
1069
1070 #ifdef __USE_XOPEN2K
1071 /* Get the clock selected for the condition variable attribute ATTR. */
1072 extern int pthread_condattr_getclock (const pthread_condattr_t *
1073 __restrict __attr,
1074 __clockid_t *__restrict __clock_id)
1075 __THROW __nonnull ((1, 2));
1076
1077 /* Set the clock selected for the condition variable attribute ATTR. */
1078 extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
1079 __clockid_t __clock_id)
1080 __THROW __nonnull ((1));
1081 #endif
1082
1083
1084 #ifdef __USE_XOPEN2K
1085 /* Functions to handle spinlocks. */
1086
1087 /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can
1088 be shared between different processes. */
1089 extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
1090 __THROW __nonnull ((1));
1091
1092 /* Destroy the spinlock LOCK. */
1093 extern int pthread_spin_destroy (pthread_spinlock_t *__lock)
1094 __THROW __nonnull ((1));
1095
1096 /* Wait until spinlock LOCK is retrieved. */
1097 extern int pthread_spin_lock (pthread_spinlock_t *__lock)
1098 __THROWNL __nonnull ((1));
1099
1100 /* Try to lock spinlock LOCK. */
1101 extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
1102 __THROWNL __nonnull ((1));
1103
1104 /* Release spinlock LOCK. */
1105 extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
1106 __THROWNL __nonnull ((1));
1107
1108
1109 /* Functions to handle barriers. */
1110
1111 /* Initialize BARRIER with the attributes in ATTR. The barrier is
1112 opened when COUNT waiters arrived. */
1113 extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
1114 const pthread_barrierattr_t *__restrict
1115 __attr, unsigned int __count)
1116 __THROW __nonnull ((1));
1117
1118 /* Destroy a previously dynamically initialized barrier BARRIER. */
1119 extern int pthread_barrier_destroy (pthread_barrier_t *__barrier)
1120 __THROW __nonnull ((1));
1121
1122 /* Wait on barrier BARRIER. */
1123 extern int pthread_barrier_wait (pthread_barrier_t *__barrier)
1124 __THROWNL __nonnull ((1));
1125
1126
1127 /* Initialize barrier attribute ATTR. */
1128 extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr)
1129 __THROW __nonnull ((1));
1130
1131 /* Destroy previously dynamically initialized barrier attribute ATTR. */
1132 extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr)
1133 __THROW __nonnull ((1));
1134
1135 /* Get the process-shared flag of the barrier attribute ATTR. */
1136 extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t *
1137 __restrict __attr,
1138 int *__restrict __pshared)
1139 __THROW __nonnull ((1, 2));
1140
1141 /* Set the process-shared flag of the barrier attribute ATTR. */
1142 extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
1143 int __pshared)
1144 __THROW __nonnull ((1));
1145 #endif
1146
1147
1148 /* Functions for handling thread-specific data. */
1149
1150 /* Create a key value identifying a location in the thread-specific
1151 data area. Each thread maintains a distinct thread-specific data
1152 area. DESTR_FUNCTION, if non-NULL, is called with the value
1153 associated to that key when the key is destroyed.
1154 DESTR_FUNCTION is not called if the value associated is NULL when
1155 the key is destroyed. */
1156 extern int pthread_key_create (pthread_key_t *__key,
1157 void (*__destr_function) (void *))
1158 __THROW __nonnull ((1));
1159
1160 /* Destroy KEY. */
1161 extern int pthread_key_delete (pthread_key_t __key) __THROW;
1162
1163 /* Return current value of the thread-specific data slot identified by KEY. */
1164 extern void *pthread_getspecific (pthread_key_t __key) __THROW;
1165
1166 /* Store POINTER in the thread-specific data slot identified by KEY. */
1167 extern int pthread_setspecific (pthread_key_t __key,
1168 const void *__pointer) __THROW ;
1169
1170
1171 #ifdef __USE_XOPEN2K
1172 /* Get ID of CPU-time clock for thread THREAD_ID. */
1173 extern int pthread_getcpuclockid (pthread_t __thread_id,
1174 __clockid_t *__clock_id)
1175 __THROW __nonnull ((2));
1176 #endif
1177
1178
1179 /* Install handlers to be called when a new process is created with FORK.
1180 The PREPARE handler is called in the parent process just before performing
1181 FORK. The PARENT handler is called in the parent process just after FORK.
1182 The CHILD handler is called in the child process. Each of the three
1183 handlers can be NULL, meaning that no handler needs to be called at that
1184 point.
1185 PTHREAD_ATFORK can be called several times, in which case the PREPARE
1186 handlers are called in LIFO order (last added with PTHREAD_ATFORK,
1187 first called before FORK), and the PARENT and CHILD handlers are called
1188 in FIFO (first added, first called). */
1189
1190 extern int pthread_atfork (void (*__prepare) (void),
1191 void (*__parent) (void),
1192 void (*__child) (void)) __THROW;
1193
1194
1195 #ifdef __USE_EXTERN_INLINES
1196 /* Optimizations. */
1197 __extern_inline int
1198 __NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2))
1199 {
1200 return __thread1 == __thread2;
1201 }
1202 #endif
1203
1204 __END_DECLS
1205
1206 #endif /* pthread.h */