Dr Andrew Scott G7VAV

My photo
 
March 2024
Mo Tu We Th Fr Sa Su
26 27 28 29 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
1 2 3 4 5 6 7


pthread.h
0001: /* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
0002:    Free Software Foundation, Inc.
0003:    This file is part of the GNU C Library.
0004: 
0005:    The GNU C Library is free software; you can redistribute it and/or
0006:    modify it under the terms of the GNU Lesser General Public
0007:    License as published by the Free Software Foundation; either
0008:    version 2.1 of the License, or (at your option) any later version.
0009: 
0010:    The GNU C Library is distributed in the hope that it will be useful,
0011:    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013:    Lesser General Public License for more details.
0014: 
0015:    You should have received a copy of the GNU Lesser General Public
0016:    License along with the GNU C Library; if not, write to the Free
0017:    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
0018:    02111-1307 USA.  */
0019: 
0020: #ifndef _PTHREAD_H
0021: #define _PTHREAD_H      1
0022: 
0023: #include <features.h>
0024: #include <endian.h>
0025: #include <sched.h>
0026: #include <time.h>
0027: 
0028: #include <bits/pthreadtypes.h>
0029: #include <bits/setjmp.h>
0030: #include <bits/wordsize.h>
0031: 
0032: 
0033: /* Detach state.  */
0034: enum
0035: {
0036:   PTHREAD_CREATE_JOINABLE,
0037: #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
0038:   PTHREAD_CREATE_DETACHED
0039: #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
0040: };
0041: 
0042: 
0043: /* Mutex types.  */
0044: enum
0045: {
0046:   PTHREAD_MUTEX_TIMED_NP,
0047:   PTHREAD_MUTEX_RECURSIVE_NP,
0048:   PTHREAD_MUTEX_ERRORCHECK_NP,
0049:   PTHREAD_MUTEX_ADAPTIVE_NP
0050: #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
0051:   ,
0052:   PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
0053:   PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
0054:   PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
0055:   PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
0056: #endif
0057: #ifdef __USE_GNU
0058:   /* For compatibility.  */
0059:   , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP
0060: #endif
0061: };
0062: 
0063: 
0064: #ifdef __USE_XOPEN2K
0065: /* Robust mutex or not flags.  */
0066: enum
0067: {
0068:   PTHREAD_MUTEX_STALLED,
0069:   PTHREAD_MUTEX_STALLED_NP = PTHREAD_MUTEX_STALLED,
0070:   PTHREAD_MUTEX_ROBUST,
0071:   PTHREAD_MUTEX_ROBUST_NP = PTHREAD_MUTEX_ROBUST
0072: };
0073: #endif
0074: 
0075: 
0076: #ifdef __USE_UNIX98
0077: /* Mutex protocols.  */
0078: enum
0079: {
0080:   PTHREAD_PRIO_NONE,
0081:   PTHREAD_PRIO_INHERIT,
0082:   PTHREAD_PRIO_PROTECT
0083: };
0084: #endif
0085: 
0086: 
0087: /* Mutex initializers.  */
0088: #if __WORDSIZE == 64
0089: # define PTHREAD_MUTEX_INITIALIZER \
0090:   { { 0, 0, 0, 0, 0, 0, { 0, 0 } } }
0091: # ifdef __USE_GNU
0092: #  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
0093:   { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0, 0 } } }
0094: #  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
0095:   { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0, 0 } } }
0096: #  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
0097:   { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0, 0 } } }
0098: # endif
0099: #else
0100: # define PTHREAD_MUTEX_INITIALIZER \
0101:   { { 0, 0, 0, 0, 0, { 0 } } }
0102: # ifdef __USE_GNU
0103: #  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
0104:   { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0 } } }
0105: #  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
0106:   { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0 } } }
0107: #  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
0108:   { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0 } } }
0109: # endif
0110: #endif
0111: 
0112: 
0113: /* Read-write lock types.  */
0114: #if defined __USE_UNIX98 || defined __USE_XOPEN2K
0115: enum
0116: {
0117:   PTHREAD_RWLOCK_PREFER_READER_NP,
0118:   PTHREAD_RWLOCK_PREFER_WRITER_NP,
0119:   PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
0120:   PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP
0121: };
0122: 
0123: /* Read-write lock initializers.  */
0124: # define PTHREAD_RWLOCK_INITIALIZER \
0125:   { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
0126: # ifdef __USE_GNU
0127: #  if __WORDSIZE == 64
0128: #   define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
0129:   { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                                           \
0130:         PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
0131: #  else
0132: #   if __BYTE_ORDER == __LITTLE_ENDIAN
0133: #    define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
0134:   { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, \
0135:       0, 0, 0, 0 } }
0136: #   else
0137: #    define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
0138:   { { 0, 0, 0, 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,\
0139:       0 } }
0140: #   endif
0141: #  endif
0142: # endif
0143: #endif  /* Unix98 or XOpen2K */
0144: 
0145: 
0146: /* Scheduler inheritance.  */
0147: enum
0148: {
0149:   PTHREAD_INHERIT_SCHED,
0150: #define PTHREAD_INHERIT_SCHED   PTHREAD_INHERIT_SCHED
0151:   PTHREAD_EXPLICIT_SCHED
0152: #define PTHREAD_EXPLICIT_SCHED  PTHREAD_EXPLICIT_SCHED
0153: };
0154: 
0155: 
0156: /* Scope handling.  */
0157: enum
0158: {
0159:   PTHREAD_SCOPE_SYSTEM,
0160: #define PTHREAD_SCOPE_SYSTEM    PTHREAD_SCOPE_SYSTEM
0161:   PTHREAD_SCOPE_PROCESS
0162: #define PTHREAD_SCOPE_PROCESS   PTHREAD_SCOPE_PROCESS
0163: };
0164: 
0165: 
0166: /* Process shared or private flag.  */
0167: enum
0168: {
0169:   PTHREAD_PROCESS_PRIVATE,
0170: #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
0171:   PTHREAD_PROCESS_SHARED
0172: #define PTHREAD_PROCESS_SHARED  PTHREAD_PROCESS_SHARED
0173: };
0174: 
0175: 
0176: 
0177: /* Conditional variable handling.  */
0178: #define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
0179: 
0180: 
0181: /* Cleanup buffers */
0182: struct _pthread_cleanup_buffer
0183: {
0184:   void (*__routine) (void *);             /* Function to call.  */
0185:   void *__arg;                            /* Its argument.  */
0186:   int __canceltype;                       /* Saved cancellation type. */
0187:   struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions.  */
0188: };
0189: 
0190: /* Cancellation */
0191: enum
0192: {
0193:   PTHREAD_CANCEL_ENABLE,
0194: #define PTHREAD_CANCEL_ENABLE   PTHREAD_CANCEL_ENABLE
0195:   PTHREAD_CANCEL_DISABLE
0196: #define PTHREAD_CANCEL_DISABLE  PTHREAD_CANCEL_DISABLE
0197: };
0198: enum
0199: {
0200:   PTHREAD_CANCEL_DEFERRED,
0201: #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
0202:   PTHREAD_CANCEL_ASYNCHRONOUS
0203: #define PTHREAD_CANCEL_ASYNCHRONOUS     PTHREAD_CANCEL_ASYNCHRONOUS
0204: };
0205: #define PTHREAD_CANCELED ((void *) -1)
0206: 
0207: 
0208: /* Single execution handling.  */
0209: #define PTHREAD_ONCE_INIT 0
0210: 
0211: 
0212: #ifdef __USE_XOPEN2K
0213: /* Value returned by 'pthread_barrier_wait' for one of the threads after
0214:    the required number of threads have called this function.
0215:    -1 is distinct from 0 and all errno constants */
0216: # define PTHREAD_BARRIER_SERIAL_THREAD -1
0217: #endif
0218: 
0219: 
0220: __BEGIN_DECLS
0221: 
0222: /* Create a new thread, starting with execution of START-ROUTINE
0223:    getting passed ARG.  Creation attributed come from ATTR.  The new
0224:    handle is stored in *NEWTHREAD.  */
0225: extern int pthread_create (pthread_t *__restrict __newthread,
0226:                            __const pthread_attr_t *__restrict __attr,
0227:                            void *(*__start_routine) (void *),
0228:                            void *__restrict __arg) __THROWNL __nonnull ((1, 3));
0229: 
0230: /* Terminate calling thread.
0231: 
0232:    The registered cleanup handlers are called via exception handling
0233:    so we cannot mark this function with __THROW.*/
0234: extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
0235: 
0236: /* Make calling thread wait for termination of the thread TH.  The
0237:    exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
0238:    is not NULL.
0239: 
0240:    This function is a cancellation point and therefore not marked with
0241:    __THROW.  */
0242: extern int pthread_join (pthread_t __th, void **__thread_return);
0243: 
0244: #ifdef __USE_GNU
0245: /* Check whether thread TH has terminated.  If yes return the status of
0246:    the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL.  */
0247: extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
0248: 
0249: /* Make calling thread wait for termination of the thread TH, but only
0250:    until TIMEOUT.  The exit status of the thread is stored in
0251:    *THREAD_RETURN, if THREAD_RETURN is not NULL.
0252: 
0253:    This function is a cancellation point and therefore not marked with
0254:    __THROW.  */
0255: extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
0256:                                  __const struct timespec *__abstime);
0257: #endif
0258: 
0259: /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
0260:    The resources of TH will therefore be freed immediately when it
0261:    terminates, instead of waiting for another thread to perform PTHREAD_JOIN
0262:    on it.  */
0263: extern int pthread_detach (pthread_t __th) __THROW;
0264: 
0265: 
0266: /* Obtain the identifier of the current thread.  */
0267: extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__));
0268: 
0269: /* Compare two thread identifiers.  */
0270: extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __THROW;
0271: 
0272: 
0273: /* Thread attribute handling.  */
0274: 
0275: /* Initialize thread attribute *ATTR with default attributes
0276:    (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
0277:     no user-provided stack).  */
0278: extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1));
0279: 
0280: /* Destroy thread attribute *ATTR.  */
0281: extern int pthread_attr_destroy (pthread_attr_t *__attr)
0282:      __THROW __nonnull ((1));
0283: 
0284: /* Get detach state attribute.  */
0285: extern int pthread_attr_getdetachstate (__const pthread_attr_t *__attr,
0286:                                         int *__detachstate)
0287:      __THROW __nonnull ((1, 2));
0288: 
0289: /* Set detach state attribute.  */
0290: extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
0291:                                         int __detachstate)
0292:      __THROW __nonnull ((1));
0293: 
0294: 
0295: /* Get the size of the guard area created for stack overflow protection.  */
0296: extern int pthread_attr_getguardsize (__const pthread_attr_t *__attr,
0297:                                       size_t *__guardsize)
0298:      __THROW __nonnull ((1, 2));
0299: 
0300: /* Set the size of the guard area created for stack overflow protection.  */
0301: extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
0302:                                       size_t __guardsize)
0303:      __THROW __nonnull ((1));
0304: 
0305: 
0306: /* Return in *PARAM the scheduling parameters of *ATTR.  */
0307: extern int pthread_attr_getschedparam (__const pthread_attr_t *__restrict
0308:                                        __attr,
0309:                                        struct sched_param *__restrict __param)
0310:      __THROW __nonnull ((1, 2));
0311: 
0312: /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM.  */
0313: extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
0314:                                        __const struct sched_param *__restrict
0315:                                        __param) __THROW __nonnull ((1, 2));
0316: 
0317: /* Return in *POLICY the scheduling policy of *ATTR.  */
0318: extern int pthread_attr_getschedpolicy (__const pthread_attr_t *__restrict
0319:                                         __attr, int *__restrict __policy)
0320:      __THROW __nonnull ((1, 2));
0321: 
0322: /* Set scheduling policy in *ATTR according to POLICY.  */
0323: extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
0324:      __THROW __nonnull ((1));
0325: 
0326: /* Return in *INHERIT the scheduling inheritance mode of *ATTR.  */
0327: extern int pthread_attr_getinheritsched (__const pthread_attr_t *__restrict
0328:                                          __attr, int *__restrict __inherit)
0329:      __THROW __nonnull ((1, 2));
0330: 
0331: /* Set scheduling inheritance mode in *ATTR according to INHERIT.  */
0332: extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
0333:                                          int __inherit)
0334:      __THROW __nonnull ((1));
0335: 
0336: 
0337: /* Return in *SCOPE the scheduling contention scope of *ATTR.  */
0338: extern int pthread_attr_getscope (__const pthread_attr_t *__restrict __attr,
0339:                                   int *__restrict __scope)
0340:      __THROW __nonnull ((1, 2));
0341: 
0342: /* Set scheduling contention scope in *ATTR according to SCOPE.  */
0343: extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
0344:      __THROW __nonnull ((1));
0345: 
0346: /* Return the previously set address for the stack.  */
0347: extern int pthread_attr_getstackaddr (__const pthread_attr_t *__restrict
0348:                                       __attr, void **__restrict __stackaddr)
0349:      __THROW __nonnull ((1, 2)) __attribute_deprecated__;
0350: 
0351: /* Set the starting address of the stack of the thread to be created.
0352:    Depending on whether the stack grows up or down the value must either
0353:    be higher or lower than all the address in the memory block.  The
0354:    minimal size of the block must be PTHREAD_STACK_MIN.  */
0355: extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
0356:                                       void *__stackaddr)
0357:      __THROW __nonnull ((1)) __attribute_deprecated__;
0358: 
0359: /* Return the currently used minimal stack size.  */
0360: extern int pthread_attr_getstacksize (__const pthread_attr_t *__restrict
0361:                                       __attr, size_t *__restrict __stacksize)
0362:      __THROW __nonnull ((1, 2));
0363: 
0364: /* Add information about the minimum stack size needed for the thread
0365:    to be started.  This size must never be less than PTHREAD_STACK_MIN
0366:    and must also not exceed the system limits.  */
0367: extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
0368:                                       size_t __stacksize)
0369:      __THROW __nonnull ((1));
0370: 
0371: #ifdef __USE_XOPEN2K
0372: /* Return the previously set address for the stack.  */
0373: extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
0374:                                   void **__restrict __stackaddr,
0375:                                   size_t *__restrict __stacksize)
0376:      __THROW __nonnull ((1, 2, 3));
0377: 
0378: /* The following two interfaces are intended to replace the last two.  They
0379:    require setting the address as well as the size since only setting the
0380:    address will make the implementation on some architectures impossible.  */
0381: extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
0382:                                   size_t __stacksize) __THROW __nonnull ((1));
0383: #endif
0384: 
0385: #ifdef __USE_GNU
0386: /* Thread created with attribute ATTR will be limited to run only on
0387:    the processors represented in CPUSET.  */
0388: extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr,
0389:                                         size_t __cpusetsize,
0390:                                         __const cpu_set_t *__cpuset)
0391:      __THROW __nonnull ((1, 3));
0392: 
0393: /* Get bit set in CPUSET representing the processors threads created with
0394:    ATTR can run on.  */
0395: extern int pthread_attr_getaffinity_np (__const pthread_attr_t *__attr,
0396:                                         size_t __cpusetsize,
0397:                                         cpu_set_t *__cpuset)
0398:      __THROW __nonnull ((1, 3));
0399: 
0400: 
0401: /* Initialize thread attribute *ATTR with attributes corresponding to the
0402:    already running thread TH.  It shall be called on uninitialized ATTR
0403:    and destroyed with pthread_attr_destroy when no longer needed.  */
0404: extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
0405:      __THROW __nonnull ((2));
0406: #endif
0407: 
0408: 
0409: /* Functions for scheduling control.  */
0410: 
0411: /* Set the scheduling parameters for TARGET_THREAD according to POLICY
0412:    and *PARAM.  */
0413: extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
0414:                                   __const struct sched_param *__param)
0415:      __THROW __nonnull ((3));
0416: 
0417: /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
0418: extern int pthread_getschedparam (pthread_t __target_thread,
0419:                                   int *__restrict __policy,
0420:                                   struct sched_param *__restrict __param)
0421:      __THROW __nonnull ((2, 3));
0422: 
0423: /* Set the scheduling priority for TARGET_THREAD.  */
0424: extern int pthread_setschedprio (pthread_t __target_thread, int __prio)
0425:      __THROW;
0426: 
0427: 
0428: #ifdef __USE_GNU
0429: /* Get thread name visible in the kernel and its interfaces.  */
0430: extern int pthread_getname_np (pthread_t __target_thread, char *__buf,
0431:                                size_t __buflen)
0432:      __THROW __nonnull ((2));
0433: 
0434: /* Set thread name visible in the kernel and its interfaces.  */
0435: extern int pthread_setname_np (pthread_t __target_thread, __const char *__name)
0436:      __THROW __nonnull ((2));
0437: #endif
0438: 
0439: 
0440: #ifdef __USE_UNIX98
0441: /* Determine level of concurrency.  */
0442: extern int pthread_getconcurrency (void) __THROW;
0443: 
0444: /* Set new concurrency level to LEVEL.  */
0445: extern int pthread_setconcurrency (int __level) __THROW;
0446: #endif
0447: 
0448: #ifdef __USE_GNU
0449: /* Yield the processor to another thread or process.
0450:    This function is similar to the POSIX `sched_yield' function but
0451:    might be differently implemented in the case of a m-on-n thread
0452:    implementation.  */
0453: extern int pthread_yield (void) __THROW;
0454: 
0455: 
0456: /* Limit specified thread TH to run only on the processors represented
0457:    in CPUSET.  */
0458: extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
0459:                                    __const cpu_set_t *__cpuset)
0460:      __THROW __nonnull ((3));
0461: 
0462: /* Get bit set in CPUSET representing the processors TH can run on.  */
0463: extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
0464:                                    cpu_set_t *__cpuset)
0465:      __THROW __nonnull ((3));
0466: #endif
0467: 
0468: 
0469: /* Functions for handling initialization.  */
0470: 
0471: /* Guarantee that the initialization function INIT_ROUTINE will be called
0472:    only once, even if pthread_once is executed several times with the
0473:    same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
0474:    extern variable initialized to PTHREAD_ONCE_INIT.
0475: 
0476:    The initialization functions might throw exception which is why
0477:    this function is not marked with __THROW.  */
0478: extern int pthread_once (pthread_once_t *__once_control,
0479:                          void (*__init_routine) (void)) __nonnull ((1, 2));
0480: 
0481: 
0482: /* Functions for handling cancellation.
0483: 
0484:    Note that these functions are explicitly not marked to not throw an
0485:    exception in C++ code.  If cancellation is implemented by unwinding
0486:    this is necessary to have the compiler generate the unwind information.  */
0487: 
0488: /* Set cancelability state of current thread to STATE, returning old
0489:    state in *OLDSTATE if OLDSTATE is not NULL.  */
0490: extern int pthread_setcancelstate (int __state, int *__oldstate);
0491: 
0492: /* Set cancellation state of current thread to TYPE, returning the old
0493:    type in *OLDTYPE if OLDTYPE is not NULL.  */
0494: extern int pthread_setcanceltype (int __type, int *__oldtype);
0495: 
0496: /* Cancel THREAD immediately or at the next possibility.  */
0497: extern int pthread_cancel (pthread_t __th);
0498: 
0499: /* Test for pending cancellation for the current thread and terminate
0500:    the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
0501:    cancelled.  */
0502: extern void pthread_testcancel (void);
0503: 
0504: 
0505: /* Cancellation handling with integration into exception handling.  */
0506: 
0507: typedef struct
0508: {
0509:   struct
0510:   {
0511:     __jmp_buf __cancel_jmp_buf;
0512:     int __mask_was_saved;
0513:   } __cancel_jmp_buf[1];
0514:   void *__pad[4];
0515: } __pthread_unwind_buf_t __attribute__ ((__aligned__));
0516: 
0517: /* No special attributes by default.  */
0518: #ifndef __cleanup_fct_attribute
0519: # define __cleanup_fct_attribute
0520: #endif
0521: 
0522: 
0523: /* Structure to hold the cleanup handler information.  */
0524: struct __pthread_cleanup_frame
0525: {
0526:   void (*__cancel_routine) (void *);
0527:   void *__cancel_arg;
0528:   int __do_it;
0529:   int __cancel_type;
0530: };
0531: 
0532: #if defined __GNUC__ && defined __EXCEPTIONS
0533: # ifdef __cplusplus
0534: /* Class to handle cancellation handler invocation.  */
0535: class __pthread_cleanup_class
0536: {
0537:   void (*__cancel_routine) (void *);
0538:   void *__cancel_arg;
0539:   int __do_it;
0540:   int __cancel_type;
0541: 
0542:  public:
0543:   __pthread_cleanup_class (void (*__fct) (void *), void *__arg)
0544:     : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { }
0545:   ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); }
0546:   void __setdoit (int __newval) { __do_it = __newval; }
0547:   void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,
0548:                                            &__cancel_type); }
0549:   void __restore () const { pthread_setcanceltype (__cancel_type, 0); }
0550: };
0551: 
0552: /* Install a cleanup handler: ROUTINE will be called with arguments ARG
0553:    when the thread is canceled or calls pthread_exit.  ROUTINE will also
0554:    be called with arguments ARG when the matching pthread_cleanup_pop
0555:    is executed with non-zero EXECUTE argument.
0556: 
0557:    pthread_cleanup_push and pthread_cleanup_pop are macros and must always
0558:    be used in matching pairs at the same nesting level of braces.  */
0559: #  define pthread_cleanup_push(routine, arg) \
0560:   do {                                                                        \
0561:     __pthread_cleanup_class __clframe (routine, arg)
0562: 
0563: /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
0564:    If EXECUTE is non-zero, the handler function is called. */
0565: #  define pthread_cleanup_pop(execute) \
0566:     __clframe.__setdoit (execute);                                            \
0567:   } while (0)
0568: 
0569: #  ifdef __USE_GNU
0570: /* Install a cleanup handler as pthread_cleanup_push does, but also
0571:    saves the current cancellation type and sets it to deferred
0572:    cancellation.  */
0573: #   define pthread_cleanup_push_defer_np(routine, arg) \
0574:   do {                                                                        \
0575:     __pthread_cleanup_class __clframe (routine, arg);                         \
0576:     __clframe.__defer ()
0577: 
0578: /* Remove a cleanup handler as pthread_cleanup_pop does, but also
0579:    restores the cancellation type that was in effect when the matching
0580:    pthread_cleanup_push_defer was called.  */
0581: #   define pthread_cleanup_pop_restore_np(execute) \
0582:     __clframe.__restore ();                                                   \
0583:     __clframe.__setdoit (execute);                                            \
0584:   } while (0)
0585: #  endif
0586: # else
0587: /* Function called to call the cleanup handler.  As an extern inline
0588:    function the compiler is free to decide inlining the change when
0589:    needed or fall back on the copy which must exist somewhere
0590:    else.  */
0591: __extern_inline void
0592: __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
0593: {
0594:   if (__frame->__do_it)
0595:     __frame->__cancel_routine (__frame->__cancel_arg);
0596: }
0597: 
0598: /* Install a cleanup handler: ROUTINE will be called with arguments ARG
0599:    when the thread is canceled or calls pthread_exit.  ROUTINE will also
0600:    be called with arguments ARG when the matching pthread_cleanup_pop
0601:    is executed with non-zero EXECUTE argument.
0602: 
0603:    pthread_cleanup_push and pthread_cleanup_pop are macros and must always
0604:    be used in matching pairs at the same nesting level of braces.  */
0605: #  define pthread_cleanup_push(routine, arg) \
0606:   do {                                                                        \
0607:     struct __pthread_cleanup_frame __clframe                                  \
0608:       __attribute__ ((__cleanup__ (__pthread_cleanup_routine)))               \
0609:       = { .__cancel_routine = (routine), .__cancel_arg = (arg),               \
0610:           .__do_it = 1 };
0611: 
0612: /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
0613:    If EXECUTE is non-zero, the handler function is called. */
0614: #  define pthread_cleanup_pop(execute) \
0615:     __clframe.__do_it = (execute);                                            \
0616:   } while (0)
0617: 
0618: #  ifdef __USE_GNU
0619: /* Install a cleanup handler as pthread_cleanup_push does, but also
0620:    saves the current cancellation type and sets it to deferred
0621:    cancellation.  */
0622: #   define pthread_cleanup_push_defer_np(routine, arg) \
0623:   do {                                                                        \
0624:     struct __pthread_cleanup_frame __clframe                                  \
0625:       __attribute__ ((__cleanup__ (__pthread_cleanup_routine)))               \
0626:       = { .__cancel_routine = (routine), .__cancel_arg = (arg),               \
0627:           .__do_it = 1 };                                                     \
0628:     (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,                    \
0629:                                   &__clframe.__cancel_type)
0630: 
0631: /* Remove a cleanup handler as pthread_cleanup_pop does, but also
0632:    restores the cancellation type that was in effect when the matching
0633:    pthread_cleanup_push_defer was called.  */
0634: #   define pthread_cleanup_pop_restore_np(execute) \
0635:     (void) pthread_setcanceltype (__clframe.__cancel_type, NULL);             \
0636:     __clframe.__do_it = (execute);                                            \
0637:   } while (0)
0638: #  endif
0639: # endif
0640: #else
0641: /* Install a cleanup handler: ROUTINE will be called with arguments ARG
0642:    when the thread is canceled or calls pthread_exit.  ROUTINE will also
0643:    be called with arguments ARG when the matching pthread_cleanup_pop
0644:    is executed with non-zero EXECUTE argument.
0645: 
0646:    pthread_cleanup_push and pthread_cleanup_pop are macros and must always
0647:    be used in matching pairs at the same nesting level of braces.  */
0648: # define pthread_cleanup_push(routine, arg) \
0649:   do {                                                                        \
0650:     __pthread_unwind_buf_t __cancel_buf;                                      \
0651:     void (*__cancel_routine) (void *) = (routine);                            \
0652:     void *__cancel_arg = (arg);                                               \
0653:     int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *)     \
0654:                                         __cancel_buf.__cancel_jmp_buf, 0);    \
0655:     if (__builtin_expect (__not_first_call, 0))                               \
0656:       {                                                                       \
0657:         __cancel_routine (__cancel_arg);                                      \
0658:         __pthread_unwind_next (&__cancel_buf);                                \
0659:         /* NOTREACHED */                                                      \
0660:       }                                                                       \
0661:                                                                               \
0662:     __pthread_register_cancel (&__cancel_buf);                                \
0663:     do {
0664: extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
0665:      __cleanup_fct_attribute;
0666: 
0667: /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
0668:    If EXECUTE is non-zero, the handler function is called. */
0669: # define pthread_cleanup_pop(execute) \
0670:       do { } while (0);/* Empty to allow label before pthread_cleanup_pop.  */\
0671:     } while (0);                                                              \
0672:     __pthread_unregister_cancel (&__cancel_buf);                              \
0673:     if (execute)                                                              \
0674:       __cancel_routine (__cancel_arg);                                        \
0675:   } while (0)
0676: extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
0677:   __cleanup_fct_attribute;
0678: 
0679: # ifdef __USE_GNU
0680: /* Install a cleanup handler as pthread_cleanup_push does, but also
0681:    saves the current cancellation type and sets it to deferred
0682:    cancellation.  */
0683: #  define pthread_cleanup_push_defer_np(routine, arg) \
0684:   do {                                                                        \
0685:     __pthread_unwind_buf_t __cancel_buf;                                      \
0686:     void (*__cancel_routine) (void *) = (routine);                            \
0687:     void *__cancel_arg = (arg);                                               \
0688:     int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *)     \
0689:                                         __cancel_buf.__cancel_jmp_buf, 0);    \
0690:     if (__builtin_expect (__not_first_call, 0))                               \
0691:       {                                                                       \
0692:         __cancel_routine (__cancel_arg);                                      \
0693:         __pthread_unwind_next (&__cancel_buf);                                \
0694:         /* NOTREACHED */                                                      \
0695:       }                                                                       \
0696:                                                                               \
0697:     __pthread_register_cancel_defer (&__cancel_buf);                          \
0698:     do {
0699: extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf)
0700:      __cleanup_fct_attribute;
0701: 
0702: /* Remove a cleanup handler as pthread_cleanup_pop does, but also
0703:    restores the cancellation type that was in effect when the matching
0704:    pthread_cleanup_push_defer was called.  */
0705: #  define pthread_cleanup_pop_restore_np(execute) \
0706:       do { } while (0);/* Empty to allow label before pthread_cleanup_pop.  */\
0707:     } while (0);                                                              \
0708:     __pthread_unregister_cancel_restore (&__cancel_buf);                      \
0709:     if (execute)                                                              \
0710:       __cancel_routine (__cancel_arg);                                        \
0711:   } while (0)
0712: extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf)
0713:   __cleanup_fct_attribute;
0714: # endif
0715: 
0716: /* Internal interface to initiate cleanup.  */
0717: extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
0718:      __cleanup_fct_attribute __attribute__ ((__noreturn__))
0719: # ifndef SHARED
0720:      __attribute__ ((__weak__))
0721: # endif
0722:      ;
0723: #endif
0724: 
0725: /* Function used in the macros.  */
0726: struct __jmp_buf_tag;
0727: extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROW;
0728: 
0729: 
0730: /* Mutex handling.  */
0731: 
0732: /* Initialize a mutex.  */
0733: extern int pthread_mutex_init (pthread_mutex_t *__mutex,
0734:                                __const pthread_mutexattr_t *__mutexattr)
0735:      __THROW __nonnull ((1));
0736: 
0737: /* Destroy a mutex.  */
0738: extern int pthread_mutex_destroy (pthread_mutex_t *__mutex)
0739:      __THROW __nonnull ((1));
0740: 
0741: /* Try locking a mutex.  */
0742: extern int pthread_mutex_trylock (pthread_mutex_t *__mutex)
0743:      __THROWNL __nonnull ((1));
0744: 
0745: /* Lock a mutex.  */
0746: extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
0747:      __THROWNL __nonnull ((1));
0748: 
0749: #ifdef __USE_XOPEN2K
0750: /* Wait until lock becomes available, or specified time passes. */
0751: extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
0752:                                     __const struct timespec *__restrict
0753:                                     __abstime) __THROWNL __nonnull ((1, 2));
0754: #endif
0755: 
0756: /* Unlock a mutex.  */
0757: extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
0758:      __THROWNL __nonnull ((1));
0759: 
0760: 
0761: /* Get the priority ceiling of MUTEX.  */
0762: extern int pthread_mutex_getprioceiling (__const pthread_mutex_t *
0763:                                          __restrict __mutex,
0764:                                          int *__restrict __prioceiling)
0765:      __THROW __nonnull ((1, 2));
0766: 
0767: /* Set the priority ceiling of MUTEX to PRIOCEILING, return old
0768:    priority ceiling value in *OLD_CEILING.  */
0769: extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex,
0770:                                          int __prioceiling,
0771:                                          int *__restrict __old_ceiling)
0772:      __THROW __nonnull ((1, 3));
0773: 
0774: 
0775: #ifdef __USE_XOPEN2K8
0776: /* Declare the state protected by MUTEX as consistent.  */
0777: extern int pthread_mutex_consistent (pthread_mutex_t *__mutex)
0778:      __THROW __nonnull ((1));
0779: # ifdef __USE_GNU
0780: extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex)
0781:      __THROW __nonnull ((1));
0782: # endif
0783: #endif
0784: 
0785: 
0786: /* Functions for handling mutex attributes.  */
0787: 
0788: /* Initialize mutex attribute object ATTR with default attributes
0789:    (kind is PTHREAD_MUTEX_TIMED_NP).  */
0790: extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr)
0791:      __THROW __nonnull ((1));
0792: 
0793: /* Destroy mutex attribute object ATTR.  */
0794: extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr)
0795:      __THROW __nonnull ((1));
0796: 
0797: /* Get the process-shared flag of the mutex attribute ATTR.  */
0798: extern int pthread_mutexattr_getpshared (__const pthread_mutexattr_t *
0799:                                          __restrict __attr,
0800:                                          int *__restrict __pshared)
0801:      __THROW __nonnull ((1, 2));
0802: 
0803: /* Set the process-shared flag of the mutex attribute ATTR.  */
0804: extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
0805:                                          int __pshared)
0806:      __THROW __nonnull ((1));
0807: 
0808: #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
0809: /* Return in *KIND the mutex kind attribute in *ATTR.  */
0810: extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
0811:                                       __attr, int *__restrict __kind)
0812:      __THROW __nonnull ((1, 2));
0813: 
0814: /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
0815:    PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
0816:    PTHREAD_MUTEX_DEFAULT).  */
0817: extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
0818:      __THROW __nonnull ((1));
0819: #endif
0820: 
0821: /* Return in *PROTOCOL the mutex protocol attribute in *ATTR.  */
0822: extern int pthread_mutexattr_getprotocol (__const pthread_mutexattr_t *
0823:                                           __restrict __attr,
0824:                                           int *__restrict __protocol)
0825:      __THROW __nonnull ((1, 2));
0826: 
0827: /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
0828:    PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT).  */
0829: extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr,
0830:                                           int __protocol)
0831:      __THROW __nonnull ((1));
0832: 
0833: /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR.  */
0834: extern int pthread_mutexattr_getprioceiling (__const pthread_mutexattr_t *
0835:                                              __restrict __attr,
0836:                                              int *__restrict __prioceiling)
0837:      __THROW __nonnull ((1, 2));
0838: 
0839: /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING.  */
0840: extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr,
0841:                                              int __prioceiling)
0842:      __THROW __nonnull ((1));
0843: 
0844: #ifdef __USE_XOPEN2K
0845: /* Get the robustness flag of the mutex attribute ATTR.  */
0846: extern int pthread_mutexattr_getrobust (__const pthread_mutexattr_t *__attr,
0847:                                         int *__robustness)
0848:      __THROW __nonnull ((1, 2));
0849: # ifdef __USE_GNU
0850: extern int pthread_mutexattr_getrobust_np (__const pthread_mutexattr_t *__attr,
0851:                                            int *__robustness)
0852:      __THROW __nonnull ((1, 2));
0853: # endif
0854: 
0855: /* Set the robustness flag of the mutex attribute ATTR.  */
0856: extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr,
0857:                                         int __robustness)
0858:      __THROW __nonnull ((1));
0859: # ifdef __USE_GNU
0860: extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr,
0861:                                            int __robustness)
0862:      __THROW __nonnull ((1));
0863: # endif
0864: #endif
0865: 
0866: 
0867: #if defined __USE_UNIX98 || defined __USE_XOPEN2K
0868: /* Functions for handling read-write locks.  */
0869: 
0870: /* Initialize read-write lock RWLOCK using attributes ATTR, or use
0871:    the default values if later is NULL.  */
0872: extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
0873:                                 __const pthread_rwlockattr_t *__restrict
0874:                                 __attr) __THROW __nonnull ((1));
0875: 
0876: /* Destroy read-write lock RWLOCK.  */
0877: extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock)
0878:      __THROW __nonnull ((1));
0879: 
0880: /* Acquire read lock for RWLOCK.  */
0881: extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock)
0882:      __THROWNL __nonnull ((1));
0883: 
0884: /* Try to acquire read lock for RWLOCK.  */
0885: extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
0886:   __THROWNL __nonnull ((1));
0887: 
0888: # ifdef __USE_XOPEN2K
0889: /* Try to acquire read lock for RWLOCK or return after specfied time.  */
0890: extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
0891:                                        __const struct timespec *__restrict
0892:                                        __abstime) __THROWNL __nonnull ((1, 2));
0893: # endif
0894: 
0895: /* Acquire write lock for RWLOCK.  */
0896: extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
0897:      __THROWNL __nonnull ((1));
0898: 
0899: /* Try to acquire write lock for RWLOCK.  */
0900: extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
0901:      __THROWNL __nonnull ((1));
0902: 
0903: # ifdef __USE_XOPEN2K
0904: /* Try to acquire write lock for RWLOCK or return after specfied time.  */
0905: extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
0906:                                        __const struct timespec *__restrict
0907:                                        __abstime) __THROWNL __nonnull ((1, 2));
0908: # endif
0909: 
0910: /* Unlock RWLOCK.  */
0911: extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
0912:      __THROWNL __nonnull ((1));
0913: 
0914: 
0915: /* Functions for handling read-write lock attributes.  */
0916: 
0917: /* Initialize attribute object ATTR with default values.  */
0918: extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr)
0919:      __THROW __nonnull ((1));
0920: 
0921: /* Destroy attribute object ATTR.  */
0922: extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr)
0923:      __THROW __nonnull ((1));
0924: 
0925: /* Return current setting of process-shared attribute of ATTR in PSHARED.  */
0926: extern int pthread_rwlockattr_getpshared (__const pthread_rwlockattr_t *
0927:                                           __restrict __attr,
0928:                                           int *__restrict __pshared)
0929:      __THROW __nonnull ((1, 2));
0930: 
0931: /* Set process-shared attribute of ATTR to PSHARED.  */
0932: extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
0933:                                           int __pshared)
0934:      __THROW __nonnull ((1));
0935: 
0936: /* Return current setting of reader/writer preference.  */
0937: extern int pthread_rwlockattr_getkind_np (__const pthread_rwlockattr_t *
0938:                                           __restrict __attr,
0939:                                           int *__restrict __pref)
0940:      __THROW __nonnull ((1, 2));
0941: 
0942: /* Set reader/write preference.  */
0943: extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
0944:                                           int __pref) __THROW __nonnull ((1));
0945: #endif
0946: 
0947: 
0948: /* Functions for handling conditional variables.  */
0949: 
0950: /* Initialize condition variable COND using attributes ATTR, or use
0951:    the default values if later is NULL.  */
0952: extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
0953:                               __const pthread_condattr_t *__restrict
0954:                               __cond_attr) __THROW __nonnull ((1));
0955: 
0956: /* Destroy condition variable COND.  */
0957: extern int pthread_cond_destroy (pthread_cond_t *__cond)
0958:      __THROW __nonnull ((1));
0959: 
0960: /* Wake up one thread waiting for condition variable COND.  */
0961: extern int pthread_cond_signal (pthread_cond_t *__cond)
0962:      __THROWNL __nonnull ((1));
0963: 
0964: /* Wake up all threads waiting for condition variables COND.  */
0965: extern int pthread_cond_broadcast (pthread_cond_t *__cond)
0966:      __THROWNL __nonnull ((1));
0967: 
0968: /* Wait for condition variable COND to be signaled or broadcast.
0969:    MUTEX is assumed to be locked before.
0970: 
0971:    This function is a cancellation point and therefore not marked with
0972:    __THROW.  */
0973: extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
0974:                               pthread_mutex_t *__restrict __mutex)
0975:      __nonnull ((1, 2));
0976: 
0977: /* Wait for condition variable COND to be signaled or broadcast until
0978:    ABSTIME.  MUTEX is assumed to be locked before.  ABSTIME is an
0979:    absolute time specification; zero is the beginning of the epoch
0980:    (00:00:00 GMT, January 1, 1970).
0981: 
0982:    This function is a cancellation point and therefore not marked with
0983:    __THROW.  */
0984: extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
0985:                                    pthread_mutex_t *__restrict __mutex,
0986:                                    __const struct timespec *__restrict
0987:                                    __abstime) __nonnull ((1, 2, 3));
0988: 
0989: /* Functions for handling condition variable attributes.  */
0990: 
0991: /* Initialize condition variable attribute ATTR.  */
0992: extern int pthread_condattr_init (pthread_condattr_t *__attr)
0993:      __THROW __nonnull ((1));
0994: 
0995: /* Destroy condition variable attribute ATTR.  */
0996: extern int pthread_condattr_destroy (pthread_condattr_t *__attr)
0997:      __THROW __nonnull ((1));
0998: 
0999: /* Get the process-shared flag of the condition variable attribute ATTR.  */
1000: extern int pthread_condattr_getpshared (__const pthread_condattr_t *
1001:                                         __restrict __attr,
1002:                                         int *__restrict __pshared)
1003:      __THROW __nonnull ((1, 2));
1004: 
1005: /* Set the process-shared flag of the condition variable attribute ATTR.  */
1006: extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
1007:                                         int __pshared) __THROW __nonnull ((1));
1008: 
1009: #ifdef __USE_XOPEN2K
1010: /* Get the clock selected for the conditon variable attribute ATTR.  */
1011: extern int pthread_condattr_getclock (__const pthread_condattr_t *
1012:                                       __restrict __attr,
1013:                                       __clockid_t *__restrict __clock_id)
1014:      __THROW __nonnull ((1, 2));
1015: 
1016: /* Set the clock selected for the conditon variable attribute ATTR.  */
1017: extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
1018:                                       __clockid_t __clock_id)
1019:      __THROW __nonnull ((1));
1020: #endif
1021: 
1022: 
1023: #ifdef __USE_XOPEN2K
1024: /* Functions to handle spinlocks.  */
1025: 
1026: /* Initialize the spinlock LOCK.  If PSHARED is nonzero the spinlock can
1027:    be shared between different processes.  */
1028: extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
1029:      __THROW __nonnull ((1));
1030: 
1031: /* Destroy the spinlock LOCK.  */
1032: extern int pthread_spin_destroy (pthread_spinlock_t *__lock)
1033:      __THROW __nonnull ((1));
1034: 
1035: /* Wait until spinlock LOCK is retrieved.  */
1036: extern int pthread_spin_lock (pthread_spinlock_t *__lock)
1037:      __THROWNL __nonnull ((1));
1038: 
1039: /* Try to lock spinlock LOCK.  */
1040: extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
1041:      __THROWNL __nonnull ((1));
1042: 
1043: /* Release spinlock LOCK.  */
1044: extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
1045:      __THROWNL __nonnull ((1));
1046: 
1047: 
1048: /* Functions to handle barriers.  */
1049: 
1050: /* Initialize BARRIER with the attributes in ATTR.  The barrier is
1051:    opened when COUNT waiters arrived.  */
1052: extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
1053:                                  __const pthread_barrierattr_t *__restrict
1054:                                  __attr, unsigned int __count)
1055:      __THROW __nonnull ((1));
1056: 
1057: /* Destroy a previously dynamically initialized barrier BARRIER.  */
1058: extern int pthread_barrier_destroy (pthread_barrier_t *__barrier)
1059:      __THROW __nonnull ((1));
1060: 
1061: /* Wait on barrier BARRIER.  */
1062: extern int pthread_barrier_wait (pthread_barrier_t *__barrier)
1063:      __THROWNL __nonnull ((1));
1064: 
1065: 
1066: /* Initialize barrier attribute ATTR.  */
1067: extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr)
1068:      __THROW __nonnull ((1));
1069: 
1070: /* Destroy previously dynamically initialized barrier attribute ATTR.  */
1071: extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr)
1072:      __THROW __nonnull ((1));
1073: 
1074: /* Get the process-shared flag of the barrier attribute ATTR.  */
1075: extern int pthread_barrierattr_getpshared (__const pthread_barrierattr_t *
1076:                                            __restrict __attr,
1077:                                            int *__restrict __pshared)
1078:      __THROW __nonnull ((1, 2));
1079: 
1080: /* Set the process-shared flag of the barrier attribute ATTR.  */
1081: extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
1082:                                            int __pshared)
1083:      __THROW __nonnull ((1));
1084: #endif
1085: 
1086: 
1087: /* Functions for handling thread-specific data.  */
1088: 
1089: /* Create a key value identifying a location in the thread-specific
1090:    data area.  Each thread maintains a distinct thread-specific data
1091:    area.  DESTR_FUNCTION, if non-NULL, is called with the value
1092:    associated to that key when the key is destroyed.
1093:    DESTR_FUNCTION is not called if the value associated is NULL when
1094:    the key is destroyed.  */
1095: extern int pthread_key_create (pthread_key_t *__key,
1096:                                void (*__destr_function) (void *))
1097:      __THROW __nonnull ((1));
1098: 
1099: /* Destroy KEY.  */
1100: extern int pthread_key_delete (pthread_key_t __key) __THROW;
1101: 
1102: /* Return current value of the thread-specific data slot identified by KEY.  */
1103: extern void *pthread_getspecific (pthread_key_t __key) __THROW;
1104: 
1105: /* Store POINTER in the thread-specific data slot identified by KEY. */
1106: extern int pthread_setspecific (pthread_key_t __key,
1107:                                 __const void *__pointer) __THROW ;
1108: 
1109: 
1110: #ifdef __USE_XOPEN2K
1111: /* Get ID of CPU-time clock for thread THREAD_ID.  */
1112: extern int pthread_getcpuclockid (pthread_t __thread_id,
1113:                                   __clockid_t *__clock_id)
1114:      __THROW __nonnull ((2));
1115: #endif
1116: 
1117: 
1118: /* Install handlers to be called when a new process is created with FORK.
1119:    The PREPARE handler is called in the parent process just before performing
1120:    FORK. The PARENT handler is called in the parent process just after FORK.
1121:    The CHILD handler is called in the child process.  Each of the three
1122:    handlers can be NULL, meaning that no handler needs to be called at that
1123:    point.
1124:    PTHREAD_ATFORK can be called several times, in which case the PREPARE
1125:    handlers are called in LIFO order (last added with PTHREAD_ATFORK,
1126:    first called before FORK), and the PARENT and CHILD handlers are called
1127:    in FIFO (first added, first called).  */
1128: 
1129: extern int pthread_atfork (void (*__prepare) (void),
1130:                            void (*__parent) (void),
1131:                            void (*__child) (void)) __THROW;
1132: 
1133: 
1134: #ifdef __USE_EXTERN_INLINES
1135: /* Optimizations.  */
1136: __extern_inline int
1137: __NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2))
1138: {
1139:   return __thread1 == __thread2;
1140: }
1141: #endif
1142: 
1143: __END_DECLS
1144: 
1145: #endif  /* pthread.h */
1146: 


for client 44.202.90.91
© Andrew Scott 2006 - 2024,
All Rights Reserved
http://www.andrew-scott.uk/
Andrew Scott
http://www.andrew-scott.co.uk/