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