1 /* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #define __need_sigset_t
28 #include <bits/pthreadtypes.h>
29 #include <bits/setjmp.h>
35 PTHREAD_CREATE_JOINABLE
,
36 #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
37 PTHREAD_CREATE_DETACHED
38 #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
45 PTHREAD_MUTEX_TIMED_NP
,
46 PTHREAD_MUTEX_RECURSIVE_NP
,
47 PTHREAD_MUTEX_ERRORCHECK_NP
,
48 PTHREAD_MUTEX_ADAPTIVE_NP
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
57 /* For compatibility. */
58 , PTHREAD_MUTEX_FAST_NP
= PTHREAD_MUTEX_TIMED_NP
62 /* Mutex initializers. */
63 #define PTHREAD_MUTEX_INITIALIZER \
66 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
67 { .__data = { .__kind = PTHREAD_MUTEX_RECURSIVE_NP } }
68 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
69 { .__data = { .__kind = PTHREAD_MUTEX_ERRORCHECK_NP } }
70 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
71 { .__data = { .__kind = PTHREAD_MUTEX_ADAPTIVE_NP } }
75 /* Read-write lock types. */
79 PTHREAD_RWLOCK_PREFER_READER_NP
,
80 PTHREAD_RWLOCK_PREFER_WRITER_NP
,
81 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
,
82 PTHREAD_RWLOCK_DEFAULT_NP
= PTHREAD_RWLOCK_PREFER_READER_NP
86 /* Read-write lock initializers. */
87 #define PTHREAD_RWLOCK_INITIALIZER \
90 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
91 { .__data = { .__flags = PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
95 /* Scheduler inheritance. */
98 PTHREAD_INHERIT_SCHED
,
99 #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
100 PTHREAD_EXPLICIT_SCHED
101 #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
105 /* Scope handling. */
108 PTHREAD_SCOPE_SYSTEM
,
109 #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
110 PTHREAD_SCOPE_PROCESS
111 #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
115 /* Process shared or private flag. */
118 PTHREAD_PROCESS_PRIVATE
,
119 #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
120 PTHREAD_PROCESS_SHARED
121 #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
126 /* Conditional variable handling. */
127 #define PTHREAD_COND_INITIALIZER { }
130 /* Cleanup buffers */
131 struct _pthread_cleanup_buffer
133 void (*__routine
) (void *); /* Function to call. */
134 void *__arg
; /* Its argument. */
135 int __canceltype
; /* Saved cancellation type. */
136 struct _pthread_cleanup_buffer
*__prev
; /* Chaining of cleanup functions. */
142 PTHREAD_CANCEL_ENABLE
,
143 #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
144 PTHREAD_CANCEL_DISABLE
145 #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
149 PTHREAD_CANCEL_DEFERRED
,
150 #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
151 PTHREAD_CANCEL_ASYNCHRONOUS
152 #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
154 #define PTHREAD_CANCELED ((void *) -1)
157 /* Single execution handling. */
158 #define PTHREAD_ONCE_INIT 0
162 /* Value returned by 'pthread_barrier_wait' for one of the threads after
163 the required number of threads have called this function.
164 -1 is distinct from 0 and all errno constants */
165 # define PTHREAD_BARRIER_SERIAL_THREAD -1
171 /* Create a new thread, starting with execution of START-ROUTINE
172 getting passed ARG. Creation attributed come from ATTR. The new
173 handle is stored in *NEWTHREAD. */
174 extern int pthread_create (pthread_t
*__restrict __newthread
,
175 __const pthread_attr_t
*__restrict __attr
,
176 void *(*__start_routine
) (void *),
177 void *__restrict __arg
) __THROW
;
179 /* Terminate calling thread.
181 The registered cleanup handlers are called via exception handling
182 so we cannot mark this function with __THROW.*/
183 extern void pthread_exit (void *__retval
) __attribute__ ((__noreturn__
));
185 /* Make calling thread wait for termination of the thread TH. The
186 exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
189 This function is a cancellation point and therefore not marked with
191 extern int pthread_join (pthread_t __th
, void **__thread_return
);
194 /* Check whether thread TH has terminated. If yes return the status of
195 the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
196 extern int pthread_tryjoin_np (pthread_t __th
, void **__thread_return
) __THROW
;
198 /* Make calling thread wait for termination of the thread TH, but only
199 until TIMEOUT. The exit status of the thread is stored in
200 *THREAD_RETURN, if THREAD_RETURN is not NULL.
202 This function is a cancellation point and therefore not marked with
204 extern int pthread_timedjoin_np (pthread_t __th
, void **__thread_return
,
205 __const
struct timespec
*__abstime
);
208 /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
209 The resources of TH will therefore be freed immediately when it
210 terminates, instead of waiting for another thread to perform PTHREAD_JOIN
212 extern int pthread_detach (pthread_t __th
) __THROW
;
215 /* Obtain the identifier of the current thread. */
216 extern pthread_t
pthread_self (void) __THROW
__attribute__ ((__const__
));
218 /* Compare two thread identifiers. */
219 extern int pthread_equal (pthread_t __thread1
, pthread_t __thread2
) __THROW
;
222 /* Thread attribute handling. */
224 /* Initialize thread attribute *ATTR with default attributes
225 (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
226 no user-provided stack). */
227 extern int pthread_attr_init (pthread_attr_t
*__attr
) __THROW
;
229 /* Destroy thread attribute *ATTR. */
230 extern int pthread_attr_destroy (pthread_attr_t
*__attr
) __THROW
;
232 /* Get detach state attribute. */
233 extern int pthread_attr_getdetachstate (__const pthread_attr_t
*__attr
,
234 int *__detachstate
) __THROW
;
236 /* Set detach state attribute. */
237 extern int pthread_attr_setdetachstate (pthread_attr_t
*__attr
,
238 int __detachstate
) __THROW
;
241 /* Get the size of the guard area created for stack overflow protection. */
242 extern int pthread_attr_getguardsize (__const pthread_attr_t
*__attr
,
243 size_t *__guardsize
) __THROW
;
245 /* Set the size of the guard area created for stack overflow protection. */
246 extern int pthread_attr_setguardsize (pthread_attr_t
*__attr
,
247 size_t __guardsize
) __THROW
;
250 /* Return in *PARAM the scheduling parameters of *ATTR. */
251 extern int pthread_attr_getschedparam (__const pthread_attr_t
*__restrict
253 struct sched_param
*__restrict __param
)
256 /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
257 extern int pthread_attr_setschedparam (pthread_attr_t
*__restrict __attr
,
258 __const
struct sched_param
*__restrict
261 /* Return in *POLICY the scheduling policy of *ATTR. */
262 extern int pthread_attr_getschedpolicy (__const pthread_attr_t
*__restrict
263 __attr
, int *__restrict __policy
)
266 /* Set scheduling policy in *ATTR according to POLICY. */
267 extern int pthread_attr_setschedpolicy (pthread_attr_t
*__attr
, int __policy
)
270 /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
271 extern int pthread_attr_getinheritsched (__const pthread_attr_t
*__restrict
272 __attr
, int *__restrict __inherit
)
275 /* Set scheduling inheritance mode in *ATTR according to INHERIT. */
276 extern int pthread_attr_setinheritsched (pthread_attr_t
*__attr
,
277 int __inherit
) __THROW
;
280 /* Return in *SCOPE the scheduling contention scope of *ATTR. */
281 extern int pthread_attr_getscope (__const pthread_attr_t
*__restrict __attr
,
282 int *__restrict __scope
) __THROW
;
284 /* Set scheduling contention scope in *ATTR according to SCOPE. */
285 extern int pthread_attr_setscope (pthread_attr_t
*__attr
, int __scope
)
288 /* Return the previously set address for the stack. */
289 extern int pthread_attr_getstackaddr (__const pthread_attr_t
*__restrict
290 __attr
, void **__restrict __stackaddr
)
291 __THROW __attribute_deprecated__
;
293 /* Set the starting address of the stack of the thread to be created.
294 Depending on whether the stack grows up or down the value must either
295 be higher or lower than all the address in the memory block. The
296 minimal size of the block must be PTHREAD_STACK_MIN. */
297 extern int pthread_attr_setstackaddr (pthread_attr_t
*__attr
,
299 __THROW __attribute_deprecated__
;
301 /* Return the currently used minimal stack size. */
302 extern int pthread_attr_getstacksize (__const pthread_attr_t
*__restrict
303 __attr
, size_t *__restrict __stacksize
)
306 /* Add information about the minimum stack size needed for the thread
307 to be started. This size must never be less than PTHREAD_STACK_MIN
308 and must also not exceed the system limits. */
309 extern int pthread_attr_setstacksize (pthread_attr_t
*__attr
,
310 size_t __stacksize
) __THROW
;
313 /* Return the previously set address for the stack. */
314 extern int pthread_attr_getstack (__const pthread_attr_t
*__restrict __attr
,
315 void **__restrict __stackaddr
,
316 size_t *__restrict __stacksize
) __THROW
;
318 /* The following two interfaces are intended to replace the last two. They
319 require setting the address as well as the size since only setting the
320 address will make the implementation on some architectures impossible. */
321 extern int pthread_attr_setstack (pthread_attr_t
*__attr
, void *__stackaddr
,
322 size_t __stacksize
) __THROW
;
326 /* Thread created with attribute ATTR will be limited to run only on
327 the processors represented in CPUSET. */
328 extern int pthread_attr_setaffinity_np (pthread_attr_t
*__attr
,
330 __const cpu_set_t
*__cpuset
) __THROW
;
332 /* Get bit set in CPUSET representing the processors threads created with
334 extern int pthread_attr_getaffinity_np (__const pthread_attr_t
*__attr
,
336 cpu_set_t
*__cpuset
) __THROW
;
339 /* Initialize thread attribute *ATTR with attributes corresponding to the
340 already running thread TH. It shall be called on unitialized ATTR
341 and destroyed with pthread_attr_destroy when no longer needed. */
342 extern int pthread_getattr_np (pthread_t __th
, pthread_attr_t
*__attr
) __THROW
;
346 /* Functions for scheduling control. */
348 /* Set the scheduling parameters for TARGET_THREAD according to POLICY
350 extern int pthread_setschedparam (pthread_t __target_thread
, int __policy
,
351 __const
struct sched_param
*__param
)
354 /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
355 extern int pthread_getschedparam (pthread_t __target_thread
,
356 int *__restrict __policy
,
357 struct sched_param
*__restrict __param
)
362 /* Determine level of concurrency. */
363 extern int pthread_getconcurrency (void) __THROW
;
365 /* Set new concurrency level to LEVEL. */
366 extern int pthread_setconcurrency (int __level
) __THROW
;
370 /* Yield the processor to another thread or process.
371 This function is similar to the POSIX `sched_yield' function but
372 might be differently implemented in the case of a m-on-n thread
374 extern int pthread_yield (void) __THROW
;
377 /* Limit specified thread TH to run only on the processors represented
379 extern int pthread_setaffinity_np (pthread_t __th
, size_t __cpusetsize
,
380 __const cpu_set_t
*__cpuset
) __THROW
;
382 /* Get bit set in CPUSET representing the processors TH can run on. */
383 extern int pthread_getaffinity_np (pthread_t __th
, size_t __cpusetsize
,
384 cpu_set_t
*__cpuset
) __THROW
;
388 /* Functions for handling initialization. */
390 /* Guarantee that the initialization function INIT_ROUTINE will be called
391 only once, even if pthread_once is executed several times with the
392 same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
393 extern variable initialized to PTHREAD_ONCE_INIT. */
394 extern int pthread_once (pthread_once_t
*__once_control
,
395 void (*__init_routine
) (void)) __THROW
;
398 /* Functions for handling cancellation.
400 Note that these functions are explicitly not marked to not throw an
401 exception in C++ code. If cancellation is implemented by unwinding
402 this is necessary to have the compiler generate the unwind information. */
404 /* Set cancelability state of current thread to STATE, returning old
405 state in *OLDSTATE if OLDSTATE is not NULL. */
406 extern int pthread_setcancelstate (int __state
, int *__oldstate
);
408 /* Set cancellation state of current thread to TYPE, returning the old
409 type in *OLDTYPE if OLDTYPE is not NULL. */
410 extern int pthread_setcanceltype (int __type
, int *__oldtype
);
412 /* Cancel THREAD immediately or at the next possibility. */
413 extern int pthread_cancel (pthread_t __th
);
415 /* Test for pending cancellation for the current thread and terminate
416 the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
418 extern void pthread_testcancel (void);
421 /* Cancellation handling with integration into exception handling. */
427 __jmp_buf __cancel_jmp_buf
;
428 int __mask_was_saved
;
429 } __cancel_jmp_buf
[1];
431 } __pthread_unwind_buf_t
__attribute__ ((__aligned__
));
433 /* No special attributes by default. */
434 #ifndef __cleanup_fct_attribute
435 # define __cleanup_fct_attribute
439 /* Structure to hold the cleanup handler information. */
440 struct __pthread_cleanup_frame
442 void (*__cancel_routine
) (void *);
448 #if defined __GNUC__ && defined __EXCEPTIONS
450 /* Class to handle cancellation handler invocation. */
451 class __pthread_cleanup_class
453 void (*__cancel_routine
) (void *);
459 __pthread_cleanup_class (void (*__fct
) (void *), void *__arg
)
460 : __cancel_routine (__fct
), __cancel_arg (__arg
), __do_it (1) { }
461 ~__pthread_cleanup_class () { if (__do_it
) __cancel_routine (__cancel_arg
); }
462 void __setdoit (int __newval
) { __do_it
= __newval
; }
463 void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
,
465 void __restore () const { pthread_setcanceltype (__cancel_type
, 0); }
468 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
469 when the thread is canceled or calls pthread_exit. ROUTINE will also
470 be called with arguments ARG when the matching pthread_cleanup_pop
471 is executed with non-zero EXECUTE argument.
473 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
474 be used in matching pairs at the same nesting level of braces. */
475 # define pthread_cleanup_push(routine, arg) \
477 __pthread_cleanup_class __clframe (routine, arg)
479 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
480 If EXECUTE is non-zero, the handler function is called. */
481 # define pthread_cleanup_pop(execute) \
482 __clframe.__setdoit (execute); \
486 /* Install a cleanup handler as pthread_cleanup_push does, but also
487 saves the current cancellation type and sets it to deferred
489 # define pthread_cleanup_push_defer_np(routine, arg) \
491 __pthread_cleanup_class __clframe (routine, arg); \
494 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
495 restores the cancellation type that was in effect when the matching
496 pthread_cleanup_push_defer was called. */
497 # define pthread_cleanup_pop_restore_np(execute) \
498 __clframe.__restore (); \
499 __clframe.__setdoit (execute); \
503 /* Function called to call the cleanup handler. As an extern inline
504 function the compiler is free to decide inlining the change when
505 needed or fall back on the copy which must exist somewhere
508 __pthread_cleanup_routine (struct __pthread_cleanup_frame
*__frame
)
510 if (__frame
->__do_it
)
511 __frame
->__cancel_routine (__frame
->__cancel_arg
);
514 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
515 when the thread is canceled or calls pthread_exit. ROUTINE will also
516 be called with arguments ARG when the matching pthread_cleanup_pop
517 is executed with non-zero EXECUTE argument.
519 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
520 be used in matching pairs at the same nesting level of braces. */
521 # define pthread_cleanup_push(routine, arg) \
523 struct __pthread_cleanup_frame __clframe \
524 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
525 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
528 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
529 If EXECUTE is non-zero, the handler function is called. */
530 # define pthread_cleanup_pop(execute) \
531 __clframe.__do_it = (execute); \
535 /* Install a cleanup handler as pthread_cleanup_push does, but also
536 saves the current cancellation type and sets it to deferred
538 # define pthread_cleanup_push_defer_np(routine, arg) \
540 struct __pthread_cleanup_frame __clframe \
541 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
542 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
544 (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \
545 &__clframe.__cancel_type)
547 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
548 restores the cancellation type that was in effect when the matching
549 pthread_cleanup_push_defer was called. */
550 # define pthread_cleanup_pop_restore_np(execute) \
551 (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \
552 __clframe.__do_it = (execute); \
557 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
558 when the thread is canceled or calls pthread_exit. ROUTINE will also
559 be called with arguments ARG when the matching pthread_cleanup_pop
560 is executed with non-zero EXECUTE argument.
562 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
563 be used in matching pairs at the same nesting level of braces. */
564 # define pthread_cleanup_push(routine, arg) \
566 __pthread_unwind_buf_t __cancel_buf; \
567 void (*__cancel_routine) (void *) = (routine); \
568 void *__cancel_arg = (arg); \
569 int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) \
570 __cancel_buf.__cancel_jmp_buf, 0); \
571 if (__builtin_expect (not_first_call, 0)) \
573 __cancel_routine (__cancel_arg); \
574 __pthread_unwind_next (&__cancel_buf); \
578 __pthread_register_cancel (&__cancel_buf); \
580 extern void __pthread_register_cancel (__pthread_unwind_buf_t
*__buf
)
581 __cleanup_fct_attribute
;
583 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
584 If EXECUTE is non-zero, the handler function is called. */
585 # define pthread_cleanup_pop(execute) \
587 __pthread_unregister_cancel (&__cancel_buf); \
589 __cancel_routine (__cancel_arg); \
591 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t
*__buf
)
592 __cleanup_fct_attribute
;
595 /* Install a cleanup handler as pthread_cleanup_push does, but also
596 saves the current cancellation type and sets it to deferred
598 # define pthread_cleanup_push_defer_np(routine, arg) \
600 __pthread_unwind_buf_t __cancel_buf; \
601 void (*__cancel_routine) (void *) = (routine); \
602 void *__cancel_arg = (arg); \
603 int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) \
604 __cancel_buf.__cancel_jmp_buf, 0); \
605 if (__builtin_expect (not_first_call, 0)) \
607 __cancel_routine (__cancel_arg); \
608 __pthread_unwind_next (&__cancel_buf); \
612 __pthread_register_cancel_defer (&__cancel_buf); \
614 extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t
*__buf
)
615 __cleanup_fct_attribute
;
617 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
618 restores the cancellation type that was in effect when the matching
619 pthread_cleanup_push_defer was called. */
620 # define pthread_cleanup_pop_restore_np(execute) \
622 __pthread_unregister_cancel_restore (&__cancel_buf); \
624 __cancel_routine (__cancel_arg); \
626 extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t
*__buf
)
627 __cleanup_fct_attribute
;
630 /* Internal interface to initiate cleanup. */
631 extern void __pthread_unwind_next (__pthread_unwind_buf_t
*__buf
)
632 __cleanup_fct_attribute
__attribute ((__noreturn__
))
634 __attribute ((__weak__
))
639 /* Function used in the macros. */
640 struct __jmp_buf_tag
;
641 extern int __sigsetjmp (struct __jmp_buf_tag __env
[1], int __savemask
) __THROW
;
644 /* Mutex handling. */
646 /* Initialize a mutex. */
647 extern int pthread_mutex_init (pthread_mutex_t
*__mutex
,
648 __const pthread_mutexattr_t
*__mutexattr
)
651 /* Destroy a mutex. */
652 extern int pthread_mutex_destroy (pthread_mutex_t
*__mutex
) __THROW
;
654 /* Try locking a mutex. */
655 extern int pthread_mutex_trylock (pthread_mutex_t
*_mutex
) __THROW
;
658 extern int pthread_mutex_lock (pthread_mutex_t
*__mutex
) __THROW
;
661 /* Wait until lock becomes available, or specified time passes. */
662 extern int pthread_mutex_timedlock (pthread_mutex_t
*__restrict __mutex
,
663 __const
struct timespec
*__restrict
667 /* Unlock a mutex. */
668 extern int pthread_mutex_unlock (pthread_mutex_t
*__mutex
) __THROW
;
671 /* Functions for handling mutex attributes. */
673 /* Initialize mutex attribute object ATTR with default attributes
674 (kind is PTHREAD_MUTEX_TIMED_NP). */
675 extern int pthread_mutexattr_init (pthread_mutexattr_t
*__attr
) __THROW
;
677 /* Destroy mutex attribute object ATTR. */
678 extern int pthread_mutexattr_destroy (pthread_mutexattr_t
*__attr
) __THROW
;
680 /* Get the process-shared flag of the mutex attribute ATTR. */
681 extern int pthread_mutexattr_getpshared (__const pthread_mutexattr_t
*
683 int *__restrict __pshared
) __THROW
;
685 /* Set the process-shared flag of the mutex attribute ATTR. */
686 extern int pthread_mutexattr_setpshared (pthread_mutexattr_t
*__attr
,
687 int __pshared
) __THROW
;
690 /* Return in *KIND the mutex kind attribute in *ATTR. */
691 extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t
*__restrict
692 __attr
, int *__restrict __kind
) __THROW
;
694 /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
695 PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
696 PTHREAD_MUTEX_DEFAULT). */
697 extern int pthread_mutexattr_settype (pthread_mutexattr_t
*__attr
, int __kind
)
703 /* Functions for handling read-write locks. */
705 /* Initialize read-write lock RWLOCK using attributes ATTR, or use
706 the default values if later is NULL. */
707 extern int pthread_rwlock_init (pthread_rwlock_t
*__restrict __rwlock
,
708 __const pthread_rwlockattr_t
*__restrict
711 /* Destroy read-write lock RWLOCK. */
712 extern int pthread_rwlock_destroy (pthread_rwlock_t
*__rwlock
) __THROW
;
714 /* Acquire read lock for RWLOCK. */
715 extern int pthread_rwlock_rdlock (pthread_rwlock_t
*__rwlock
) __THROW
;
717 /* Try to acquire read lock for RWLOCK. */
718 extern int pthread_rwlock_tryrdlock (pthread_rwlock_t
*__rwlock
) __THROW
;
720 # ifdef __USE_XOPEN2K
721 /* Try to acquire read lock for RWLOCK or return after specfied time. */
722 extern int pthread_rwlock_timedrdlock (pthread_rwlock_t
*__restrict __rwlock
,
723 __const
struct timespec
*__restrict
727 /* Acquire write lock for RWLOCK. */
728 extern int pthread_rwlock_wrlock (pthread_rwlock_t
*__rwlock
) __THROW
;
730 /* Try to acquire write lock for RWLOCK. */
731 extern int pthread_rwlock_trywrlock (pthread_rwlock_t
*__rwlock
) __THROW
;
733 # ifdef __USE_XOPEN2K
734 /* Try to acquire write lock for RWLOCK or return after specfied time. */
735 extern int pthread_rwlock_timedwrlock (pthread_rwlock_t
*__restrict __rwlock
,
736 __const
struct timespec
*__restrict
741 extern int pthread_rwlock_unlock (pthread_rwlock_t
*__rwlock
) __THROW
;
744 /* Functions for handling read-write lock attributes. */
746 /* Initialize attribute object ATTR with default values. */
747 extern int pthread_rwlockattr_init (pthread_rwlockattr_t
*__attr
) __THROW
;
749 /* Destroy attribute object ATTR. */
750 extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t
*__attr
) __THROW
;
752 /* Return current setting of process-shared attribute of ATTR in PSHARED. */
753 extern int pthread_rwlockattr_getpshared (__const pthread_rwlockattr_t
*
755 int *__restrict __pshared
) __THROW
;
757 /* Set process-shared attribute of ATTR to PSHARED. */
758 extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t
*__attr
,
759 int __pshared
) __THROW
;
761 /* Return current setting of reader/writer preference. */
762 extern int pthread_rwlockattr_getkind_np (__const pthread_rwlockattr_t
*
764 int *__restrict __pref
) __THROW
;
766 /* Set reader/write preference. */
767 extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t
*__attr
,
772 /* Functions for handling conditional variables. */
774 /* Initialize condition variable COND using attributes ATTR, or use
775 the default values if later is NULL. */
776 extern int pthread_cond_init (pthread_cond_t
*__restrict __cond
,
777 __const pthread_condattr_t
*__restrict
778 __cond_attr
) __THROW
;
780 /* Destroy condition variable COND. */
781 extern int pthread_cond_destroy (pthread_cond_t
*__cond
) __THROW
;
783 /* Wake up one thread waiting for condition variable COND. */
784 extern int pthread_cond_signal (pthread_cond_t
*__cond
) __THROW
;
786 /* Wake up all threads waiting for condition variables COND. */
787 extern int pthread_cond_broadcast (pthread_cond_t
*__cond
) __THROW
;
789 /* Wait for condition variable COND to be signaled or broadcast.
790 MUTEX is assumed to be locked before.
792 This function is a cancellation point and therefore not marked with
794 extern int pthread_cond_wait (pthread_cond_t
*__restrict __cond
,
795 pthread_mutex_t
*__restrict __mutex
);
797 /* Wait for condition variable COND to be signaled or broadcast until
798 ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an
799 absolute time specification; zero is the beginning of the epoch
800 (00:00:00 GMT, January 1, 1970).
802 This function is a cancellation point and therefore not marked with
804 extern int pthread_cond_timedwait (pthread_cond_t
*__restrict __cond
,
805 pthread_mutex_t
*__restrict __mutex
,
806 __const
struct timespec
*__restrict
809 /* Functions for handling condition variable attributes. */
811 /* Initialize condition variable attribute ATTR. */
812 extern int pthread_condattr_init (pthread_condattr_t
*__attr
) __THROW
;
814 /* Destroy condition variable attribute ATTR. */
815 extern int pthread_condattr_destroy (pthread_condattr_t
*__attr
) __THROW
;
817 /* Get the process-shared flag of the condition variable attribute ATTR. */
818 extern int pthread_condattr_getpshared (__const pthread_condattr_t
*
820 int *__restrict __pshared
) __THROW
;
822 /* Set the process-shared flag of the condition variable attribute ATTR. */
823 extern int pthread_condattr_setpshared (pthread_condattr_t
*__attr
,
824 int __pshared
) __THROW
;
827 /* Get the clock selected for the conditon variable attribute ATTR. */
828 extern int pthread_condattr_getclock (__const pthread_condattr_t
*
830 __clockid_t
*__restrict __clock_id
)
833 /* Set the clock selected for the conditon variable attribute ATTR. */
834 extern int pthread_condattr_setclock (pthread_condattr_t
*__attr
,
835 __clockid_t __clock_id
) __THROW
;
841 /* Functions to handle spinlocks. */
843 /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can
844 be shared between different processes. */
845 extern int pthread_spin_init (pthread_spinlock_t
*__lock
, int __pshared
)
848 /* Destroy the spinlock LOCK. */
849 extern int pthread_spin_destroy (pthread_spinlock_t
*__lock
) __THROW
;
851 /* Wait until spinlock LOCK is retrieved. */
852 extern int pthread_spin_lock (pthread_spinlock_t
*__lock
) __THROW
;
854 /* Try to lock spinlock LOCK. */
855 extern int pthread_spin_trylock (pthread_spinlock_t
*__lock
) __THROW
;
857 /* Release spinlock LOCK. */
858 extern int pthread_spin_unlock (pthread_spinlock_t
*__lock
) __THROW
;
861 /* Functions to handle barriers. */
863 /* Initialize BARRIER with the attributes in ATTR. The barrier is
864 opened when COUNT waiters arrived. */
865 extern int pthread_barrier_init (pthread_barrier_t
*__restrict __barrier
,
866 __const pthread_barrierattr_t
*__restrict
867 __attr
, unsigned int __count
) __THROW
;
869 /* Destroy a previously dynamically initialized barrier BARRIER. */
870 extern int pthread_barrier_destroy (pthread_barrier_t
*__barrier
) __THROW
;
872 /* Wait on barrier BARRIER. */
873 extern int pthread_barrier_wait (pthread_barrier_t
*__barrier
) __THROW
;
876 /* Initialize barrier attribute ATTR. */
877 extern int pthread_barrierattr_init (pthread_barrierattr_t
*__attr
) __THROW
;
879 /* Destroy previously dynamically initialized barrier attribute ATTR. */
880 extern int pthread_barrierattr_destroy (pthread_barrierattr_t
*__attr
) __THROW
;
882 /* Get the process-shared flag of the barrier attribute ATTR. */
883 extern int pthread_barrierattr_getpshared (__const pthread_barrierattr_t
*
885 int *__restrict __pshared
) __THROW
;
887 /* Set the process-shared flag of the barrier attribute ATTR. */
888 extern int pthread_barrierattr_setpshared (pthread_barrierattr_t
*__attr
,
889 int __pshared
) __THROW
;
893 /* Functions for handling thread-specific data. */
895 /* Create a key value identifying a location in the thread-specific
896 data area. Each thread maintains a distinct thread-specific data
897 area. DESTR_FUNCTION, if non-NULL, is called with the value
898 associated to that key when the key is destroyed.
899 DESTR_FUNCTION is not called if the value associated is NULL when
900 the key is destroyed. */
901 extern int pthread_key_create (pthread_key_t
*__key
,
902 void (*__destr_function
) (void *)) __THROW
;
905 extern int pthread_key_delete (pthread_key_t __key
) __THROW
;
907 /* Return current value of the thread-specific data slot identified by KEY. */
908 extern void *pthread_getspecific (pthread_key_t __key
) __THROW
;
910 /* Store POINTER in the thread-specific data slot identified by KEY. */
911 extern int pthread_setspecific (pthread_key_t __key
,
912 __const
void *__pointer
) __THROW
;
916 /* Get ID of CPU-time clock for thread THREAD_ID. */
917 extern int pthread_getcpuclockid (pthread_t __thread_id
,
918 clockid_t
*__clock_id
) __THROW
;
922 /* Install handlers to be called when a new process is created with FORK.
923 The PREPARE handler is called in the parent process just before performing
924 FORK. The PARENT handler is called in the parent process just after FORK.
925 The CHILD handler is called in the child process. Each of the three
926 handlers can be NULL, meaning that no handler needs to be called at that
928 PTHREAD_ATFORK can be called several times, in which case the PREPARE
929 handlers are called in LIFO order (last added with PTHREAD_ATFORK,
930 first called before FORK), and the PARENT and CHILD handlers are called
931 in FIFO (first added, first called). */
933 extern int pthread_atfork (void (*__prepare
) (void),
934 void (*__parent
) (void),
935 void (*__child
) (void)) __THROW
;
939 #endif /* pthread.h */