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