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