1 /* Linuxthreads - a simple clone()-based implementation of Posix */ 2 /* threads for Linux. */ 3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */ 4 /* */ 5 /* This program is free software; you can redistribute it and/or */ 6 /* modify it under the terms of the GNU Library General Public License */ 7 /* as published by the Free Software Foundation; either version 2 */ 8 /* of the License, or (at your option) any later version. */ 9 /* */ 10 /* This program is distributed in the hope that it will be useful, */ 11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 13 /* GNU Library General Public License for more details. */ 14 15 #if !defined _BITS_TYPES_H && !defined _PTHREAD_H 16 # error "Never include <bits/pthreadtypes.h> directly; use <sys/types.h> instead." 17 #endif 18 19 #ifndef _BITS_PTHREADTYPES_H 20 #define _BITS_PTHREADTYPES_H 1 21 22 #define __need_size_t 23 #include <stddef.h> 24 25 #define __need_schedparam 26 #include <bits/sched.h> 27 28 #define __SIZEOF_PTHREAD_CONDATTR_T 4 29 30 /* Fast locks (not abstract because mutexes and conditions aren't abstract). */ 31 struct _pthread_fastlock 32 { 33 long int __status; /* "Free" or "taken" or head of waiting list */ 34 int __spinlock; /* Used by compare_and_swap emulation. Also, 35 adaptive SMP lock stores spin count here. */ 36 }; 37 38 #ifndef _PTHREAD_DESCR_DEFINED 39 /* Thread descriptors */ 40 typedef struct _pthread_descr_struct *_pthread_descr; 41 # define _PTHREAD_DESCR_DEFINED 42 #endif 43 44 45 /* Attributes for threads. */ 46 typedef struct __pthread_attr_s 47 { 48 int __detachstate; 49 int __schedpolicy; 50 struct __sched_param __schedparam; 51 int __inheritsched; 52 int __scope; 53 size_t __guardsize; 54 int __stackaddr_set; 55 void *__stackaddr; 56 size_t __stacksize; 57 } pthread_attr_t; 58 59 60 /* Conditions (not abstract because of PTHREAD_COND_INITIALIZER */ 61 typedef struct 62 { 63 struct _pthread_fastlock __c_lock; /* Protect against concurrent access */ 64 _pthread_descr __c_waiting; /* Threads waiting on this condition */ 65 } pthread_cond_t; 66 67 68 typedef union 69 { 70 char __size[__SIZEOF_PTHREAD_CONDATTR_T]; 71 int __align; 72 } pthread_condattr_t; 73 74 75 /* Keys for thread-specific data */ 76 typedef unsigned int pthread_key_t; 77 78 79 /* Mutexes (not abstract because of PTHREAD_MUTEX_INITIALIZER). */ 80 /* (The layout is unnatural to maintain binary compatibility 81 with earlier releases of LinuxThreads.) */ 82 typedef struct 83 { 84 int __m_reserved; /* Reserved for future use */ 85 int __m_count; /* Depth of recursive locking */ 86 _pthread_descr __m_owner; /* Owner thread (if recursive or errcheck) */ 87 int __m_kind; /* Mutex kind: fast, recursive or errcheck */ 88 struct _pthread_fastlock __m_lock; /* Underlying fast lock */ 89 } pthread_mutex_t; 90 91 92 /* Attribute for mutex. */ 93 typedef struct 94 { 95 int __mutexkind; 96 } pthread_mutexattr_t; 97 98 99 /* Once-only execution */ 100 typedef int pthread_once_t; 101 102 103 #if defined __USE_UNIX98 || defined __USE_XOPEN2K 104 /* Read-write locks. */ 105 typedef struct _pthread_rwlock_t 106 { 107 struct _pthread_fastlock __rw_lock; /* Lock to guarantee mutual exclusion */ 108 int __rw_readers; /* Number of readers */ 109 _pthread_descr __rw_writer; /* Identity of writer, or NULL if none */ 110 _pthread_descr __rw_read_waiting; /* Threads waiting for reading */ 111 _pthread_descr __rw_write_waiting; /* Threads waiting for writing */ 112 int __rw_kind; /* Reader/Writer preference selection */ 113 int __rw_pshared; /* Shared between processes or not */ 114 } pthread_rwlock_t; 115 116 117 /* Attribute for read-write locks. */ 118 typedef struct 119 { 120 int __lockkind; 121 int __pshared; 122 } pthread_rwlockattr_t; 123 #endif 124 125 #ifdef __USE_XOPEN2K 126 /* POSIX spinlock data type. */ 127 typedef volatile int pthread_spinlock_t; 128 129 /* POSIX barrier. */ 130 typedef struct { 131 struct _pthread_fastlock __ba_lock; /* Lock to guarantee mutual exclusion */ 132 int __ba_required; /* Threads needed for completion */ 133 int __ba_present; /* Threads waiting */ 134 _pthread_descr __ba_waiting; /* Queue of waiting threads */ 135 } pthread_barrier_t; 136 137 /* barrier attribute */ 138 typedef struct { 139 int __pshared; 140 } pthread_barrierattr_t; 141 142 #endif 143 144 145 /* Thread identifiers */ 146 typedef unsigned long int pthread_t; 147 148 #endif /* bits/pthreadtypes.h */ 149