]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/x86/bits/pthreadtypes.h
New pthread rwlock that is more scalable.
[thirdparty/glibc.git] / sysdeps / x86 / bits / pthreadtypes.h
CommitLineData
bfff8b1b 1/* Copyright (C) 2002-2017 Free Software Foundation, Inc.
654dff90 2 This file is part of the GNU C Library.
654dff90
UD
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
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
654dff90
UD
17
18#ifndef _BITS_PTHREADTYPES_H
19#define _BITS_PTHREADTYPES_H 1
20
6442d5d7
UD
21#include <bits/wordsize.h>
22
b8caea2c
L
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
6442d5d7
UD
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
654dff90
UD
56
57
58/* Thread identifiers. The structure of the attribute type is not
59 exposed on purpose. */
806e4a4a 60typedef unsigned long int pthread_t;
654dff90
UD
61
62
8da0464f 63union pthread_attr_t
654dff90
UD
64{
65 char __size[__SIZEOF_PTHREAD_ATTR_T];
66 long int __align;
4a3dded5
UD
67};
68#ifndef __have_pthread_attr_t
22f9d9df 69typedef union pthread_attr_t pthread_attr_t;
4a3dded5
UD
70# define __have_pthread_attr_t 1
71#endif
654dff90
UD
72
73
b8caea2c 74#ifdef __x86_64__
b007ce7c
UD
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
654dff90
UD
88/* Data structures for mutex handling. The structure of the attribute
89 type is not exposed on purpose. */
d804f5df 90typedef union
654dff90 91{
d804f5df 92 struct __pthread_mutex_s
654dff90
UD
93 {
94 int __lock;
95 unsigned int __count;
61623643 96 int __owner;
b8caea2c 97#ifdef __x86_64__
61623643 98 unsigned int __nusers;
6442d5d7 99#endif
654dff90 100 /* KIND must stay at this position in the structure to maintain
c74940f2 101 binary compatibility with static initializers. */
654dff90 102 int __kind;
b8caea2c 103#ifdef __x86_64__
e8c659d7
AK
104 short __spins;
105 short __elision;
b007ce7c 106 __pthread_list_t __list;
1bcfb5a5 107# define __PTHREAD_MUTEX_HAVE_PREV 1
01f8eac2
AZ
108/* Mutex __spins initializer used by PTHREAD_MUTEX_INITIALIZER. */
109# define __PTHREAD_SPINS 0, 0
1bcfb5a5 110#else
6442d5d7 111 unsigned int __nusers;
01a3f2ef 112 __extension__ union
1bcfb5a5 113 {
e8c659d7
AK
114 struct
115 {
075b9322 116 short __espins;
e8c659d7 117 short __elision;
2307e126
SP
118# define __spins __elision_data.__espins
119# define __elision __elision_data.__elision
01f8eac2 120# define __PTHREAD_SPINS { 0, 0 }
2307e126 121 } __elision_data;
b007ce7c 122 __pthread_slist_t __list;
1bcfb5a5 123 };
6442d5d7 124#endif
654dff90
UD
125 } __data;
126 char __size[__SIZEOF_PTHREAD_MUTEX_T];
127 long int __align;
128} pthread_mutex_t;
129
130typedef union
131{
132 char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
7da168bf 133 int __align;
654dff90
UD
134} pthread_mutexattr_t;
135
136
137/* Data structure for conditional variable handling. The structure of
138 the attribute type is not exposed on purpose. */
139typedef union
140{
141 struct
142 {
ed19993b
TR
143 __extension__ union
144 {
145 __extension__ unsigned long long int __wseq;
146 struct {
147 unsigned int __low;
148 unsigned int __high;
149 } __wseq32;
150 };
151 __extension__ union
152 {
153 __extension__ unsigned long long int __g1_start;
154 struct {
155 unsigned int __low;
156 unsigned int __high;
157 } __g1_start32;
158 };
159 unsigned int __g_refs[2];
160 unsigned int __g_size[2];
161 unsigned int __g1_orig_size;
162 unsigned int __wrefs;
163 unsigned int __g_signals[2];
654dff90
UD
164 } __data;
165 char __size[__SIZEOF_PTHREAD_COND_T];
e9f4e844 166 __extension__ long long int __align;
654dff90
UD
167} pthread_cond_t;
168
169typedef union
170{
171 char __size[__SIZEOF_PTHREAD_CONDATTR_T];
7da168bf 172 int __align;
654dff90
UD
173} pthread_condattr_t;
174
175
176/* Keys for thread-specific data */
177typedef unsigned int pthread_key_t;
178
179
180/* Once-only execution */
181typedef int pthread_once_t;
182
183
ccc63b07 184#if defined __USE_UNIX98 || defined __USE_XOPEN2K
654dff90
UD
185/* Data structure for read-write lock variable handling. The
186 structure of the attribute type is not exposed on purpose. */
187typedef union
188{
b8caea2c 189# ifdef __x86_64__
654dff90
UD
190 struct
191 {
cc25c8b4
TR
192 unsigned int __readers;
193 unsigned int __writers;
194 unsigned int __wrphase_futex;
195 unsigned int __writers_futex;
196 unsigned int __pad3;
197 unsigned int __pad4;
198 int __cur_writer;
e59660bc 199 int __shared;
8491ed6d 200 signed char __rwelision;
c8daec5c
L
201# ifdef __ILP32__
202 unsigned char __pad1[3];
203# define __PTHREAD_RWLOCK_ELISION_EXTRA 0, { 0, 0, 0 }
204# else
8491ed6d 205 unsigned char __pad1[7];
c8daec5c
L
206# define __PTHREAD_RWLOCK_ELISION_EXTRA 0, { 0, 0, 0, 0, 0, 0, 0 }
207# endif
69278ade 208 unsigned long int __pad2;
654dff90
UD
209 /* FLAGS must stay at this position in the structure to maintain
210 binary compatibility. */
211 unsigned int __flags;
b8caea2c 212# define __PTHREAD_RWLOCK_INT_FLAGS_SHARED 1
654dff90 213 } __data;
6442d5d7
UD
214# else
215 struct
216 {
cc25c8b4
TR
217 unsigned int __readers;
218 unsigned int __writers;
219 unsigned int __wrphase_futex;
220 unsigned int __writers_futex;
221 unsigned int __pad3;
222 unsigned int __pad4;
6442d5d7
UD
223 /* FLAGS must stay at this position in the structure to maintain
224 binary compatibility. */
e59660bc
UD
225 unsigned char __flags;
226 unsigned char __shared;
8491ed6d
AK
227 signed char __rwelision;
228# define __PTHREAD_RWLOCK_ELISION_EXTRA 0
e59660bc 229 unsigned char __pad2;
cc25c8b4 230 int __cur_writer;
6442d5d7
UD
231 } __data;
232# endif
654dff90
UD
233 char __size[__SIZEOF_PTHREAD_RWLOCK_T];
234 long int __align;
235} pthread_rwlock_t;
236
237typedef union
238{
239 char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
240 long int __align;
241} pthread_rwlockattr_t;
242#endif
243
244
245#ifdef __USE_XOPEN2K
246/* POSIX spinlock data type. */
247typedef volatile int pthread_spinlock_t;
248
249
250/* POSIX barriers data type. The structure of the type is
251 deliberately not exposed. */
252typedef union
253{
254 char __size[__SIZEOF_PTHREAD_BARRIER_T];
255 long int __align;
256} pthread_barrier_t;
257
258typedef union
259{
260 char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
261 int __align;
262} pthread_barrierattr_t;
263#endif
264
265
c0d2c853 266#ifndef __x86_64__
088f460f
UD
267/* Extra attributes for the cleanup functions. */
268# define __cleanup_fct_attribute __attribute__ ((__regparm__ (1)))
269#endif
270
654dff90 271#endif /* bits/pthreadtypes.h */