Back to index

glibc  2.9
pthreadtypes.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 #if !defined _BITS_TYPES_H && !defined _PTHREAD_H
00016 # error "Never include <bits/pthreadtypes.h> directly; use <sys/types.h> instead."
00017 #endif
00018 
00019 #ifndef _BITS_PTHREADTYPES_H
00020 #define _BITS_PTHREADTYPES_H       1
00021 
00022 #define __need_schedparam
00023 #include <bits/sched.h>
00024 
00025 /* Fast locks (not abstract because mutexes and conditions aren't abstract). */
00026 struct _pthread_fastlock
00027 {
00028   long int __status;   /* "Free" or "taken" or head of waiting list */
00029   int __spinlock;      /* Used by compare_and_swap emulation. Also,
00030                        adaptive SMP lock stores spin count here. */
00031 };
00032 
00033 #ifndef _PTHREAD_DESCR_DEFINED
00034 /* Thread descriptors */
00035 typedef struct _pthread_descr_struct *_pthread_descr;
00036 # define _PTHREAD_DESCR_DEFINED
00037 #endif
00038 
00039 
00040 /* Attributes for threads.  */
00041 typedef struct __pthread_attr_s
00042 {
00043   int __detachstate;
00044   int __schedpolicy;
00045   struct __sched_param __schedparam;
00046   int __inheritsched;
00047   int __scope;
00048   size_t __guardsize;
00049   int __stackaddr_set;
00050   void *__stackaddr;
00051   size_t __stacksize;
00052 } pthread_attr_t;
00053 
00054 
00055 /* Conditions (not abstract because of PTHREAD_COND_INITIALIZER */
00056 
00057 #ifdef __GLIBC_HAVE_LONG_LONG
00058 __extension__ typedef long long __pthread_cond_align_t;
00059 #else
00060 typedef long __pthread_cond_align_t;
00061 #endif
00062 
00063 typedef struct
00064 {
00065   struct _pthread_fastlock __c_lock; /* Protect against concurrent access */
00066   _pthread_descr __c_waiting;        /* Threads waiting on this condition */
00067   char __padding[48 - sizeof (struct _pthread_fastlock)
00068                - sizeof (_pthread_descr) - sizeof (__pthread_cond_align_t)];
00069   __pthread_cond_align_t __align;
00070 } pthread_cond_t;
00071 
00072 
00073 /* Attribute for conditionally variables.  */
00074 typedef struct
00075 {
00076   int __dummy;
00077 } pthread_condattr_t;
00078 
00079 /* Keys for thread-specific data */
00080 typedef unsigned int pthread_key_t;
00081 
00082 
00083 /* Mutexes (not abstract because of PTHREAD_MUTEX_INITIALIZER).  */
00084 /* (The layout is unnatural to maintain binary compatibility
00085     with earlier releases of LinuxThreads.) */
00086 typedef struct
00087 {
00088   int __m_reserved;               /* Reserved for future use */
00089   int __m_count;                  /* Depth of recursive locking */
00090   _pthread_descr __m_owner;       /* Owner thread (if recursive or errcheck) */
00091   int __m_kind;                   /* Mutex kind: fast, recursive or errcheck */
00092   struct _pthread_fastlock __m_lock; /* Underlying fast lock */
00093 } pthread_mutex_t;
00094 
00095 
00096 /* Attribute for mutex.  */
00097 typedef struct
00098 {
00099   int __mutexkind;
00100 } pthread_mutexattr_t;
00101 
00102 
00103 /* Once-only execution */
00104 typedef int pthread_once_t;
00105 
00106 
00107 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
00108 /* Read-write locks.  */
00109 typedef struct _pthread_rwlock_t
00110 {
00111   struct _pthread_fastlock __rw_lock; /* Lock to guarantee mutual exclusion */
00112   int __rw_readers;                   /* Number of readers */
00113   _pthread_descr __rw_writer;         /* Identity of writer, or NULL if none */
00114   _pthread_descr __rw_read_waiting;   /* Threads waiting for reading */
00115   _pthread_descr __rw_write_waiting;  /* Threads waiting for writing */
00116   int __rw_kind;                      /* Reader/Writer preference selection */
00117   int __rw_pshared;                   /* Shared between processes or not */
00118 } pthread_rwlock_t;
00119 
00120 
00121 /* Attribute for read-write locks.  */
00122 typedef struct
00123 {
00124   int __lockkind;
00125   int __pshared;
00126 } pthread_rwlockattr_t;
00127 #endif
00128 
00129 #ifdef __USE_XOPEN2K
00130 /* POSIX spinlock data type.  */
00131 typedef volatile int pthread_spinlock_t;
00132 
00133 /* POSIX barrier. */
00134 typedef struct {
00135   struct _pthread_fastlock __ba_lock; /* Lock to guarantee mutual exclusion */
00136   int __ba_required;                  /* Threads needed for completion */
00137   int __ba_present;                   /* Threads waiting */
00138   _pthread_descr __ba_waiting;        /* Queue of waiting threads */
00139 } pthread_barrier_t;
00140 
00141 /* barrier attribute */
00142 typedef struct {
00143   int __pshared;
00144 } pthread_barrierattr_t;
00145 
00146 #endif
00147 
00148 
00149 /* Thread identifiers */
00150 typedef unsigned long int pthread_t;
00151 
00152 #endif /* bits/pthreadtypes.h */