]>
Commit | Line | Data |
---|---|---|
d614a753 | 1 | /* Copyright (C) 2002-2020 Free Software Foundation, Inc. |
76a50749 UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. | |
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 | |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
76a50749 UD |
18 | |
19 | #ifndef _INTERNALTYPES_H | |
20 | #define _INTERNALTYPES_H 1 | |
21 | ||
73e9ae88 | 22 | #include <stdint.h> |
042e1521 CD |
23 | #include <atomic.h> |
24 | #include <endian.h> | |
73e9ae88 | 25 | |
76a50749 UD |
26 | |
27 | struct pthread_attr | |
28 | { | |
29 | /* Scheduler parameters and priority. */ | |
30 | struct sched_param schedparam; | |
31 | int schedpolicy; | |
32 | /* Various flags like detachstate, scope, etc. */ | |
33 | int flags; | |
34 | /* Size of guard area. */ | |
35 | size_t guardsize; | |
36 | /* Stack handling. */ | |
37 | void *stackaddr; | |
38 | size_t stacksize; | |
80f536db UD |
39 | /* Affinity map. */ |
40 | cpu_set_t *cpuset; | |
701a7b23 | 41 | size_t cpusetsize; |
76a50749 UD |
42 | }; |
43 | ||
44 | #define ATTR_FLAG_DETACHSTATE 0x0001 | |
45 | #define ATTR_FLAG_NOTINHERITSCHED 0x0002 | |
46 | #define ATTR_FLAG_SCOPEPROCESS 0x0004 | |
47 | #define ATTR_FLAG_STACKADDR 0x0008 | |
5cb48b84 | 48 | #define ATTR_FLAG_OLDATTR 0x0010 |
14ffbc83 UD |
49 | #define ATTR_FLAG_SCHED_SET 0x0020 |
50 | #define ATTR_FLAG_POLICY_SET 0x0040 | |
76a50749 | 51 | |
331c6e8a FW |
52 | /* Used to allocate a pthread_attr_t object which is also accessed |
53 | internally. */ | |
54 | union pthread_attr_transparent | |
55 | { | |
56 | pthread_attr_t external; | |
57 | struct pthread_attr internal; | |
58 | }; | |
76a50749 UD |
59 | |
60 | /* Mutex attribute data structure. */ | |
61 | struct pthread_mutexattr | |
62 | { | |
63 | /* Identifier for the kind of mutex. | |
64 | ||
65 | Bit 31 is set if the mutex is to be shared between processes. | |
66 | ||
67 | Bit 0 to 30 contain one of the PTHREAD_MUTEX_ values to identify | |
68 | the type of the mutex. */ | |
69 | int mutexkind; | |
70 | }; | |
71 | ||
72 | ||
73 | /* Conditional variable attribute data structure. */ | |
74 | struct pthread_condattr | |
75 | { | |
86a9ee5e UD |
76 | /* Combination of values: |
77 | ||
ed19993b TR |
78 | Bit 0 : flag whether conditional variable will be |
79 | sharable between processes. | |
80 | Bit 1-COND_CLOCK_BITS: Clock ID. COND_CLOCK_BITS is the number of bits | |
81 | needed to represent the ID of the clock. */ | |
86a9ee5e | 82 | int value; |
76a50749 | 83 | }; |
ed19993b | 84 | #define COND_CLOCK_BITS 1 |
73f7c32c UD |
85 | |
86 | ||
76a50749 UD |
87 | /* Read-write lock variable attribute data structure. */ |
88 | struct pthread_rwlockattr | |
89 | { | |
90 | int lockkind; | |
91 | int pshared; | |
92 | }; | |
93 | ||
94 | ||
b02840ba TR |
95 | /* Barrier data structure. See pthread_barrier_wait for a description |
96 | of how these fields are used. */ | |
76a50749 UD |
97 | struct pthread_barrier |
98 | { | |
b02840ba TR |
99 | unsigned int in; |
100 | unsigned int current_round; | |
101 | unsigned int count; | |
102 | int shared; | |
103 | unsigned int out; | |
76a50749 | 104 | }; |
b02840ba TR |
105 | /* See pthread_barrier_wait for a description. */ |
106 | #define BARRIER_IN_THRESHOLD (UINT_MAX/2) | |
76a50749 UD |
107 | |
108 | ||
109 | /* Barrier variable attribute data structure. */ | |
110 | struct pthread_barrierattr | |
111 | { | |
112 | int pshared; | |
113 | }; | |
114 | ||
115 | ||
116 | /* Thread-local data handling. */ | |
117 | struct pthread_key_struct | |
118 | { | |
119 | /* Sequence numbers. Even numbers indicated vacant entries. Note | |
120 | that zero is even. We use uintptr_t to not require padding on | |
121 | 32- and 64-bit machines. On 64-bit machines it helps to avoid | |
122 | wrapping, too. */ | |
123 | uintptr_t seq; | |
124 | ||
125 | /* Destructor for the data. */ | |
126 | void (*destr) (void *); | |
127 | }; | |
128 | ||
129 | /* Check whether an entry is unused. */ | |
130 | #define KEY_UNUSED(p) (((p) & 1) == 0) | |
131 | /* Check whether a key is usable. We cannot reuse an allocated key if | |
132 | the sequence counter would overflow after the next destroy call. | |
133 | This would mean that we potentially free memory for a key with the | |
134 | same sequence. This is *very* unlikely to happen, A program would | |
135 | have to create and destroy a key 2^31 times (on 32-bit platforms, | |
136 | on 64-bit platforms that would be 2^63). If it should happen we | |
137 | simply don't use this specific key anymore. */ | |
138 | #define KEY_USABLE(p) (((uintptr_t) (p)) < ((uintptr_t) ((p) + 2))) | |
139 | ||
140 | ||
141 | /* Handling of read-write lock data. */ | |
142 | // XXX For now there is only one flag. Maybe more in future. | |
143 | #define RWLOCK_RECURSIVE(rwlock) ((rwlock)->__data.__flags != 0) | |
144 | ||
145 | ||
146 | /* Semaphore variable structure. */ | |
3d2dd6ca | 147 | struct new_sem |
76a50749 | 148 | { |
042e1521 | 149 | #if __HAVE_64B_ATOMICS |
0555c477 | 150 | /* The data field holds both value (in the least-significant 32 bits) and |
042e1521 CD |
151 | nwaiters. */ |
152 | # if __BYTE_ORDER == __LITTLE_ENDIAN | |
153 | # define SEM_VALUE_OFFSET 0 | |
154 | # elif __BYTE_ORDER == __BIG_ENDIAN | |
155 | # define SEM_VALUE_OFFSET 1 | |
156 | # else | |
157 | # error Unsupported byte order. | |
158 | # endif | |
159 | # define SEM_NWAITERS_SHIFT 32 | |
160 | # define SEM_VALUE_MASK (~(unsigned int)0) | |
22971c35 | 161 | uint64_t data; |
042e1521 CD |
162 | int private; |
163 | int pad; | |
164 | #else | |
165 | # define SEM_VALUE_SHIFT 1 | |
166 | # define SEM_NWAITERS_MASK ((unsigned int)1) | |
3d2dd6ca UD |
167 | unsigned int value; |
168 | int private; | |
042e1521 CD |
169 | int pad; |
170 | unsigned int nwaiters; | |
171 | #endif | |
3d2dd6ca UD |
172 | }; |
173 | ||
174 | struct old_sem | |
175 | { | |
176 | unsigned int value; | |
76a50749 UD |
177 | }; |
178 | ||
73e9ae88 UD |
179 | |
180 | /* Compatibility type for old conditional variable interfaces. */ | |
181 | typedef struct | |
182 | { | |
183 | pthread_cond_t *cond; | |
184 | } pthread_cond_2_0_t; | |
185 | ||
76a50749 | 186 | #endif /* internaltypes.h */ |