1 | /* Common threading primitives definitions for both POSIX and C11. |
2 | Copyright (C) 2017 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library 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 GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ |
18 | |
19 | #ifndef _THREAD_SHARED_TYPES_H |
20 | #define _THREAD_SHARED_TYPES_H 1 |
21 | |
22 | /* Arch-specific definitions. Each architecture must define the following |
23 | macros to define the expected sizes of pthread data types: |
24 | |
25 | __SIZEOF_PTHREAD_ATTR_T - size of pthread_attr_t. |
26 | __SIZEOF_PTHREAD_MUTEX_T - size of pthread_mutex_t. |
27 | __SIZEOF_PTHREAD_MUTEXATTR_T - size of pthread_mutexattr_t. |
28 | __SIZEOF_PTHREAD_COND_T - size of pthread_cond_t. |
29 | __SIZEOF_PTHREAD_CONDATTR_T - size of pthread_condattr_t. |
30 | __SIZEOF_PTHREAD_RWLOCK_T - size of pthread_rwlock_t. |
31 | __SIZEOF_PTHREAD_RWLOCKATTR_T - size of pthread_rwlockattr_t. |
32 | __SIZEOF_PTHREAD_BARRIER_T - size of pthread_barrier_t. |
33 | __SIZEOF_PTHREAD_BARRIERATTR_T - size of pthread_barrierattr_t. |
34 | |
35 | Also, the following macros must be define for internal pthread_mutex_t |
36 | struct definitions (struct __pthread_mutex_s): |
37 | |
38 | __PTHREAD_COMPAT_PADDING_MID - any additional members after 'kind' |
39 | and before '__spin' (for 64 bits) or |
40 | '__nusers' (for 32 bits). |
41 | __PTHREAD_COMPAT_PADDING_END - any additional members at the end of |
42 | the internal structure. |
43 | __PTHREAD_MUTEX_LOCK_ELISION - 1 if the architecture supports lock |
44 | elision or 0 otherwise. |
45 | |
46 | The additional macro defines any constraint for the lock alignment |
47 | inside the thread structures: |
48 | |
49 | __LOCK_ALIGNMENT - for internal lock/futex usage. |
50 | |
51 | Same idea but for the once locking primitive: |
52 | |
53 | __ONCE_ALIGNMENT - for pthread_once_t/once_flag definition. |
54 | |
55 | And finally the internal pthread_rwlock_t (struct __pthread_rwlock_arch_t) |
56 | must be defined. |
57 | */ |
58 | #include <bits/pthreadtypes-arch.h> |
59 | |
60 | /* Common definition of pthread_mutex_t. */ |
61 | |
62 | #if __WORDSIZE == 64 |
63 | typedef struct __pthread_internal_list |
64 | { |
65 | struct __pthread_internal_list *__prev; |
66 | struct __pthread_internal_list *__next; |
67 | } __pthread_list_t; |
68 | #else |
69 | typedef struct __pthread_internal_slist |
70 | { |
71 | struct __pthread_internal_slist *__next; |
72 | } __pthread_slist_t; |
73 | #endif |
74 | |
75 | /* Lock elision support. */ |
76 | #if __PTHREAD_MUTEX_LOCK_ELISION |
77 | # if __WORDSIZE == 64 |
78 | # define __PTHREAD_SPINS_DATA \ |
79 | short __spins; \ |
80 | short __elision |
81 | # define __PTHREAD_SPINS 0, 0 |
82 | # else |
83 | # define __PTHREAD_SPINS_DATA \ |
84 | struct \ |
85 | { \ |
86 | short __espins; \ |
87 | short __eelision; \ |
88 | } __elision_data |
89 | # define __PTHREAD_SPINS { 0, 0 } |
90 | # define __spins __elision_data.__espins |
91 | # define __elision __elision_data.__eelision |
92 | # endif |
93 | #else |
94 | # define __PTHREAD_SPINS_DATA int __spins |
95 | /* Mutex __spins initializer used by PTHREAD_MUTEX_INITIALIZER. */ |
96 | # define __PTHREAD_SPINS 0 |
97 | #endif |
98 | |
99 | struct __pthread_mutex_s |
100 | { |
101 | int __lock __LOCK_ALIGNMENT; |
102 | unsigned int __count; |
103 | int __owner; |
104 | #if __WORDSIZE == 64 |
105 | unsigned int __nusers; |
106 | #endif |
107 | /* KIND must stay at this position in the structure to maintain |
108 | binary compatibility with static initializers. */ |
109 | int __kind; |
110 | __PTHREAD_COMPAT_PADDING_MID |
111 | #if __WORDSIZE == 64 |
112 | __PTHREAD_SPINS_DATA; |
113 | __pthread_list_t __list; |
114 | # define __PTHREAD_MUTEX_HAVE_PREV 1 |
115 | #else |
116 | unsigned int __nusers; |
117 | __extension__ union |
118 | { |
119 | __PTHREAD_SPINS_DATA; |
120 | __pthread_slist_t __list; |
121 | }; |
122 | #endif |
123 | __PTHREAD_COMPAT_PADDING_END |
124 | }; |
125 | |
126 | |
127 | /* Common definition of pthread_cond_t. */ |
128 | |
129 | struct __pthread_cond_s |
130 | { |
131 | __extension__ union |
132 | { |
133 | __extension__ unsigned long long int __wseq; |
134 | struct |
135 | { |
136 | unsigned int __low; |
137 | unsigned int __high; |
138 | } __wseq32; |
139 | }; |
140 | __extension__ union |
141 | { |
142 | __extension__ unsigned long long int __g1_start; |
143 | struct |
144 | { |
145 | unsigned int __low; |
146 | unsigned int __high; |
147 | } __g1_start32; |
148 | }; |
149 | unsigned int __g_refs[2] __LOCK_ALIGNMENT; |
150 | unsigned int __g_size[2]; |
151 | unsigned int __g1_orig_size; |
152 | unsigned int __wrefs; |
153 | unsigned int __g_signals[2]; |
154 | }; |
155 | |
156 | #endif /* _THREAD_SHARED_TYPES_H */ |
157 | |