Back to index

glibc  2.9
pthread.h
Go to the documentation of this file.
00001 /* Linuxthreads - a simple clone()-based implementation of Posix        */
00002 /* threads for Linux.                                                   */
00003 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr)              */
00004 /*                                                                      */
00005 /* This program is free software; you can redistribute it and/or        */
00006 /* modify it under the terms of the GNU Library General Public License  */
00007 /* as published by the Free Software Foundation; either version 2       */
00008 /* of the License, or (at your option) any later version.               */
00009 /*                                                                      */
00010 /* This program 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        */
00013 /* GNU Library General Public License for more details.                 */
00014 
00015 #ifndef _PTHREAD_H
00016 #define _PTHREAD_H   1
00017 
00018 #include <features.h>
00019 
00020 #include <sched.h>
00021 #include <time.h>
00022 
00023 #define __need_sigset_t
00024 #include <signal.h>
00025 #include <bits/pthreadtypes.h>
00026 #include <bits/initspin.h>
00027 
00028 
00029 __BEGIN_DECLS
00030 
00031 /* Initializers.  */
00032 
00033 #define PTHREAD_MUTEX_INITIALIZER \
00034   {0, 0, 0, PTHREAD_MUTEX_TIMED_NP, __LOCK_INITIALIZER}
00035 #ifdef __USE_GNU
00036 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
00037   {0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, __LOCK_INITIALIZER}
00038 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
00039   {0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, __LOCK_INITIALIZER}
00040 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
00041   {0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __LOCK_INITIALIZER}
00042 #endif
00043 
00044 #define PTHREAD_COND_INITIALIZER {__LOCK_INITIALIZER, 0, "", 0}
00045 
00046 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
00047 # define PTHREAD_RWLOCK_INITIALIZER \
00048   { __LOCK_INITIALIZER, 0, NULL, NULL, NULL,                                \
00049     PTHREAD_RWLOCK_DEFAULT_NP, PTHREAD_PROCESS_PRIVATE }
00050 #endif
00051 #ifdef __USE_GNU
00052 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
00053   { __LOCK_INITIALIZER, 0, NULL, NULL, NULL,                                \
00054     PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, PTHREAD_PROCESS_PRIVATE }
00055 #endif
00056 
00057 /* Values for attributes.  */
00058 
00059 enum
00060 {
00061   PTHREAD_CREATE_JOINABLE,
00062 #define PTHREAD_CREATE_JOINABLE    PTHREAD_CREATE_JOINABLE
00063   PTHREAD_CREATE_DETACHED
00064 #define PTHREAD_CREATE_DETACHED    PTHREAD_CREATE_DETACHED
00065 };
00066 
00067 enum
00068 {
00069   PTHREAD_INHERIT_SCHED,
00070 #define PTHREAD_INHERIT_SCHED      PTHREAD_INHERIT_SCHED
00071   PTHREAD_EXPLICIT_SCHED
00072 #define PTHREAD_EXPLICIT_SCHED     PTHREAD_EXPLICIT_SCHED
00073 };
00074 
00075 enum
00076 {
00077   PTHREAD_SCOPE_SYSTEM,
00078 #define PTHREAD_SCOPE_SYSTEM       PTHREAD_SCOPE_SYSTEM
00079   PTHREAD_SCOPE_PROCESS
00080 #define PTHREAD_SCOPE_PROCESS      PTHREAD_SCOPE_PROCESS
00081 };
00082 
00083 enum
00084 {
00085   PTHREAD_MUTEX_TIMED_NP,
00086   PTHREAD_MUTEX_RECURSIVE_NP,
00087   PTHREAD_MUTEX_ERRORCHECK_NP,
00088   PTHREAD_MUTEX_ADAPTIVE_NP
00089 #ifdef __USE_UNIX98
00090   ,
00091   PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
00092   PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
00093   PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
00094   PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
00095 #endif
00096 #ifdef __USE_GNU
00097   /* For compatibility.  */
00098   , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_ADAPTIVE_NP
00099 #endif
00100 };
00101 
00102 enum
00103 {
00104   PTHREAD_PROCESS_PRIVATE,
00105 #define PTHREAD_PROCESS_PRIVATE    PTHREAD_PROCESS_PRIVATE
00106   PTHREAD_PROCESS_SHARED
00107 #define PTHREAD_PROCESS_SHARED     PTHREAD_PROCESS_SHARED
00108 };
00109 
00110 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
00111 enum
00112 {
00113   PTHREAD_RWLOCK_PREFER_READER_NP,
00114   PTHREAD_RWLOCK_PREFER_WRITER_NP,
00115   PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
00116   PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_WRITER_NP
00117 };
00118 #endif /* Unix98 */
00119 
00120 #define PTHREAD_ONCE_INIT 0
00121 
00122 /* Special constants */
00123 
00124 #ifdef __USE_XOPEN2K
00125 /* -1 is distinct from 0 and all errno constants */
00126 # define PTHREAD_BARRIER_SERIAL_THREAD -1
00127 #endif
00128 
00129 /* Cleanup buffers */
00130 
00131 struct _pthread_cleanup_buffer
00132 {
00133   void (*__routine) (void *);               /* Function to call.  */
00134   void *__arg;                              /* Its argument.  */
00135   int __canceltype;                  /* Saved cancellation type. */
00136   struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions.  */
00137 };
00138 
00139 /* Cancellation */
00140 
00141 enum
00142 {
00143   PTHREAD_CANCEL_ENABLE,
00144 #define PTHREAD_CANCEL_ENABLE      PTHREAD_CANCEL_ENABLE
00145   PTHREAD_CANCEL_DISABLE
00146 #define PTHREAD_CANCEL_DISABLE     PTHREAD_CANCEL_DISABLE
00147 };
00148 enum
00149 {
00150   PTHREAD_CANCEL_DEFERRED,
00151 #define PTHREAD_CANCEL_DEFERRED    PTHREAD_CANCEL_DEFERRED
00152   PTHREAD_CANCEL_ASYNCHRONOUS
00153 #define PTHREAD_CANCEL_ASYNCHRONOUS       PTHREAD_CANCEL_ASYNCHRONOUS
00154 };
00155 #define PTHREAD_CANCELED ((void *) -1)
00156 
00157 
00158 /* Function for handling threads.  */
00159 
00160 /* Create a thread with given attributes ATTR (or default attributes
00161    if ATTR is NULL), and call function START_ROUTINE with given
00162    arguments ARG.  */
00163 extern int pthread_create (pthread_t *__restrict __threadp,
00164                         __const pthread_attr_t *__restrict __attr,
00165                         void *(*__start_routine) (void *),
00166                         void *__restrict __arg) __THROW;
00167 
00168 /* Obtain the identifier of the current thread.  */
00169 extern pthread_t pthread_self (void) __THROW;
00170 
00171 /* Compare two thread identifiers.  */
00172 extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __THROW;
00173 
00174 /* Terminate calling thread.  */
00175 extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
00176 
00177 /* Make calling thread wait for termination of the thread TH.  The
00178    exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
00179    is not NULL.  */
00180 extern int pthread_join (pthread_t __th, void **__thread_return);
00181 
00182 /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
00183    The resources of TH will therefore be freed immediately when it
00184    terminates, instead of waiting for another thread to perform PTHREAD_JOIN
00185    on it.  */
00186 extern int pthread_detach (pthread_t __th) __THROW;
00187 
00188 
00189 /* Functions for handling attributes.  */
00190 
00191 /* Initialize thread attribute *ATTR with default attributes
00192    (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
00193     no user-provided stack).  */
00194 extern int pthread_attr_init (pthread_attr_t *__attr) __THROW;
00195 
00196 /* Destroy thread attribute *ATTR.  */
00197 extern int pthread_attr_destroy (pthread_attr_t *__attr) __THROW;
00198 
00199 /* Set the `detachstate' attribute in *ATTR according to DETACHSTATE.  */
00200 extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
00201                                    int __detachstate) __THROW;
00202 
00203 /* Return in *DETACHSTATE the `detachstate' attribute in *ATTR.  */
00204 extern int pthread_attr_getdetachstate (__const pthread_attr_t *__attr,
00205                                    int *__detachstate) __THROW;
00206 
00207 /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM.  */
00208 extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
00209                                    __const struct sched_param *__restrict
00210                                    __param) __THROW;
00211 
00212 /* Return in *PARAM the scheduling parameters of *ATTR.  */
00213 extern int pthread_attr_getschedparam (__const pthread_attr_t *__restrict
00214                                    __attr,
00215                                    struct sched_param *__restrict __param)
00216      __THROW;
00217 
00218 /* Set scheduling policy in *ATTR according to POLICY.  */
00219 extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
00220      __THROW;
00221 
00222 /* Return in *POLICY the scheduling policy of *ATTR.  */
00223 extern int pthread_attr_getschedpolicy (__const pthread_attr_t *__restrict
00224                                    __attr, int *__restrict __policy)
00225      __THROW;
00226 
00227 /* Set scheduling inheritance mode in *ATTR according to INHERIT.  */
00228 extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
00229                                     int __inherit) __THROW;
00230 
00231 /* Return in *INHERIT the scheduling inheritance mode of *ATTR.  */
00232 extern int pthread_attr_getinheritsched (__const pthread_attr_t *__restrict
00233                                     __attr, int *__restrict __inherit)
00234      __THROW;
00235 
00236 /* Set scheduling contention scope in *ATTR according to SCOPE.  */
00237 extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
00238      __THROW;
00239 
00240 /* Return in *SCOPE the scheduling contention scope of *ATTR.  */
00241 extern int pthread_attr_getscope (__const pthread_attr_t *__restrict __attr,
00242                               int *__restrict __scope) __THROW;
00243 
00244 #ifdef __USE_UNIX98
00245 /* Set the size of the guard area at the bottom of the thread.  */
00246 extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
00247                                   size_t __guardsize) __THROW;
00248 
00249 /* Get the size of the guard area at the bottom of the thread.  */
00250 extern int pthread_attr_getguardsize (__const pthread_attr_t *__restrict
00251                                   __attr, size_t *__restrict __guardsize)
00252      __THROW;
00253 #endif
00254 
00255 /* Set the starting address of the stack of the thread to be created.
00256    Depending on whether the stack grows up or down the value must either
00257    be higher or lower than all the address in the memory block.  The
00258    minimal size of the block must be PTHREAD_STACK_MIN.  */
00259 extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
00260                                   void *__stackaddr) __THROW;
00261 
00262 /* Return the previously set address for the stack.  */
00263 extern int pthread_attr_getstackaddr (__const pthread_attr_t *__restrict
00264                                   __attr, void **__restrict __stackaddr)
00265      __THROW;
00266 
00267 #ifdef __USE_XOPEN2K
00268 /* The following two interfaces are intended to replace the last two.  They
00269    require setting the address as well as the size since only setting the
00270    address will make the implementation on some architectures impossible.  */
00271 extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
00272                               size_t __stacksize) __THROW;
00273 
00274 /* Return the previously set address for the stack.  */
00275 extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
00276                               void **__restrict __stackaddr,
00277                               size_t *__restrict __stacksize) __THROW;
00278 #endif
00279 
00280 /* Add information about the minimum stack size needed for the thread
00281    to be started.  This size must never be less than PTHREAD_STACK_MIN
00282    and must also not exceed the system limits.  */
00283 extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
00284                                   size_t __stacksize) __THROW;
00285 
00286 /* Return the currently used minimal stack size.  */
00287 extern int pthread_attr_getstacksize (__const pthread_attr_t *__restrict
00288                                   __attr, size_t *__restrict __stacksize)
00289      __THROW;
00290 
00291 #ifdef __USE_GNU
00292 /* Initialize thread attribute *ATTR with attributes corresponding to the
00293    already running thread TH.  It shall be called on unitialized ATTR
00294    and destroyed with pthread_attr_destroy when no longer needed.  */
00295 extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) __THROW;
00296 #endif
00297 
00298 /* Functions for scheduling control.  */
00299 
00300 /* Set the scheduling parameters for TARGET_THREAD according to POLICY
00301    and *PARAM.  */
00302 extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
00303                               __const struct sched_param *__param)
00304      __THROW;
00305 
00306 /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD.  */
00307 extern int pthread_getschedparam (pthread_t __target_thread,
00308                               int *__restrict __policy,
00309                               struct sched_param *__restrict __param)
00310      __THROW;
00311 
00312 #ifdef __USE_UNIX98
00313 /* Determine level of concurrency.  */
00314 extern int pthread_getconcurrency (void) __THROW;
00315 
00316 /* Set new concurrency level to LEVEL.  */
00317 extern int pthread_setconcurrency (int __level) __THROW;
00318 #endif
00319 
00320 #ifdef __USE_GNU
00321 /* Yield the processor to another thread or process.
00322    This function is similar to the POSIX `sched_yield' function but
00323    might be differently implemented in the case of a m-on-n thread
00324    implementation.  */
00325 extern int pthread_yield (void) __THROW;
00326 #endif
00327 
00328 /* Functions for mutex handling.  */
00329 
00330 /* Initialize MUTEX using attributes in *MUTEX_ATTR, or use the
00331    default values if later is NULL.  */
00332 extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,
00333                             __const pthread_mutexattr_t *__restrict
00334                             __mutex_attr) __THROW;
00335 
00336 /* Destroy MUTEX.  */
00337 extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) __THROW;
00338 
00339 /* Try to lock MUTEX.  */
00340 extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) __THROW;
00341 
00342 /* Wait until lock for MUTEX becomes available and lock it.  */
00343 extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __THROW;
00344 
00345 #ifdef __USE_XOPEN2K
00346 /* Wait until lock becomes available, or specified time passes. */
00347 extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
00348                                 __const struct timespec *__restrict
00349                                 __abstime) __THROW;
00350 #endif
00351 
00352 /* Unlock MUTEX.  */
00353 extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROW;
00354 
00355 
00356 /* Functions for handling mutex attributes.  */
00357 
00358 /* Initialize mutex attribute object ATTR with default attributes
00359    (kind is PTHREAD_MUTEX_TIMED_NP).  */
00360 extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr) __THROW;
00361 
00362 /* Destroy mutex attribute object ATTR.  */
00363 extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr) __THROW;
00364 
00365 /* Get the process-shared flag of the mutex attribute ATTR.  */
00366 extern int pthread_mutexattr_getpshared (__const pthread_mutexattr_t *
00367                                     __restrict __attr,
00368                                     int *__restrict __pshared) __THROW;
00369 
00370 /* Set the process-shared flag of the mutex attribute ATTR.  */
00371 extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
00372                                     int __pshared) __THROW;
00373 
00374 #ifdef __USE_UNIX98
00375 /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
00376    PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
00377    PTHREAD_MUTEX_DEFAULT).  */
00378 extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
00379      __THROW;
00380 
00381 /* Return in *KIND the mutex kind attribute in *ATTR.  */
00382 extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
00383                                   __attr, int *__restrict __kind) __THROW;
00384 #endif
00385 
00386 
00387 /* Functions for handling conditional variables.  */
00388 
00389 /* Initialize condition variable COND using attributes ATTR, or use
00390    the default values if later is NULL.  */
00391 extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
00392                            __const pthread_condattr_t *__restrict
00393                            __cond_attr) __THROW;
00394 
00395 /* Destroy condition variable COND.  */
00396 extern int pthread_cond_destroy (pthread_cond_t *__cond) __THROW;
00397 
00398 /* Wake up one thread waiting for condition variable COND.  */
00399 extern int pthread_cond_signal (pthread_cond_t *__cond) __THROW;
00400 
00401 /* Wake up all threads waiting for condition variables COND.  */
00402 extern int pthread_cond_broadcast (pthread_cond_t *__cond) __THROW;
00403 
00404 /* Wait for condition variable COND to be signaled or broadcast.
00405    MUTEX is assumed to be locked before.  */
00406 extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
00407                            pthread_mutex_t *__restrict __mutex);
00408 
00409 /* Wait for condition variable COND to be signaled or broadcast until
00410    ABSTIME.  MUTEX is assumed to be locked before.  ABSTIME is an
00411    absolute time specification; zero is the beginning of the epoch
00412    (00:00:00 GMT, January 1, 1970).  */
00413 extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
00414                                pthread_mutex_t *__restrict __mutex,
00415                                __const struct timespec *__restrict
00416                                __abstime);
00417 
00418 /* Functions for handling condition variable attributes.  */
00419 
00420 /* Initialize condition variable attribute ATTR.  */
00421 extern int pthread_condattr_init (pthread_condattr_t *__attr) __THROW;
00422 
00423 /* Destroy condition variable attribute ATTR.  */
00424 extern int pthread_condattr_destroy (pthread_condattr_t *__attr) __THROW;
00425 
00426 /* Get the process-shared flag of the condition variable attribute ATTR.  */
00427 extern int pthread_condattr_getpshared (__const pthread_condattr_t *
00428                                    __restrict __attr,
00429                                    int *__restrict __pshared) __THROW;
00430 
00431 /* Set the process-shared flag of the condition variable attribute ATTR.  */
00432 extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
00433                                    int __pshared) __THROW;
00434 
00435 
00436 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
00437 /* Functions for handling read-write locks.  */
00438 
00439 /* Initialize read-write lock RWLOCK using attributes ATTR, or use
00440    the default values if later is NULL.  */
00441 extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
00442                             __const pthread_rwlockattr_t *__restrict
00443                             __attr) __THROW;
00444 
00445 /* Destroy read-write lock RWLOCK.  */
00446 extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) __THROW;
00447 
00448 /* Acquire read lock for RWLOCK.  */
00449 extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) __THROW;
00450 
00451 /* Try to acquire read lock for RWLOCK.  */
00452 extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) __THROW;
00453 
00454 # ifdef __USE_XOPEN2K
00455 /* Try to acquire read lock for RWLOCK or return after specfied time.  */
00456 extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
00457                                    __const struct timespec *__restrict
00458                                    __abstime) __THROW;
00459 # endif
00460 
00461 /* Acquire write lock for RWLOCK.  */
00462 extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) __THROW;
00463 
00464 /* Try to acquire write lock for RWLOCK.  */
00465 extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) __THROW;
00466 
00467 # ifdef __USE_XOPEN2K
00468 /* Try to acquire write lock for RWLOCK or return after specfied time.  */
00469 extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
00470                                    __const struct timespec *__restrict
00471                                    __abstime) __THROW;
00472 # endif
00473 
00474 /* Unlock RWLOCK.  */
00475 extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) __THROW;
00476 
00477 
00478 /* Functions for handling read-write lock attributes.  */
00479 
00480 /* Initialize attribute object ATTR with default values.  */
00481 extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr) __THROW;
00482 
00483 /* Destroy attribute object ATTR.  */
00484 extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr) __THROW;
00485 
00486 /* Return current setting of process-shared attribute of ATTR in PSHARED.  */
00487 extern int pthread_rwlockattr_getpshared (__const pthread_rwlockattr_t *
00488                                      __restrict __attr,
00489                                      int *__restrict __pshared) __THROW;
00490 
00491 /* Set process-shared attribute of ATTR to PSHARED.  */
00492 extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
00493                                      int __pshared) __THROW;
00494 
00495 /* Return current setting of reader/writer preference.  */
00496 extern int pthread_rwlockattr_getkind_np (__const pthread_rwlockattr_t *__attr,
00497                                      int *__pref) __THROW;
00498 
00499 /* Set reader/write preference.  */
00500 extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
00501                                      int __pref) __THROW;
00502 #endif
00503 
00504 #ifdef __USE_XOPEN2K
00505 /* The IEEE Std. 1003.1j-2000 introduces functions to implement
00506    spinlocks.  */
00507 
00508 /* Initialize the spinlock LOCK.  If PSHARED is nonzero the spinlock can
00509    be shared between different processes.  */
00510 extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
00511      __THROW;
00512 
00513 /* Destroy the spinlock LOCK.  */
00514 extern int pthread_spin_destroy (pthread_spinlock_t *__lock) __THROW;
00515 
00516 /* Wait until spinlock LOCK is retrieved.  */
00517 extern int pthread_spin_lock (pthread_spinlock_t *__lock) __THROW;
00518 
00519 /* Try to lock spinlock LOCK.  */
00520 extern int pthread_spin_trylock (pthread_spinlock_t *__lock) __THROW;
00521 
00522 /* Release spinlock LOCK.  */
00523 extern int pthread_spin_unlock (pthread_spinlock_t *__lock) __THROW;
00524 
00525 
00526 /* Barriers are a also a new feature in 1003.1j-2000. */
00527 
00528 extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
00529                              __const pthread_barrierattr_t *__restrict
00530                              __attr, unsigned int __count) __THROW;
00531 
00532 extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) __THROW;
00533 
00534 extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr) __THROW;
00535 
00536 extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr) __THROW;
00537 
00538 extern int pthread_barrierattr_getpshared (__const pthread_barrierattr_t *
00539                                       __restrict __attr,
00540                                       int *__restrict __pshared) __THROW;
00541 
00542 extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
00543                                       int __pshared) __THROW;
00544 
00545 extern int pthread_barrier_wait (pthread_barrier_t *__barrier) __THROW;
00546 #endif
00547 
00548 
00549 /* Functions for handling thread-specific data.  */
00550 
00551 /* Create a key value identifying a location in the thread-specific
00552    data area.  Each thread maintains a distinct thread-specific data
00553    area.  DESTR_FUNCTION, if non-NULL, is called with the value
00554    associated to that key when the key is destroyed.
00555    DESTR_FUNCTION is not called if the value associated is NULL when
00556    the key is destroyed.  */
00557 extern int pthread_key_create (pthread_key_t *__key,
00558                             void (*__destr_function) (void *)) __THROW;
00559 
00560 /* Destroy KEY.  */
00561 extern int pthread_key_delete (pthread_key_t __key) __THROW;
00562 
00563 /* Store POINTER in the thread-specific data slot identified by KEY. */
00564 extern int pthread_setspecific (pthread_key_t __key,
00565                             __const void *__pointer) __THROW;
00566 
00567 /* Return current value of the thread-specific data slot identified by KEY.  */
00568 extern void *pthread_getspecific (pthread_key_t __key) __THROW;
00569 
00570 
00571 /* Functions for handling initialization.  */
00572 
00573 /* Guarantee that the initialization function INIT_ROUTINE will be called
00574    only once, even if pthread_once is executed several times with the
00575    same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
00576    extern variable initialized to PTHREAD_ONCE_INIT.
00577 
00578    The initialization functions might throw exception which is why
00579    this function is not marked with __THROW.  */
00580 extern int pthread_once (pthread_once_t *__once_control,
00581                       void (*__init_routine) (void));
00582 
00583 
00584 /* Functions for handling cancellation.  */
00585 
00586 /* Set cancelability state of current thread to STATE, returning old
00587    state in *OLDSTATE if OLDSTATE is not NULL.  */
00588 extern int pthread_setcancelstate (int __state, int *__oldstate);
00589 
00590 /* Set cancellation state of current thread to TYPE, returning the old
00591    type in *OLDTYPE if OLDTYPE is not NULL.  */
00592 extern int pthread_setcanceltype (int __type, int *__oldtype);
00593 
00594 /* Cancel THREAD immediately or at the next possibility.  */
00595 extern int pthread_cancel (pthread_t __cancelthread);
00596 
00597 /* Test for pending cancellation for the current thread and terminate
00598    the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
00599    cancelled.  */
00600 extern void pthread_testcancel (void);
00601 
00602 
00603 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
00604    when the thread is cancelled or calls pthread_exit.  ROUTINE will also
00605    be called with arguments ARG when the matching pthread_cleanup_pop
00606    is executed with non-zero EXECUTE argument.
00607    pthread_cleanup_push and pthread_cleanup_pop are macros and must always
00608    be used in matching pairs at the same nesting level of braces. */
00609 
00610 #define pthread_cleanup_push(routine,arg) \
00611   { struct _pthread_cleanup_buffer _buffer;                                 \
00612     _pthread_cleanup_push (&_buffer, (routine), (arg));
00613 
00614 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer,
00615                                void (*__routine) (void *),
00616                                void *__arg) __THROW;
00617 
00618 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
00619    If EXECUTE is non-zero, the handler function is called. */
00620 
00621 #define pthread_cleanup_pop(execute) \
00622     _pthread_cleanup_pop (&_buffer, (execute)); }
00623 
00624 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer,
00625                               int __execute) __THROW;
00626 
00627 /* Install a cleanup handler as pthread_cleanup_push does, but also
00628    saves the current cancellation type and set it to deferred cancellation.  */
00629 
00630 #ifdef __USE_GNU
00631 # define pthread_cleanup_push_defer_np(routine,arg) \
00632   { struct _pthread_cleanup_buffer _buffer;                                 \
00633     _pthread_cleanup_push_defer (&_buffer, (routine), (arg));
00634 
00635 extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *__buffer,
00636                                     void (*__routine) (void *),
00637                                     void *__arg) __THROW;
00638 
00639 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
00640    restores the cancellation type that was in effect when the matching
00641    pthread_cleanup_push_defer was called.  */
00642 
00643 # define pthread_cleanup_pop_restore_np(execute) \
00644   _pthread_cleanup_pop_restore (&_buffer, (execute)); }
00645 
00646 extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *__buffer,
00647                                      int __execute) __THROW;
00648 #endif
00649 
00650 
00651 #ifdef __USE_XOPEN2K
00652 /* Get ID of CPU-time clock for thread THREAD_ID.  */
00653 extern int pthread_getcpuclockid (pthread_t __thread_id,
00654                               __clockid_t *__clock_id) __THROW;
00655 #endif
00656 
00657 
00658 /* Functions for handling signals.  */
00659 #include <bits/sigthread.h>
00660 
00661 
00662 /* Functions for handling process creation and process execution.  */
00663 
00664 /* Install handlers to be called when a new process is created with FORK.
00665    The PREPARE handler is called in the parent process just before performing
00666    FORK. The PARENT handler is called in the parent process just after FORK.
00667    The CHILD handler is called in the child process.  Each of the three
00668    handlers can be NULL, meaning that no handler needs to be called at that
00669    point.
00670    PTHREAD_ATFORK can be called several times, in which case the PREPARE
00671    handlers are called in LIFO order (last added with PTHREAD_ATFORK,
00672    first called before FORK), and the PARENT and CHILD handlers are called
00673    in FIFO (first added, first called).  */
00674 
00675 extern int pthread_atfork (void (*__prepare) (void),
00676                         void (*__parent) (void),
00677                         void (*__child) (void)) __THROW;
00678 
00679 /* Terminate all threads in the program except the calling process.
00680    Should be called just before invoking one of the exec*() functions.  */
00681 
00682 extern void pthread_kill_other_threads_np (void) __THROW;
00683 
00684 __END_DECLS
00685 
00686 #endif /* pthread.h */