1 /* Copyright (C) 2005-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
18 #ifndef _BITS_PTHREADTYPES_H
19 #define _BITS_PTHREADTYPES_H 1
21 /* Linuxthread type sizes (bytes):
22 sizeof(pthread_attr_t) = 0x24 (36)
23 sizeof(pthread_barrier_t) = 0x30 (48)
24 sizeof(pthread_barrierattr_t) = 0x4 (4)
25 sizeof(pthread_cond_t) = 0x30 (48)
26 sizeof(pthread_condattr_t) = 0x4 (4)
27 sizeof(pthread_mutex_t) = 0x30 (48)
28 sizeof(pthread_mutexattr_t) = 0x4 (4)
29 sizeof(pthread_rwlock_t) = 0x40 (64)
30 sizeof(pthread_rwlockattr_t) = 0x8 (8)
31 sizeof(pthread_spinlock_t) = 0x10 (16) */
33 #define __SIZEOF_PTHREAD_ATTR_T 36
34 #define __SIZEOF_PTHREAD_BARRIER_T 48
35 #define __SIZEOF_PTHREAD_BARRIERATTR_T 4
36 #define __SIZEOF_PTHREAD_COND_T 48
37 #define __SIZEOF_PTHREAD_CONDATTR_T 4
38 #define __SIZEOF_PTHREAD_MUTEX_T 48
39 #define __SIZEOF_PTHREAD_MUTEXATTR_T 4
40 #define __SIZEOF_PTHREAD_RWLOCK_T 64
41 #define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
43 /* Thread identifiers. The structure of the attribute type is not
44 exposed on purpose. */
45 typedef unsigned long int pthread_t
;
49 char __size
[__SIZEOF_PTHREAD_ATTR_T
];
52 #ifndef __have_pthread_attr_t
53 typedef union pthread_attr_t pthread_attr_t
;
54 # define __have_pthread_attr_t 1
58 typedef struct __pthread_internal_slist
60 struct __pthread_internal_slist
*__next
;
64 /* Data structures for mutex handling. The structure of the attribute
65 type is not exposed on purpose. */
68 struct __pthread_mutex_s
70 int __lock
__attribute__ ((__aligned__(16)));
73 /* KIND must stay at this position in the structure to maintain
74 binary compatibility with static initializers. */
76 /* The old 4-word 16-byte aligned lock. This is initalized
77 to all ones by the Linuxthreads PTHREAD_MUTEX_INITIALIZER.
79 int __compat_padding
[4];
80 /* In the old structure there are 4 words left due to alignment.
81 In NPTL two words are used. */
82 unsigned int __nusers
;
86 __pthread_slist_t __list
;
88 /* Two more words are left before the NPTL
89 pthread_mutex_t is larger than Linuxthreads. */
93 char __size
[__SIZEOF_PTHREAD_MUTEX_T
];
97 /* Mutex __spins initializer used by PTHREAD_MUTEX_INITIALIZER. */
98 #define __PTHREAD_SPINS 0
102 char __size
[__SIZEOF_PTHREAD_MUTEXATTR_T
];
104 } pthread_mutexattr_t
;
107 /* Data structure for conditional variable handling. The structure of
108 the attribute type is not exposed on purpose. However, this structure
109 is exposed via PTHREAD_COND_INITIALIZER, and because of this, the
110 Linuxthreads version sets the first four ints to one. In the NPTL
111 version we must check, in every function using pthread_cond_t,
112 for the static Linuxthreads initializer and clear the appropriate
118 /* In the old Linuxthreads pthread_cond_t, this is the
119 start of the 4-word lock structure, the next four words
120 are set all to 1 by the Linuxthreads
121 PTHREAD_COND_INITIALIZER. */
122 int __lock
__attribute__ ((__aligned__(16)));
123 /* Tracks the initialization of this structure:
124 0 initialized with NPTL PTHREAD_COND_INITIALIZER.
125 1 initialized with Linuxthreads PTHREAD_COND_INITIALIZER.
126 2 initialization in progress. */
128 unsigned int __futex
;
130 /* In the old Linuxthreads this would have been the start
131 of the pthread_fastlock status word. */
132 __extension__
unsigned long long int __total_seq
;
133 __extension__
unsigned long long int __wakeup_seq
;
134 __extension__
unsigned long long int __woken_seq
;
135 unsigned int __nwaiters
;
136 unsigned int __broadcast_seq
;
137 /* The NPTL pthread_cond_t is exactly the same size as
138 the Linuxthreads version, there are no words to spare. */
140 char __size
[__SIZEOF_PTHREAD_COND_T
];
141 __extension__
long long int __align
;
146 char __size
[__SIZEOF_PTHREAD_CONDATTR_T
];
148 } pthread_condattr_t
;
151 /* Keys for thread-specific data */
152 typedef unsigned int pthread_key_t
;
155 /* Once-only execution */
156 typedef int pthread_once_t
;
159 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
160 /* Data structure for read-write lock variable handling. The
161 structure of the attribute type is not exposed on purpose. */
166 /* In the old Linuxthreads pthread_rwlock_t, this is the
167 start of the 4-word 16-byte aligned lock structure. The
168 next four words are all set to 1 by the Linuxthreads
169 PTHREAD_RWLOCK_INITIALIZER. We ignore them in NPTL. */
170 int __compat_padding
[4] __attribute__ ((__aligned__(16)));
172 unsigned int __nr_readers
;
173 unsigned int __readers_wakeup
;
174 unsigned int __writer_wakeup
;
175 unsigned int __nr_readers_queued
;
176 unsigned int __nr_writers_queued
;
178 /* An unused word, reserved for future use. It was added
179 to maintain the location of the flags from the Linuxthreads
180 layout of this structure. */
182 /* FLAGS must stay at this position in the structure to maintain
183 binary compatibility. */
184 unsigned char __pad2
;
185 unsigned char __pad1
;
186 unsigned char __shared
;
187 unsigned char __flags
;
188 /* The NPTL pthread_rwlock_t is 4 words smaller than the
189 Linuxthreads version. One word is in the middle of the
190 structure, the other three are at the end. */
195 char __size
[__SIZEOF_PTHREAD_RWLOCK_T
];
199 #define __PTHREAD_RWLOCK_ELISION_EXTRA 0
203 char __size
[__SIZEOF_PTHREAD_RWLOCKATTR_T
];
205 } pthread_rwlockattr_t
;
210 /* POSIX spinlock data type. */
211 typedef volatile int pthread_spinlock_t
;
214 /* POSIX barriers data type. The structure of the type is
215 deliberately not exposed. */
218 char __size
[__SIZEOF_PTHREAD_BARRIER_T
];
224 char __size
[__SIZEOF_PTHREAD_BARRIERATTR_T
];
226 } pthread_barrierattr_t
;
230 #endif /* bits/pthreadtypes.h */