Back to index

glibc  2.9
pthreadtypes.h
Go to the documentation of this file.
00001 /* Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _BITS_PTHREADTYPES_H
00020 #define _BITS_PTHREADTYPES_H       1
00021 
00022 /* Linuxthread type sizes (bytes):
00023    sizeof(pthread_attr_t) = 0x24 (36)
00024    sizeof(pthread_mutex_t) = 0x30 (48)
00025    sizeof(pthread_mutexattr_t) = 0x4 (4)
00026    sizeof(pthread_cond_t) = 0x30 (48)
00027        = Expanded to 64 bytes in NPTL. 
00028    sizeof(pthread_cond_compat_t) = 0xc (12)
00029        = Did not exist in Linuxthreads.
00030    sizeof(pthread_condattr_t) = 0x4 (4)
00031    sizeof(pthread_rwlock_t) = 0x40 (64)
00032    sizeof(pthread_rwlockattr_t) = 0x8 (8)
00033    sizeof(pthread_barrier_t) = 0x30 (48)
00034    sizeof(pthread_barrierattr_t) = 0x4 (4) */
00035 
00036 #define __SIZEOF_PTHREAD_ATTR_T 36
00037 #define __SIZEOF_PTHREAD_MUTEX_T 48 
00038 #define __SIZEOF_PTHREAD_MUTEXATTR_T 4
00039 #define __SIZEOF_PTHREAD_COND_T 64
00040 #define __SIZEOF_PTHREAD_COND_COMPAT_T 12
00041 #define __SIZEOF_PTHREAD_CONDATTR_T 4
00042 #define __SIZEOF_PTHREAD_RWLOCK_T 64
00043 #define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
00044 #define __SIZEOF_PTHREAD_BARRIER_T 48
00045 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
00046 
00047 /* Thread identifiers.  The structure of the attribute type is not
00048    exposed on purpose.  */
00049 typedef unsigned long int pthread_t;
00050 
00051 /* Our old basic lock type, listed here for posterity.
00052    We needed self-aligning locks for linuxthreads LDCW 
00053    implementation. For NPTL we use LWS Compare and 
00054    Exchange to implement primitives. */
00055 #if 0
00056 typedef volatile struct {
00057        int lock[4];
00058 } __attribute__ ((aligned(16))) __atomic_lock_t;
00059 #endif
00060 
00061 typedef union
00062 {
00063   char __size[__SIZEOF_PTHREAD_ATTR_T];
00064   long int __align;
00065 } pthread_attr_t;
00066 
00067 
00068 typedef struct __pthread_internal_slist
00069 {
00070   struct __pthread_internal_slist *__next;
00071 } __pthread_slist_t;
00072 
00073 
00074 /* Data structures for mutex handling.  The structure of the attribute
00075    type is not exposed on purpose.  */
00076 typedef union
00077 {
00078   struct __pthread_mutex_s
00079   {
00080     int __lock;
00081     unsigned int __count;
00082     int __owner;
00083     /* KIND must stay at this position in the structure to maintain
00084        binary compatibility.  */
00085     int __kind;
00086     unsigned int __nusers;
00087     __extension__ union
00088     {
00089       int __spins;
00090       __pthread_slist_t __list;
00091     };
00092   } __data;
00093   char __size[__SIZEOF_PTHREAD_MUTEX_T];
00094   long int __align;
00095 } pthread_mutex_t;
00096 
00097 typedef union
00098 {
00099   char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
00100   long int __align;
00101 } pthread_mutexattr_t;
00102 
00103 
00104 /* Data structure for conditional variable handling.  The structure of
00105    the attribute type is not exposed on purpose.  */
00106 typedef union
00107 {
00108   struct
00109   {
00110     int __lock;
00111     unsigned int __futex;
00112     __extension__ unsigned long long int __total_seq;
00113     __extension__ unsigned long long int __wakeup_seq;
00114     __extension__ unsigned long long int __woken_seq;
00115     void *__mutex;
00116     unsigned int __nwaiters;
00117     unsigned int __broadcast_seq;
00118   } __data;
00119   char __size[__SIZEOF_PTHREAD_COND_T];
00120   __extension__ long long int __align;
00121 } pthread_cond_t;
00122 
00123 typedef union
00124 {
00125   char __size[__SIZEOF_PTHREAD_CONDATTR_T];
00126   long int __align;
00127 } pthread_condattr_t;
00128 
00129 
00130 /* Keys for thread-specific data */
00131 typedef unsigned int pthread_key_t;
00132 
00133 
00134 /* Once-only execution */
00135 typedef int pthread_once_t;
00136 
00137 
00138 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
00139 /* Data structure for read-write lock variable handling.  The
00140    structure of the attribute type is not exposed on purpose.  */
00141 typedef union
00142 {
00143   struct
00144   {
00145     int __lock;
00146     unsigned int __nr_readers;
00147     unsigned int __readers_wakeup;
00148     unsigned int __writer_wakeup;
00149     unsigned int __nr_readers_queued;
00150     unsigned int __nr_writers_queued;
00151     /* FLAGS must stay at this position in the structure to maintain
00152        binary compatibility.  */
00153     unsigned char __pad2;
00154     unsigned char __pad1;
00155     unsigned char __shared;
00156     unsigned char __flags;
00157     int __writer;
00158   } __data;
00159   char __size[__SIZEOF_PTHREAD_RWLOCK_T];
00160   long int __align;
00161 } pthread_rwlock_t;
00162 
00163 typedef union
00164 {
00165   char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
00166   long int __align;
00167 } pthread_rwlockattr_t;
00168 #endif
00169 
00170 
00171 #ifdef __USE_XOPEN2K
00172 /* POSIX spinlock data type.  */
00173 typedef volatile int pthread_spinlock_t;
00174 
00175 
00176 /* POSIX barriers data type.  The structure of the type is
00177    deliberately not exposed.  */
00178 typedef union
00179 {
00180   char __size[__SIZEOF_PTHREAD_BARRIER_T];
00181   long int __align;
00182 } pthread_barrier_t;
00183 
00184 typedef union
00185 {
00186   char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
00187   int __align;
00188 } pthread_barrierattr_t;
00189 #endif
00190 
00191 
00192 #endif /* bits/pthreadtypes.h */