1/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifndef _BITS_PTHREADTYPES_H
19#define _BITS_PTHREADTYPES_H 1
20
21#include <bits/wordsize.h>
22
23#ifdef __x86_64__
24# if __WORDSIZE == 64
25# define __SIZEOF_PTHREAD_ATTR_T 56
26# define __SIZEOF_PTHREAD_MUTEX_T 40
27# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
28# define __SIZEOF_PTHREAD_COND_T 48
29# define __SIZEOF_PTHREAD_CONDATTR_T 4
30# define __SIZEOF_PTHREAD_RWLOCK_T 56
31# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
32# define __SIZEOF_PTHREAD_BARRIER_T 32
33# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
34# else
35# define __SIZEOF_PTHREAD_ATTR_T 32
36# define __SIZEOF_PTHREAD_MUTEX_T 32
37# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
38# define __SIZEOF_PTHREAD_COND_T 48
39# define __SIZEOF_PTHREAD_CONDATTR_T 4
40# define __SIZEOF_PTHREAD_RWLOCK_T 44
41# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
42# define __SIZEOF_PTHREAD_BARRIER_T 20
43# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
44# endif
45#else
46# define __SIZEOF_PTHREAD_ATTR_T 36
47# define __SIZEOF_PTHREAD_MUTEX_T 24
48# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
49# define __SIZEOF_PTHREAD_COND_T 48
50# define __SIZEOF_PTHREAD_CONDATTR_T 4
51# define __SIZEOF_PTHREAD_RWLOCK_T 32
52# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
53# define __SIZEOF_PTHREAD_BARRIER_T 20
54# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
55#endif
56
57
58/* Thread identifiers. The structure of the attribute type is not
59 exposed on purpose. */
60typedef unsigned long int pthread_t;
61
62
63union pthread_attr_t
64{
65 char __size[__SIZEOF_PTHREAD_ATTR_T];
66 long int __align;
67};
68#ifndef __have_pthread_attr_t
69typedef union pthread_attr_t pthread_attr_t;
70# define __have_pthread_attr_t 1
71#endif
72
73
74#ifdef __x86_64__
75typedef struct __pthread_internal_list
76{
77 struct __pthread_internal_list *__prev;
78 struct __pthread_internal_list *__next;
79} __pthread_list_t;
80#else
81typedef struct __pthread_internal_slist
82{
83 struct __pthread_internal_slist *__next;
84} __pthread_slist_t;
85#endif
86
87
88/* Data structures for mutex handling. The structure of the attribute
89 type is not exposed on purpose. */
90typedef union
91{
92 struct __pthread_mutex_s
93 {
94 int __lock;
95 unsigned int __count;
96 int __owner;
97#ifdef __x86_64__
98 unsigned int __nusers;
99#endif
100 /* KIND must stay at this position in the structure to maintain
101 binary compatibility. */
102 int __kind;
103#ifdef __x86_64__
104 short __spins;
105 short __elision;
106 __pthread_list_t __list;
107# define __PTHREAD_MUTEX_HAVE_PREV 1
108# define __PTHREAD_MUTEX_HAVE_ELISION 1
109#else
110 unsigned int __nusers;
111 __extension__ union
112 {
113 struct
114 {
115 short __espins;
116 short __elision;
117# define __spins d.__espins
118# define __elision d.__elision
119# define __PTHREAD_MUTEX_HAVE_ELISION 2
120 } d;
121 __pthread_slist_t __list;
122 };
123#endif
124 } __data;
125 char __size[__SIZEOF_PTHREAD_MUTEX_T];
126 long int __align;
127} pthread_mutex_t;
128
129typedef union
130{
131 char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
132 int __align;
133} pthread_mutexattr_t;
134
135
136/* Data structure for conditional variable handling. The structure of
137 the attribute type is not exposed on purpose. */
138typedef union
139{
140 struct
141 {
142 int __lock;
143 unsigned int __futex;
144 __extension__ unsigned long long int __total_seq;
145 __extension__ unsigned long long int __wakeup_seq;
146 __extension__ unsigned long long int __woken_seq;
147 void *__mutex;
148 unsigned int __nwaiters;
149 unsigned int __broadcast_seq;
150 } __data;
151 char __size[__SIZEOF_PTHREAD_COND_T];
152 __extension__ long long int __align;
153} pthread_cond_t;
154
155typedef union
156{
157 char __size[__SIZEOF_PTHREAD_CONDATTR_T];
158 int __align;
159} pthread_condattr_t;
160
161
162/* Keys for thread-specific data */
163typedef unsigned int pthread_key_t;
164
165
166/* Once-only execution */
167typedef int pthread_once_t;
168
169
170#if defined __USE_UNIX98 || defined __USE_XOPEN2K
171/* Data structure for read-write lock variable handling. The
172 structure of the attribute type is not exposed on purpose. */
173typedef union
174{
175# ifdef __x86_64__
176 struct
177 {
178 int __lock;
179 unsigned int __nr_readers;
180 unsigned int __readers_wakeup;
181 unsigned int __writer_wakeup;
182 unsigned int __nr_readers_queued;
183 unsigned int __nr_writers_queued;
184 int __writer;
185 int __shared;
186 unsigned long int __pad1;
187 unsigned long int __pad2;
188 /* FLAGS must stay at this position in the structure to maintain
189 binary compatibility. */
190 unsigned int __flags;
191# define __PTHREAD_RWLOCK_INT_FLAGS_SHARED 1
192 } __data;
193# else
194 struct
195 {
196 int __lock;
197 unsigned int __nr_readers;
198 unsigned int __readers_wakeup;
199 unsigned int __writer_wakeup;
200 unsigned int __nr_readers_queued;
201 unsigned int __nr_writers_queued;
202 /* FLAGS must stay at this position in the structure to maintain
203 binary compatibility. */
204 unsigned char __flags;
205 unsigned char __shared;
206 unsigned char __pad1;
207 unsigned char __pad2;
208 int __writer;
209 } __data;
210# endif
211 char __size[__SIZEOF_PTHREAD_RWLOCK_T];
212 long int __align;
213} pthread_rwlock_t;
214
215typedef union
216{
217 char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
218 long int __align;
219} pthread_rwlockattr_t;
220#endif
221
222
223#ifdef __USE_XOPEN2K
224/* POSIX spinlock data type. */
225typedef volatile int pthread_spinlock_t;
226
227
228/* POSIX barriers data type. The structure of the type is
229 deliberately not exposed. */
230typedef union
231{
232 char __size[__SIZEOF_PTHREAD_BARRIER_T];
233 long int __align;
234} pthread_barrier_t;
235
236typedef union
237{
238 char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
239 int __align;
240} pthread_barrierattr_t;
241#endif
242
243
244#ifndef __x86_64__
245/* Extra attributes for the cleanup functions. */
246# define __cleanup_fct_attribute __attribute__ ((__regparm__ (1)))
247#endif
248
249#endif /* bits/pthreadtypes.h */
250