Back to index

glibc  2.9
pthread.h
Go to the documentation of this file.
00001 /* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _PTHREAD_H
00021 #define _PTHREAD_H   1
00022 
00023 #include <features.h>
00024 #include <endian.h>
00025 #include <sched.h>
00026 #include <time.h>
00027 
00028 #define __need_sigset_t
00029 #include <signal.h>
00030 #include <bits/pthreadtypes.h>
00031 #include <bits/setjmp.h>
00032 #include <bits/wordsize.h>
00033 
00034 
00035 /* Detach state.  */
00036 enum
00037 {
00038   PTHREAD_CREATE_JOINABLE,
00039 #define PTHREAD_CREATE_JOINABLE    PTHREAD_CREATE_JOINABLE
00040   PTHREAD_CREATE_DETACHED
00041 #define PTHREAD_CREATE_DETACHED    PTHREAD_CREATE_DETACHED
00042 };
00043 
00044 
00045 /* Mutex types.  */
00046 enum
00047 {
00048   PTHREAD_MUTEX_TIMED_NP,
00049   PTHREAD_MUTEX_RECURSIVE_NP,
00050   PTHREAD_MUTEX_ERRORCHECK_NP,
00051   PTHREAD_MUTEX_ADAPTIVE_NP
00052 #ifdef __USE_UNIX98
00053   ,
00054   PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
00055   PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
00056   PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
00057   PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
00058 #endif
00059 #ifdef __USE_GNU
00060   /* For compatibility.  */
00061   , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP
00062 #endif
00063 };
00064 
00065 
00066 #ifdef __USE_GNU
00067 /* Robust mutex or not flags.  */
00068 enum
00069 {
00070   PTHREAD_MUTEX_STALLED_NP,
00071   PTHREAD_MUTEX_ROBUST_NP
00072 };
00073 #endif
00074 
00075 
00076 #ifdef __USE_UNIX98
00077 /* Mutex protocols.  */
00078 enum
00079 {
00080   PTHREAD_PRIO_NONE,
00081   PTHREAD_PRIO_INHERIT,
00082   PTHREAD_PRIO_PROTECT
00083 };
00084 #endif
00085 
00086 
00087 /* Mutex initializers.  */
00088 #if __WORDSIZE == 64
00089 # define PTHREAD_MUTEX_INITIALIZER \
00090   { { 0, 0, 0, 0, 0, 0, { 0, 0 } } }
00091 # ifdef __USE_GNU
00092 #  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
00093   { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0, 0 } } }
00094 #  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
00095   { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0, 0 } } }
00096 #  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
00097   { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0, 0 } } }
00098 # endif
00099 #else
00100 # define PTHREAD_MUTEX_INITIALIZER \
00101   { { 0, 0, 0, 0, 0, { 0 } } }
00102 # ifdef __USE_GNU
00103 #  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
00104   { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0 } } }
00105 #  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
00106   { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0 } } }
00107 #  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
00108   { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0 } } }
00109 # endif
00110 #endif
00111 
00112 
00113 /* Read-write lock types.  */
00114 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
00115 enum
00116 {
00117   PTHREAD_RWLOCK_PREFER_READER_NP,
00118   PTHREAD_RWLOCK_PREFER_WRITER_NP,
00119   PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
00120   PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP
00121 };
00122 
00123 /* Read-write lock initializers.  */
00124 # define PTHREAD_RWLOCK_INITIALIZER \
00125   { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
00126 # ifdef __USE_GNU
00127 #  if __WORDSIZE == 64
00128 #   define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
00129   { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                                         \
00130        PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
00131 #  else
00132 #   if __BYTE_ORDER == __LITTLE_ENDIAN
00133 #    define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
00134   { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, \
00135       0, 0, 0, 0 } }
00136 #   else
00137 #    define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
00138   { { 0, 0, 0, 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,\
00139       0 } }
00140 #   endif
00141 #  endif
00142 # endif
00143 #endif  /* Unix98 or XOpen2K */
00144 
00145 
00146 /* Scheduler inheritance.  */
00147 enum
00148 {
00149   PTHREAD_INHERIT_SCHED,
00150 #define PTHREAD_INHERIT_SCHED   PTHREAD_INHERIT_SCHED
00151   PTHREAD_EXPLICIT_SCHED
00152 #define PTHREAD_EXPLICIT_SCHED  PTHREAD_EXPLICIT_SCHED
00153 };
00154 
00155 
00156 /* Scope handling.  */
00157 enum
00158 {
00159   PTHREAD_SCOPE_SYSTEM,
00160 #define PTHREAD_SCOPE_SYSTEM    PTHREAD_SCOPE_SYSTEM
00161   PTHREAD_SCOPE_PROCESS
00162 #define PTHREAD_SCOPE_PROCESS   PTHREAD_SCOPE_PROCESS
00163 };
00164 
00165 
00166 /* Process shared or private flag.  */
00167 enum
00168 {
00169   PTHREAD_PROCESS_PRIVATE,
00170 #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
00171   PTHREAD_PROCESS_SHARED
00172 #define PTHREAD_PROCESS_SHARED  PTHREAD_PROCESS_SHARED
00173 };
00174 
00175 
00176 
00177 /* Conditional variable handling.  */
00178 #define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
00179 
00180 
00181 /* Cleanup buffers */
00182 struct _pthread_cleanup_buffer
00183 {
00184   void (*__routine) (void *);             /* Function to call.  */
00185   void *__arg;                            /* Its argument.  */
00186   int __canceltype;                       /* Saved cancellation type. */
00187   struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions.  */
00188 };
00189 
00190 /* Cancellation */
00191 enum
00192 {
00193   PTHREAD_CANCEL_ENABLE,
00194 #define PTHREAD_CANCEL_ENABLE   PTHREAD_CANCEL_ENABLE
00195   PTHREAD_CANCEL_DISABLE
00196 #define PTHREAD_CANCEL_DISABLE  PTHREAD_CANCEL_DISABLE
00197 };
00198 enum
00199 {
00200   PTHREAD_CANCEL_DEFERRED,
00201 #define PTHREAD_CANCEL_DEFERRED    PTHREAD_CANCEL_DEFERRED
00202   PTHREAD_CANCEL_ASYNCHRONOUS
00203 #define PTHREAD_CANCEL_ASYNCHRONOUS       PTHREAD_CANCEL_ASYNCHRONOUS
00204 };
00205 #define PTHREAD_CANCELED ((void *) -1)
00206 
00207 
00208 /* Single execution handling.  */
00209 #define PTHREAD_ONCE_INIT 0
00210 
00211 
00212 #ifdef __USE_XOPEN2K
00213 /* Value returned by 'pthread_barrier_wait' for one of the threads after
00214    the required number of threads have called this function.
00215    -1 is distinct from 0 and all errno constants */
00216 # define PTHREAD_BARRIER_SERIAL_THREAD -1
00217 #endif
00218 
00219 
00220 __BEGIN_DECLS
00221 
00222 /* Create a new thread, starting with execution of START-ROUTINE
00223    getting passed ARG.  Creation attributed come from ATTR.  The new
00224    handle is stored in *NEWTHREAD.  */
00225 extern int pthread_create (pthread_t *__restrict __newthread,
00226                         __const pthread_attr_t *__restrict __attr,
00227                         void *(*__start_routine) (void *),
00228                         void *__restrict __arg) __THROW __nonnull ((1, 3));
00229 
00230 /* Terminate calling thread.
00231 
00232    The registered cleanup handlers are called via exception handling
00233    so we cannot mark this function with __THROW.*/
00234 extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
00235 
00236 /* Make calling thread wait for termination of the thread TH.  The
00237    exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
00238    is not NULL.
00239 
00240    This function is a cancellation point and therefore not marked with
00241    __THROW.  */
00242 extern int pthread_join (pthread_t __th, void **__thread_return);
00243 
00244 #ifdef __USE_GNU
00245 /* Check whether thread TH has terminated.  If yes return the status of
00246    the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL.  */
00247 extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
00248 
00249 /* Make calling thread wait for termination of the thread TH, but only
00250    until TIMEOUT.  The exit status of the thread is stored in
00251    *THREAD_RETURN, if THREAD_RETURN is not NULL.
00252 
00253    This function is a cancellation point and therefore not marked with
00254    __THROW.  */
00255 extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
00256                              __const struct timespec *__abstime);
00257 #endif
00258 
00259 /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
00260    The resources of TH will therefore be freed immediately when it
00261    terminates, instead of waiting for another thread to perform PTHREAD_JOIN
00262    on it.  */
00263 extern int pthread_detach (pthread_t __th) __THROW;
00264 
00265 
00266 /* Obtain the identifier of the current thread.  */
00267 extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__));
00268 
00269 /* Compare two thread identifiers.  */
00270 extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __THROW;
00271 
00272 
00273 /* Thread attribute handling.  */
00274 
00275 /* Initialize thread attribute *ATTR with default attributes
00276    (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
00277     no user-provided stack).  */
00278 extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1));
00279 
00280 /* Destroy thread attribute *ATTR.  */
00281 extern int pthread_attr_destroy (pthread_attr_t *__attr)
00282      __THROW __nonnull ((1));
00283 
00284 /* Get detach state attribute.  */
00285 extern int pthread_attr_getdetachstate (__const pthread_attr_t *__attr,
00286                                    int *__detachstate)
00287      __THROW __nonnull ((1, 2));
00288 
00289 /* Set detach state attribute.  */
00290 extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
00291                                    int __detachstate)
00292      __THROW __nonnull ((1));
00293 
00294 
00295 /* Get the size of the guard area created for stack overflow protection.  */
00296 extern int pthread_attr_getguardsize (__const pthread_attr_t *__attr,
00297                                   size_t *__guardsize)
00298      __THROW __nonnull ((1, 2));
00299 
00300 /* Set the size of the guard area created for stack overflow protection.  */
00301 extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
00302                                   size_t __guardsize)
00303      __THROW __nonnull ((1));
00304 
00305 
00306 /* Return in *PARAM the scheduling parameters of *ATTR.  */
00307 extern int pthread_attr_getschedparam (__const pthread_attr_t *__restrict
00308                                    __attr,
00309                                    struct sched_param *__restrict __param)
00310      __THROW __nonnull ((1, 2));
00311 
00312 /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM.  */
00313 extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
00314                                    __const struct sched_param *__restrict
00315                                    __param) __THROW __nonnull ((1, 2));
00316 
00317 /* Return in *POLICY the scheduling policy of *ATTR.  */
00318 extern int pthread_attr_getschedpolicy (__const pthread_attr_t *__restrict
00319                                    __attr, int *__restrict __policy)
00320      __THROW __nonnull ((1, 2));
00321 
00322 /* Set scheduling policy in *ATTR according to POLICY.  */
00323 extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
00324      __THROW __nonnull ((1));
00325 
00326 /* Return in *INHERIT the scheduling inheritance mode of *ATTR.  */
00327 extern int pthread_attr_getinheritsched (__const pthread_attr_t *__restrict
00328                                     __attr, int *__restrict __inherit)
00329      __THROW __nonnull ((1, 2));
00330 
00331 /* Set scheduling inheritance mode in *ATTR according to INHERIT.  */
00332 extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
00333                                     int __inherit)
00334      __THROW __nonnull ((1));
00335 
00336 
00337 /* Return in *SCOPE the scheduling contention scope of *ATTR.  */
00338 extern int pthread_attr_getscope (__const pthread_attr_t *__restrict __attr,
00339                               int *__restrict __scope)
00340      __THROW __nonnull ((1, 2));
00341 
00342 /* Set scheduling contention scope in *ATTR according to SCOPE.  */
00343 extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
00344      __THROW __nonnull ((1));
00345 
00346 /* Return the previously set address for the stack.  */
00347 extern int pthread_attr_getstackaddr (__const pthread_attr_t *__restrict
00348                                   __attr, void **__restrict __stackaddr)
00349      __THROW __nonnull ((1, 2)) __attribute_deprecated__;
00350 
00351 /* Set the starting address of the stack of the thread to be created.
00352    Depending on whether the stack grows up or down the value must either
00353    be higher or lower than all the address in the memory block.  The
00354    minimal size of the block must be PTHREAD_STACK_MIN.  */
00355 extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
00356                                   void *__stackaddr)
00357      __THROW __nonnull ((1)) __attribute_deprecated__;
00358 
00359 /* Return the currently used minimal stack size.  */
00360 extern int pthread_attr_getstacksize (__const pthread_attr_t *__restrict
00361                                   __attr, size_t *__restrict __stacksize)
00362      __THROW __nonnull ((1, 2));
00363 
00364 /* Add information about the minimum stack size needed for the thread
00365    to be started.  This size must never be less than PTHREAD_STACK_MIN
00366    and must also not exceed the system limits.  */
00367 extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
00368                                   size_t __stacksize)
00369      __THROW __nonnull ((1));
00370 
00371 #ifdef __USE_XOPEN2K
00372 /* Return the previously set address for the stack.  */
00373 extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
00374                               void **__restrict __stackaddr,
00375                               size_t *__restrict __stacksize)
00376      __THROW __nonnull ((1, 2, 3));
00377 
00378 /* The following two interfaces are intended to replace the last two.  They
00379    require setting the address as well as the size since only setting the
00380    address will make the implementation on some architectures impossible.  */
00381 extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
00382                               size_t __stacksize) __THROW __nonnull ((1));
00383 #endif
00384 
00385 #ifdef __USE_GNU
00386 /* Thread created with attribute ATTR will be limited to run only on
00387    the processors represented in CPUSET.  */
00388 extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr,
00389                                    size_t __cpusetsize,
00390                                    __const cpu_set_t *__cpuset)
00391      __THROW __nonnull ((1, 3));
00392 
00393 /* Get bit set in CPUSET representing the processors threads created with
00394    ATTR can run on.  */
00395 extern int pthread_attr_getaffinity_np (__const pthread_attr_t *__attr,
00396                                    size_t __cpusetsize,
00397                                    cpu_set_t *__cpuset)
00398      __THROW __nonnull ((1, 3));
00399 
00400 
00401 /* Initialize thread attribute *ATTR with attributes corresponding to the
00402    already running thread TH.  It shall be called on uninitialized ATTR
00403    and destroyed with pthread_attr_destroy when no longer needed.  */
00404 extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
00405      __THROW __nonnull ((2));
00406 #endif
00407 
00408 
00409 /* Functions for scheduling control.  */
00410 
00411 /* Set the scheduling parameters for TARGET_THREAD according to POLICY
00412    and *PARAM.  */
00413 extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
00414                               __const struct sched_param *__param)
00415      __THROW __nonnull ((3));
00416 
00417 /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
00418 extern int pthread_getschedparam (pthread_t __target_thread,
00419                               int *__restrict __policy,
00420                               struct sched_param *__restrict __param)
00421      __THROW __nonnull ((2, 3));
00422 
00423 /* Set the scheduling priority for TARGET_THREAD.  */
00424 extern int pthread_setschedprio (pthread_t __target_thread, int __prio)
00425      __THROW;
00426 
00427 
00428 #ifdef __USE_UNIX98
00429 /* Determine level of concurrency.  */
00430 extern int pthread_getconcurrency (void) __THROW;
00431 
00432 /* Set new concurrency level to LEVEL.  */
00433 extern int pthread_setconcurrency (int __level) __THROW;
00434 #endif
00435 
00436 #ifdef __USE_GNU
00437 /* Yield the processor to another thread or process.
00438    This function is similar to the POSIX `sched_yield' function but
00439    might be differently implemented in the case of a m-on-n thread
00440    implementation.  */
00441 extern int pthread_yield (void) __THROW;
00442 
00443 
00444 /* Limit specified thread TH to run only on the processors represented
00445    in CPUSET.  */
00446 extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
00447                                __const cpu_set_t *__cpuset)
00448      __THROW __nonnull ((3));
00449 
00450 /* Get bit set in CPUSET representing the processors TH can run on.  */
00451 extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
00452                                cpu_set_t *__cpuset)
00453      __THROW __nonnull ((3));
00454 #endif
00455 
00456 
00457 /* Functions for handling initialization.  */
00458 
00459 /* Guarantee that the initialization function INIT_ROUTINE will be called
00460    only once, even if pthread_once is executed several times with the
00461    same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
00462    extern variable initialized to PTHREAD_ONCE_INIT.
00463 
00464    The initialization functions might throw exception which is why
00465    this function is not marked with __THROW.  */
00466 extern int pthread_once (pthread_once_t *__once_control,
00467                       void (*__init_routine) (void)) __nonnull ((1, 2));
00468 
00469 
00470 /* Functions for handling cancellation.
00471 
00472    Note that these functions are explicitly not marked to not throw an
00473    exception in C++ code.  If cancellation is implemented by unwinding
00474    this is necessary to have the compiler generate the unwind information.  */
00475 
00476 /* Set cancelability state of current thread to STATE, returning old
00477    state in *OLDSTATE if OLDSTATE is not NULL.  */
00478 extern int pthread_setcancelstate (int __state, int *__oldstate);
00479 
00480 /* Set cancellation state of current thread to TYPE, returning the old
00481    type in *OLDTYPE if OLDTYPE is not NULL.  */
00482 extern int pthread_setcanceltype (int __type, int *__oldtype);
00483 
00484 /* Cancel THREAD immediately or at the next possibility.  */
00485 extern int pthread_cancel (pthread_t __th);
00486 
00487 /* Test for pending cancellation for the current thread and terminate
00488    the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
00489    cancelled.  */
00490 extern void pthread_testcancel (void);
00491 
00492 
00493 /* Cancellation handling with integration into exception handling.  */
00494 
00495 typedef struct
00496 {
00497   struct
00498   {
00499     __jmp_buf __cancel_jmp_buf;
00500     int __mask_was_saved;
00501   } __cancel_jmp_buf[1];
00502   void *__pad[4];
00503 } __pthread_unwind_buf_t __attribute__ ((__aligned__));
00504 
00505 /* No special attributes by default.  */
00506 #ifndef __cleanup_fct_attribute
00507 # define __cleanup_fct_attribute
00508 #endif
00509 
00510 
00511 /* Structure to hold the cleanup handler information.  */
00512 struct __pthread_cleanup_frame
00513 {
00514   void (*__cancel_routine) (void *);
00515   void *__cancel_arg;
00516   int __do_it;
00517   int __cancel_type;
00518 };
00519 
00520 #if defined __GNUC__ && defined __EXCEPTIONS
00521 # ifdef __cplusplus
00522 /* Class to handle cancellation handler invocation.  */
00523 class __pthread_cleanup_class
00524 {
00525   void (*__cancel_routine) (void *);
00526   void *__cancel_arg;
00527   int __do_it;
00528   int __cancel_type;
00529 
00530  public:
00531   __pthread_cleanup_class (void (*__fct) (void *), void *__arg)
00532     : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { }
00533   ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); }
00534   void __setdoit (int __newval) { __do_it = __newval; }
00535   void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,
00536                                       &__cancel_type); }
00537   void __restore () const { pthread_setcanceltype (__cancel_type, 0); }
00538 };
00539 
00540 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
00541    when the thread is canceled or calls pthread_exit.  ROUTINE will also
00542    be called with arguments ARG when the matching pthread_cleanup_pop
00543    is executed with non-zero EXECUTE argument.
00544 
00545    pthread_cleanup_push and pthread_cleanup_pop are macros and must always
00546    be used in matching pairs at the same nesting level of braces.  */
00547 #  define pthread_cleanup_push(routine, arg) \
00548   do {                                                               \
00549     __pthread_cleanup_class __clframe (routine, arg)
00550 
00551 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
00552    If EXECUTE is non-zero, the handler function is called. */
00553 #  define pthread_cleanup_pop(execute) \
00554     __clframe.__setdoit (execute);                                   \
00555   } while (0)
00556 
00557 #  ifdef __USE_GNU
00558 /* Install a cleanup handler as pthread_cleanup_push does, but also
00559    saves the current cancellation type and sets it to deferred
00560    cancellation.  */
00561 #   define pthread_cleanup_push_defer_np(routine, arg) \
00562   do {                                                               \
00563     __pthread_cleanup_class __clframe (routine, arg);                       \
00564     __clframe.__defer ()
00565 
00566 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
00567    restores the cancellation type that was in effect when the matching
00568    pthread_cleanup_push_defer was called.  */
00569 #   define pthread_cleanup_pop_restore_np(execute) \
00570     __clframe.__restore ();                                          \
00571     __clframe.__setdoit (execute);                                   \
00572   } while (0)
00573 #  endif
00574 # else
00575 /* Function called to call the cleanup handler.  As an extern inline
00576    function the compiler is free to decide inlining the change when
00577    needed or fall back on the copy which must exist somewhere
00578    else.  */
00579 __extern_inline void
00580 __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
00581 {
00582   if (__frame->__do_it)
00583     __frame->__cancel_routine (__frame->__cancel_arg);
00584 }
00585 
00586 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
00587    when the thread is canceled or calls pthread_exit.  ROUTINE will also
00588    be called with arguments ARG when the matching pthread_cleanup_pop
00589    is executed with non-zero EXECUTE argument.
00590 
00591    pthread_cleanup_push and pthread_cleanup_pop are macros and must always
00592    be used in matching pairs at the same nesting level of braces.  */
00593 #  define pthread_cleanup_push(routine, arg) \
00594   do {                                                               \
00595     struct __pthread_cleanup_frame __clframe                                \
00596       __attribute__ ((__cleanup__ (__pthread_cleanup_routine)))                    \
00597       = { .__cancel_routine = (routine), .__cancel_arg = (arg),                    \
00598          .__do_it = 1 };
00599 
00600 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
00601    If EXECUTE is non-zero, the handler function is called. */
00602 #  define pthread_cleanup_pop(execute) \
00603     __clframe.__do_it = (execute);                                   \
00604   } while (0)
00605 
00606 #  ifdef __USE_GNU
00607 /* Install a cleanup handler as pthread_cleanup_push does, but also
00608    saves the current cancellation type and sets it to deferred
00609    cancellation.  */
00610 #   define pthread_cleanup_push_defer_np(routine, arg) \
00611   do {                                                               \
00612     struct __pthread_cleanup_frame __clframe                                \
00613       __attribute__ ((__cleanup__ (__pthread_cleanup_routine)))                    \
00614       = { .__cancel_routine = (routine), .__cancel_arg = (arg),                    \
00615          .__do_it = 1 };                                             \
00616     (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,                  \
00617                               &__clframe.__cancel_type)
00618 
00619 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
00620    restores the cancellation type that was in effect when the matching
00621    pthread_cleanup_push_defer was called.  */
00622 #   define pthread_cleanup_pop_restore_np(execute) \
00623     (void) pthread_setcanceltype (__clframe.__cancel_type, NULL);           \
00624     __clframe.__do_it = (execute);                                   \
00625   } while (0)
00626 #  endif
00627 # endif
00628 #else
00629 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
00630    when the thread is canceled or calls pthread_exit.  ROUTINE will also
00631    be called with arguments ARG when the matching pthread_cleanup_pop
00632    is executed with non-zero EXECUTE argument.
00633 
00634    pthread_cleanup_push and pthread_cleanup_pop are macros and must always
00635    be used in matching pairs at the same nesting level of braces.  */
00636 # define pthread_cleanup_push(routine, arg) \
00637   do {                                                               \
00638     __pthread_unwind_buf_t __cancel_buf;                             \
00639     void (*__cancel_routine) (void *) = (routine);                          \
00640     void *__cancel_arg = (arg);                                             \
00641     int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *)            \
00642                                   __cancel_buf.__cancel_jmp_buf, 0);      \
00643     if (__builtin_expect (not_first_call, 0))                               \
00644       {                                                                     \
00645        __cancel_routine (__cancel_arg);                              \
00646        __pthread_unwind_next (&__cancel_buf);                               \
00647        /* NOTREACHED */                                              \
00648       }                                                                     \
00649                                                                      \
00650     __pthread_register_cancel (&__cancel_buf);                              \
00651     do {
00652 extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
00653      __cleanup_fct_attribute;
00654 
00655 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
00656    If EXECUTE is non-zero, the handler function is called. */
00657 # define pthread_cleanup_pop(execute) \
00658       do; while (0); /* Empty to allow label before pthread_cleanup_pop.  */  \
00659     } while (0);                                                     \
00660     __pthread_unregister_cancel (&__cancel_buf);                     \
00661     if (execute)                                                     \
00662       __cancel_routine (__cancel_arg);                                      \
00663   } while (0)
00664 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
00665   __cleanup_fct_attribute;
00666 
00667 # ifdef __USE_GNU
00668 /* Install a cleanup handler as pthread_cleanup_push does, but also
00669    saves the current cancellation type and sets it to deferred
00670    cancellation.  */
00671 #  define pthread_cleanup_push_defer_np(routine, arg) \
00672   do {                                                               \
00673     __pthread_unwind_buf_t __cancel_buf;                             \
00674     void (*__cancel_routine) (void *) = (routine);                          \
00675     void *__cancel_arg = (arg);                                             \
00676     int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *)            \
00677                                   __cancel_buf.__cancel_jmp_buf, 0);      \
00678     if (__builtin_expect (not_first_call, 0))                               \
00679       {                                                                     \
00680        __cancel_routine (__cancel_arg);                              \
00681        __pthread_unwind_next (&__cancel_buf);                               \
00682        /* NOTREACHED */                                              \
00683       }                                                                     \
00684                                                                      \
00685     __pthread_register_cancel_defer (&__cancel_buf);                        \
00686     do {
00687 extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf)
00688      __cleanup_fct_attribute;
00689 
00690 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
00691    restores the cancellation type that was in effect when the matching
00692    pthread_cleanup_push_defer was called.  */
00693 #  define pthread_cleanup_pop_restore_np(execute) \
00694       do; while (0); /* Empty to allow label before pthread_cleanup_pop.  */  \
00695     } while (0);                                                     \
00696     __pthread_unregister_cancel_restore (&__cancel_buf);                    \
00697     if (execute)                                                     \
00698       __cancel_routine (__cancel_arg);                                      \
00699   } while (0)
00700 extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf)
00701   __cleanup_fct_attribute;
00702 # endif
00703 
00704 /* Internal interface to initiate cleanup.  */
00705 extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
00706      __cleanup_fct_attribute __attribute__ ((__noreturn__))
00707 # ifndef SHARED
00708      __attribute__ ((__weak__))
00709 # endif
00710      ;
00711 #endif
00712 
00713 /* Function used in the macros.  */
00714 struct __jmp_buf_tag;
00715 extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROW;
00716 
00717 
00718 /* Mutex handling.  */
00719 
00720 /* Initialize a mutex.  */
00721 extern int pthread_mutex_init (pthread_mutex_t *__mutex,
00722                             __const pthread_mutexattr_t *__mutexattr)
00723      __THROW __nonnull ((1));
00724 
00725 /* Destroy a mutex.  */
00726 extern int pthread_mutex_destroy (pthread_mutex_t *__mutex)
00727      __THROW __nonnull ((1));
00728 
00729 /* Try locking a mutex.  */
00730 extern int pthread_mutex_trylock (pthread_mutex_t *__mutex)
00731      __THROW __nonnull ((1));
00732 
00733 /* Lock a mutex.  */
00734 extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
00735      __THROW __nonnull ((1));
00736 
00737 #ifdef __USE_XOPEN2K
00738 /* Wait until lock becomes available, or specified time passes. */
00739 extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
00740                                     __const struct timespec *__restrict
00741                                     __abstime) __THROW __nonnull ((1, 2));
00742 #endif
00743 
00744 /* Unlock a mutex.  */
00745 extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
00746      __THROW __nonnull ((1));
00747 
00748 
00749 #ifdef __USE_UNIX98
00750 /* Get the priority ceiling of MUTEX.  */
00751 extern int pthread_mutex_getprioceiling (__const pthread_mutex_t *
00752                                     __restrict __mutex,
00753                                     int *__restrict __prioceiling)
00754      __THROW __nonnull ((1, 2));
00755 
00756 /* Set the priority ceiling of MUTEX to PRIOCEILING, return old
00757    priority ceiling value in *OLD_CEILING.  */
00758 extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex,
00759                                     int __prioceiling,
00760                                     int *__restrict __old_ceiling)
00761      __THROW __nonnull ((1, 3));
00762 #endif
00763 
00764 
00765 #ifdef __USE_GNU
00766 /* Declare the state protected by MUTEX as consistent.  */
00767 extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex)
00768      __THROW __nonnull ((1));
00769 #endif
00770 
00771 
00772 /* Functions for handling mutex attributes.  */
00773 
00774 /* Initialize mutex attribute object ATTR with default attributes
00775    (kind is PTHREAD_MUTEX_TIMED_NP).  */
00776 extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr)
00777      __THROW __nonnull ((1));
00778 
00779 /* Destroy mutex attribute object ATTR.  */
00780 extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr)
00781      __THROW __nonnull ((1));
00782 
00783 /* Get the process-shared flag of the mutex attribute ATTR.  */
00784 extern int pthread_mutexattr_getpshared (__const pthread_mutexattr_t *
00785                                     __restrict __attr,
00786                                     int *__restrict __pshared)
00787      __THROW __nonnull ((1, 2));
00788 
00789 /* Set the process-shared flag of the mutex attribute ATTR.  */
00790 extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
00791                                     int __pshared)
00792      __THROW __nonnull ((1));
00793 
00794 #ifdef __USE_UNIX98
00795 /* Return in *KIND the mutex kind attribute in *ATTR.  */
00796 extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
00797                                   __attr, int *__restrict __kind)
00798      __THROW __nonnull ((1, 2));
00799 
00800 /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
00801    PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
00802    PTHREAD_MUTEX_DEFAULT).  */
00803 extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
00804      __THROW __nonnull ((1));
00805 
00806 /* Return in *PROTOCOL the mutex protocol attribute in *ATTR.  */
00807 extern int pthread_mutexattr_getprotocol (__const pthread_mutexattr_t *
00808                                      __restrict __attr,
00809                                      int *__restrict __protocol)
00810      __THROW __nonnull ((1, 2));
00811 
00812 /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
00813    PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT).  */
00814 extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr,
00815                                      int __protocol)
00816      __THROW __nonnull ((1));
00817 
00818 /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR.  */
00819 extern int pthread_mutexattr_getprioceiling (__const pthread_mutexattr_t *
00820                                         __restrict __attr,
00821                                         int *__restrict __prioceiling)
00822      __THROW __nonnull ((1, 2));
00823 
00824 /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING.  */
00825 extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr,
00826                                         int __prioceiling)
00827      __THROW __nonnull ((1));
00828 #endif
00829 
00830 #ifdef __USE_GNU
00831 /* Get the robustness flag of the mutex attribute ATTR.  */
00832 extern int pthread_mutexattr_getrobust_np (__const pthread_mutexattr_t *__attr,
00833                                       int *__robustness)
00834      __THROW __nonnull ((1, 2));
00835 
00836 /* Set the robustness flag of the mutex attribute ATTR.  */
00837 extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr,
00838                                       int __robustness)
00839      __THROW __nonnull ((1));
00840 #endif
00841 
00842 
00843 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
00844 /* Functions for handling read-write locks.  */
00845 
00846 /* Initialize read-write lock RWLOCK using attributes ATTR, or use
00847    the default values if later is NULL.  */
00848 extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
00849                             __const pthread_rwlockattr_t *__restrict
00850                             __attr) __THROW __nonnull ((1));
00851 
00852 /* Destroy read-write lock RWLOCK.  */
00853 extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock)
00854      __THROW __nonnull ((1));
00855 
00856 /* Acquire read lock for RWLOCK.  */
00857 extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock)
00858      __THROW __nonnull ((1));
00859 
00860 /* Try to acquire read lock for RWLOCK.  */
00861 extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
00862   __THROW __nonnull ((1));
00863 
00864 # ifdef __USE_XOPEN2K
00865 /* Try to acquire read lock for RWLOCK or return after specfied time.  */
00866 extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
00867                                    __const struct timespec *__restrict
00868                                    __abstime) __THROW __nonnull ((1, 2));
00869 # endif
00870 
00871 /* Acquire write lock for RWLOCK.  */
00872 extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
00873      __THROW __nonnull ((1));
00874 
00875 /* Try to acquire write lock for RWLOCK.  */
00876 extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
00877      __THROW __nonnull ((1));
00878 
00879 # ifdef __USE_XOPEN2K
00880 /* Try to acquire write lock for RWLOCK or return after specfied time.  */
00881 extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
00882                                    __const struct timespec *__restrict
00883                                    __abstime) __THROW __nonnull ((1, 2));
00884 # endif
00885 
00886 /* Unlock RWLOCK.  */
00887 extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
00888      __THROW __nonnull ((1));
00889 
00890 
00891 /* Functions for handling read-write lock attributes.  */
00892 
00893 /* Initialize attribute object ATTR with default values.  */
00894 extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr)
00895      __THROW __nonnull ((1));
00896 
00897 /* Destroy attribute object ATTR.  */
00898 extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr)
00899      __THROW __nonnull ((1));
00900 
00901 /* Return current setting of process-shared attribute of ATTR in PSHARED.  */
00902 extern int pthread_rwlockattr_getpshared (__const pthread_rwlockattr_t *
00903                                      __restrict __attr,
00904                                      int *__restrict __pshared)
00905      __THROW __nonnull ((1, 2));
00906 
00907 /* Set process-shared attribute of ATTR to PSHARED.  */
00908 extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
00909                                      int __pshared)
00910      __THROW __nonnull ((1));
00911 
00912 /* Return current setting of reader/writer preference.  */
00913 extern int pthread_rwlockattr_getkind_np (__const pthread_rwlockattr_t *
00914                                      __restrict __attr,
00915                                      int *__restrict __pref)
00916      __THROW __nonnull ((1, 2));
00917 
00918 /* Set reader/write preference.  */
00919 extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
00920                                      int __pref) __THROW __nonnull ((1));
00921 #endif
00922 
00923 
00924 /* Functions for handling conditional variables.  */
00925 
00926 /* Initialize condition variable COND using attributes ATTR, or use
00927    the default values if later is NULL.  */
00928 extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
00929                            __const pthread_condattr_t *__restrict
00930                            __cond_attr) __THROW __nonnull ((1));
00931 
00932 /* Destroy condition variable COND.  */
00933 extern int pthread_cond_destroy (pthread_cond_t *__cond)
00934      __THROW __nonnull ((1));
00935 
00936 /* Wake up one thread waiting for condition variable COND.  */
00937 extern int pthread_cond_signal (pthread_cond_t *__cond)
00938      __THROW __nonnull ((1));
00939 
00940 /* Wake up all threads waiting for condition variables COND.  */
00941 extern int pthread_cond_broadcast (pthread_cond_t *__cond)
00942      __THROW __nonnull ((1));
00943 
00944 /* Wait for condition variable COND to be signaled or broadcast.
00945    MUTEX is assumed to be locked before.
00946 
00947    This function is a cancellation point and therefore not marked with
00948    __THROW.  */
00949 extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
00950                            pthread_mutex_t *__restrict __mutex)
00951      __nonnull ((1, 2));
00952 
00953 /* Wait for condition variable COND to be signaled or broadcast until
00954    ABSTIME.  MUTEX is assumed to be locked before.  ABSTIME is an
00955    absolute time specification; zero is the beginning of the epoch
00956    (00:00:00 GMT, January 1, 1970).
00957 
00958    This function is a cancellation point and therefore not marked with
00959    __THROW.  */
00960 extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
00961                                pthread_mutex_t *__restrict __mutex,
00962                                __const struct timespec *__restrict
00963                                __abstime) __nonnull ((1, 2, 3));
00964 
00965 /* Functions for handling condition variable attributes.  */
00966 
00967 /* Initialize condition variable attribute ATTR.  */
00968 extern int pthread_condattr_init (pthread_condattr_t *__attr)
00969      __THROW __nonnull ((1));
00970 
00971 /* Destroy condition variable attribute ATTR.  */
00972 extern int pthread_condattr_destroy (pthread_condattr_t *__attr)
00973      __THROW __nonnull ((1));
00974 
00975 /* Get the process-shared flag of the condition variable attribute ATTR.  */
00976 extern int pthread_condattr_getpshared (__const pthread_condattr_t *
00977                                         __restrict __attr,
00978                                         int *__restrict __pshared)
00979      __THROW __nonnull ((1, 2));
00980 
00981 /* Set the process-shared flag of the condition variable attribute ATTR.  */
00982 extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
00983                                         int __pshared) __THROW __nonnull ((1));
00984 
00985 #ifdef __USE_XOPEN2K
00986 /* Get the clock selected for the conditon variable attribute ATTR.  */
00987 extern int pthread_condattr_getclock (__const pthread_condattr_t *
00988                                   __restrict __attr,
00989                                   __clockid_t *__restrict __clock_id)
00990      __THROW __nonnull ((1, 2));
00991 
00992 /* Set the clock selected for the conditon variable attribute ATTR.  */
00993 extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
00994                                   __clockid_t __clock_id)
00995      __THROW __nonnull ((1));
00996 #endif
00997 
00998 
00999 #ifdef __USE_XOPEN2K
01000 /* Functions to handle spinlocks.  */
01001 
01002 /* Initialize the spinlock LOCK.  If PSHARED is nonzero the spinlock can
01003    be shared between different processes.  */
01004 extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
01005      __THROW __nonnull ((1));
01006 
01007 /* Destroy the spinlock LOCK.  */
01008 extern int pthread_spin_destroy (pthread_spinlock_t *__lock)
01009      __THROW __nonnull ((1));
01010 
01011 /* Wait until spinlock LOCK is retrieved.  */
01012 extern int pthread_spin_lock (pthread_spinlock_t *__lock)
01013      __THROW __nonnull ((1));
01014 
01015 /* Try to lock spinlock LOCK.  */
01016 extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
01017      __THROW __nonnull ((1));
01018 
01019 /* Release spinlock LOCK.  */
01020 extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
01021      __THROW __nonnull ((1));
01022 
01023 
01024 /* Functions to handle barriers.  */
01025 
01026 /* Initialize BARRIER with the attributes in ATTR.  The barrier is
01027    opened when COUNT waiters arrived.  */
01028 extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
01029                              __const pthread_barrierattr_t *__restrict
01030                              __attr, unsigned int __count)
01031      __THROW __nonnull ((1));
01032 
01033 /* Destroy a previously dynamically initialized barrier BARRIER.  */
01034 extern int pthread_barrier_destroy (pthread_barrier_t *__barrier)
01035      __THROW __nonnull ((1));
01036 
01037 /* Wait on barrier BARRIER.  */
01038 extern int pthread_barrier_wait (pthread_barrier_t *__barrier)
01039      __THROW __nonnull ((1));
01040 
01041 
01042 /* Initialize barrier attribute ATTR.  */
01043 extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr)
01044      __THROW __nonnull ((1));
01045 
01046 /* Destroy previously dynamically initialized barrier attribute ATTR.  */
01047 extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr)
01048      __THROW __nonnull ((1));
01049 
01050 /* Get the process-shared flag of the barrier attribute ATTR.  */
01051 extern int pthread_barrierattr_getpshared (__const pthread_barrierattr_t *
01052                                       __restrict __attr,
01053                                       int *__restrict __pshared)
01054      __THROW __nonnull ((1, 2));
01055 
01056 /* Set the process-shared flag of the barrier attribute ATTR.  */
01057 extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
01058                                            int __pshared)
01059      __THROW __nonnull ((1));
01060 #endif
01061 
01062 
01063 /* Functions for handling thread-specific data.  */
01064 
01065 /* Create a key value identifying a location in the thread-specific
01066    data area.  Each thread maintains a distinct thread-specific data
01067    area.  DESTR_FUNCTION, if non-NULL, is called with the value
01068    associated to that key when the key is destroyed.
01069    DESTR_FUNCTION is not called if the value associated is NULL when
01070    the key is destroyed.  */
01071 extern int pthread_key_create (pthread_key_t *__key,
01072                             void (*__destr_function) (void *))
01073      __THROW __nonnull ((1));
01074 
01075 /* Destroy KEY.  */
01076 extern int pthread_key_delete (pthread_key_t __key) __THROW;
01077 
01078 /* Return current value of the thread-specific data slot identified by KEY.  */
01079 extern void *pthread_getspecific (pthread_key_t __key) __THROW;
01080 
01081 /* Store POINTER in the thread-specific data slot identified by KEY. */
01082 extern int pthread_setspecific (pthread_key_t __key,
01083                             __const void *__pointer) __THROW ;
01084 
01085 
01086 #ifdef __USE_XOPEN2K
01087 /* Get ID of CPU-time clock for thread THREAD_ID.  */
01088 extern int pthread_getcpuclockid (pthread_t __thread_id,
01089                               __clockid_t *__clock_id)
01090      __THROW __nonnull ((2));
01091 #endif
01092 
01093 
01094 /* Install handlers to be called when a new process is created with FORK.
01095    The PREPARE handler is called in the parent process just before performing
01096    FORK. The PARENT handler is called in the parent process just after FORK.
01097    The CHILD handler is called in the child process.  Each of the three
01098    handlers can be NULL, meaning that no handler needs to be called at that
01099    point.
01100    PTHREAD_ATFORK can be called several times, in which case the PREPARE
01101    handlers are called in LIFO order (last added with PTHREAD_ATFORK,
01102    first called before FORK), and the PARENT and CHILD handlers are called
01103    in FIFO (first added, first called).  */
01104 
01105 extern int pthread_atfork (void (*__prepare) (void),
01106                         void (*__parent) (void),
01107                         void (*__child) (void)) __THROW;
01108 
01109 
01110 #ifdef __USE_EXTERN_INLINES
01111 /* Optimizations.  */
01112 __extern_inline int
01113 __NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2))
01114 {
01115   return __thread1 == __thread2;
01116 }
01117 #endif
01118 
01119 __END_DECLS
01120 
01121 #endif /* pthread.h */