]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 2002-2019 Free Software Foundation, Inc. |
76a50749 UD |
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 | |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
76a50749 UD |
17 | |
18 | #ifndef _PTHREAD_H | |
19 | #define _PTHREAD_H 1 | |
20 | ||
21 | #include <features.h> | |
22 | #include <sched.h> | |
23 | #include <time.h> | |
24 | ||
aa706e13 | 25 | #include <bits/endian.h> |
76a50749 | 26 | #include <bits/pthreadtypes.h> |
09d65ff3 | 27 | #include <bits/setjmp.h> |
31f93b3b | 28 | #include <bits/wordsize.h> |
05b68e14 | 29 | #include <bits/types/struct_timespec.h> |
76a50749 UD |
30 | |
31 | ||
32 | /* Detach state. */ | |
33 | enum | |
34 | { | |
35 | PTHREAD_CREATE_JOINABLE, | |
36 | #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE | |
37 | PTHREAD_CREATE_DETACHED | |
38 | #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED | |
39 | }; | |
40 | ||
41 | ||
a1ea4c06 | 42 | /* Mutex types. */ |
76a50749 UD |
43 | enum |
44 | { | |
45 | PTHREAD_MUTEX_TIMED_NP, | |
46 | PTHREAD_MUTEX_RECURSIVE_NP, | |
47 | PTHREAD_MUTEX_ERRORCHECK_NP, | |
48 | PTHREAD_MUTEX_ADAPTIVE_NP | |
d3c7e686 | 49 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K8 |
76a50749 UD |
50 | , |
51 | PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP, | |
52 | PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP, | |
53 | PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP, | |
54 | PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL | |
55 | #endif | |
56 | #ifdef __USE_GNU | |
57 | /* For compatibility. */ | |
58 | , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP | |
59 | #endif | |
60 | }; | |
61 | ||
1bcfb5a5 | 62 | |
77db439e | 63 | #ifdef __USE_XOPEN2K |
1bcfb5a5 UD |
64 | /* Robust mutex or not flags. */ |
65 | enum | |
66 | { | |
77db439e UD |
67 | PTHREAD_MUTEX_STALLED, |
68 | PTHREAD_MUTEX_STALLED_NP = PTHREAD_MUTEX_STALLED, | |
1f04d005 | 69 | PTHREAD_MUTEX_ROBUST, |
77db439e | 70 | PTHREAD_MUTEX_ROBUST_NP = PTHREAD_MUTEX_ROBUST |
1bcfb5a5 UD |
71 | }; |
72 | #endif | |
73 | ||
74 | ||
4efeffc1 | 75 | #if defined __USE_POSIX199506 || defined __USE_UNIX98 |
a5f2bd86 RM |
76 | /* Mutex protocols. */ |
77 | enum | |
78 | { | |
79 | PTHREAD_PRIO_NONE, | |
80 | PTHREAD_PRIO_INHERIT, | |
81 | PTHREAD_PRIO_PROTECT | |
82 | }; | |
83 | #endif | |
84 | ||
85 | ||
06be6368 | 86 | #if __PTHREAD_MUTEX_HAVE_PREV |
1bcfb5a5 | 87 | # define PTHREAD_MUTEX_INITIALIZER \ |
b023e4ca | 88 | { { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } } |
1bcfb5a5 | 89 | # ifdef __USE_GNU |
31f93b3b | 90 | # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ |
b023e4ca | 91 | { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, __PTHREAD_SPINS, { 0, 0 } } } |
31f93b3b | 92 | # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ |
b023e4ca | 93 | { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, __PTHREAD_SPINS, { 0, 0 } } } |
31f93b3b | 94 | # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \ |
b023e4ca | 95 | { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __PTHREAD_SPINS, { 0, 0 } } } |
b023e4ca | 96 | |
1bcfb5a5 UD |
97 | # endif |
98 | #else | |
99 | # define PTHREAD_MUTEX_INITIALIZER \ | |
b023e4ca | 100 | { { 0, 0, 0, 0, 0, { __PTHREAD_SPINS } } } |
1bcfb5a5 | 101 | # ifdef __USE_GNU |
31f93b3b | 102 | # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ |
b023e4ca | 103 | { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { __PTHREAD_SPINS } } } |
31f93b3b | 104 | # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ |
b023e4ca | 105 | { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { __PTHREAD_SPINS } } } |
31f93b3b | 106 | # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \ |
b023e4ca AK |
107 | { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { __PTHREAD_SPINS } } } |
108 | ||
31f93b3b | 109 | # endif |
a1ea4c06 UD |
110 | #endif |
111 | ||
76a50749 UD |
112 | |
113 | /* Read-write lock types. */ | |
20f8e666 | 114 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K |
76a50749 UD |
115 | enum |
116 | { | |
117 | PTHREAD_RWLOCK_PREFER_READER_NP, | |
118 | PTHREAD_RWLOCK_PREFER_WRITER_NP, | |
119 | PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, | |
120 | PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP | |
121 | }; | |
76a50749 | 122 | |
245a11d7 L |
123 | /* Define __PTHREAD_RWLOCK_INT_FLAGS_SHARED to 1 if pthread_rwlock_t |
124 | has the shared field. All 64-bit architectures have the shared field | |
125 | in pthread_rwlock_t. */ | |
126 | #ifndef __PTHREAD_RWLOCK_INT_FLAGS_SHARED | |
127 | # if __WORDSIZE == 64 | |
128 | # define __PTHREAD_RWLOCK_INT_FLAGS_SHARED 1 | |
129 | # endif | |
130 | #endif | |
131 | ||
a1ea4c06 | 132 | /* Read-write lock initializers. */ |
e59660bc | 133 | # define PTHREAD_RWLOCK_INITIALIZER \ |
8491ed6d | 134 | { { 0, 0, 0, 0, 0, 0, 0, 0, __PTHREAD_RWLOCK_ELISION_EXTRA, 0, 0 } } |
20f8e666 | 135 | # ifdef __USE_GNU |
245a11d7 | 136 | # ifdef __PTHREAD_RWLOCK_INT_FLAGS_SHARED |
20f8e666 | 137 | # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ |
8491ed6d | 138 | { { 0, 0, 0, 0, 0, 0, 0, 0, __PTHREAD_RWLOCK_ELISION_EXTRA, 0, \ |
5a337776 | 139 | PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } } |
20f8e666 | 140 | # else |
e59660bc UD |
141 | # if __BYTE_ORDER == __LITTLE_ENDIAN |
142 | # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ | |
143 | { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, \ | |
8491ed6d | 144 | 0, __PTHREAD_RWLOCK_ELISION_EXTRA, 0, 0 } } |
e59660bc UD |
145 | # else |
146 | # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ | |
147 | { { 0, 0, 0, 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,\ | |
148 | 0 } } | |
149 | # endif | |
20f8e666 | 150 | # endif |
31f93b3b | 151 | # endif |
20f8e666 | 152 | #endif /* Unix98 or XOpen2K */ |
a1ea4c06 | 153 | |
76a50749 UD |
154 | |
155 | /* Scheduler inheritance. */ | |
156 | enum | |
157 | { | |
158 | PTHREAD_INHERIT_SCHED, | |
159 | #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED | |
160 | PTHREAD_EXPLICIT_SCHED | |
161 | #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED | |
162 | }; | |
163 | ||
164 | ||
165 | /* Scope handling. */ | |
166 | enum | |
167 | { | |
168 | PTHREAD_SCOPE_SYSTEM, | |
169 | #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM | |
170 | PTHREAD_SCOPE_PROCESS | |
171 | #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS | |
172 | }; | |
173 | ||
174 | ||
175 | /* Process shared or private flag. */ | |
176 | enum | |
177 | { | |
178 | PTHREAD_PROCESS_PRIVATE, | |
179 | #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE | |
180 | PTHREAD_PROCESS_SHARED | |
181 | #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED | |
182 | }; | |
183 | ||
184 | ||
185 | ||
186 | /* Conditional variable handling. */ | |
ed19993b | 187 | #define PTHREAD_COND_INITIALIZER { { {0}, {0}, {0, 0}, {0, 0}, 0, 0, {0, 0} } } |
76a50749 UD |
188 | |
189 | ||
190 | /* Cleanup buffers */ | |
191 | struct _pthread_cleanup_buffer | |
192 | { | |
193 | void (*__routine) (void *); /* Function to call. */ | |
194 | void *__arg; /* Its argument. */ | |
195 | int __canceltype; /* Saved cancellation type. */ | |
196 | struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */ | |
197 | }; | |
198 | ||
199 | /* Cancellation */ | |
200 | enum | |
201 | { | |
202 | PTHREAD_CANCEL_ENABLE, | |
203 | #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE | |
204 | PTHREAD_CANCEL_DISABLE | |
205 | #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE | |
206 | }; | |
207 | enum | |
208 | { | |
209 | PTHREAD_CANCEL_DEFERRED, | |
210 | #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED | |
211 | PTHREAD_CANCEL_ASYNCHRONOUS | |
212 | #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS | |
213 | }; | |
214 | #define PTHREAD_CANCELED ((void *) -1) | |
215 | ||
216 | ||
217 | /* Single execution handling. */ | |
218 | #define PTHREAD_ONCE_INIT 0 | |
219 | ||
220 | ||
221 | #ifdef __USE_XOPEN2K | |
222 | /* Value returned by 'pthread_barrier_wait' for one of the threads after | |
223 | the required number of threads have called this function. | |
224 | -1 is distinct from 0 and all errno constants */ | |
225 | # define PTHREAD_BARRIER_SERIAL_THREAD -1 | |
226 | #endif | |
227 | ||
228 | ||
229 | __BEGIN_DECLS | |
230 | ||
231 | /* Create a new thread, starting with execution of START-ROUTINE | |
232 | getting passed ARG. Creation attributed come from ATTR. The new | |
233 | handle is stored in *NEWTHREAD. */ | |
234 | extern int pthread_create (pthread_t *__restrict __newthread, | |
a784e502 | 235 | const pthread_attr_t *__restrict __attr, |
76a50749 | 236 | void *(*__start_routine) (void *), |
3871f58f | 237 | void *__restrict __arg) __THROWNL __nonnull ((1, 3)); |
76a50749 | 238 | |
68b9e1ae UD |
239 | /* Terminate calling thread. |
240 | ||
241 | The registered cleanup handlers are called via exception handling | |
242 | so we cannot mark this function with __THROW.*/ | |
243 | extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__)); | |
76a50749 UD |
244 | |
245 | /* Make calling thread wait for termination of the thread TH. The | |
246 | exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN | |
4e648ea3 UD |
247 | is not NULL. |
248 | ||
249 | This function is a cancellation point and therefore not marked with | |
250 | __THROW. */ | |
251 | extern int pthread_join (pthread_t __th, void **__thread_return); | |
76a50749 UD |
252 | |
253 | #ifdef __USE_GNU | |
254 | /* Check whether thread TH has terminated. If yes return the status of | |
255 | the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */ | |
256 | extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW; | |
257 | ||
258 | /* Make calling thread wait for termination of the thread TH, but only | |
259 | until TIMEOUT. The exit status of the thread is stored in | |
4e648ea3 UD |
260 | *THREAD_RETURN, if THREAD_RETURN is not NULL. |
261 | ||
262 | This function is a cancellation point and therefore not marked with | |
263 | __THROW. */ | |
76a50749 | 264 | extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return, |
a784e502 | 265 | const struct timespec *__abstime); |
69ca4b54 MC |
266 | |
267 | /* Make calling thread wait for termination of the thread TH, but only | |
268 | until TIMEOUT measured against the clock specified by CLOCKID. The | |
269 | exit status of the thread is stored in *THREAD_RETURN, if | |
270 | THREAD_RETURN is not NULL. | |
271 | ||
272 | This function is a cancellation point and therefore not marked with | |
273 | __THROW. */ | |
274 | extern int pthread_clockjoin_np (pthread_t __th, void **__thread_return, | |
275 | clockid_t clockid, | |
276 | const struct timespec *__abstime); | |
76a50749 UD |
277 | #endif |
278 | ||
279 | /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN. | |
280 | The resources of TH will therefore be freed immediately when it | |
281 | terminates, instead of waiting for another thread to perform PTHREAD_JOIN | |
282 | on it. */ | |
283 | extern int pthread_detach (pthread_t __th) __THROW; | |
284 | ||
285 | ||
286 | /* Obtain the identifier of the current thread. */ | |
287 | extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__)); | |
288 | ||
289 | /* Compare two thread identifiers. */ | |
8898f020 UD |
290 | extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) |
291 | __THROW __attribute__ ((__const__)); | |
76a50749 UD |
292 | |
293 | ||
294 | /* Thread attribute handling. */ | |
295 | ||
296 | /* Initialize thread attribute *ATTR with default attributes | |
297 | (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER, | |
298 | no user-provided stack). */ | |
feb37183 | 299 | extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1)); |
76a50749 UD |
300 | |
301 | /* Destroy thread attribute *ATTR. */ | |
feb37183 UD |
302 | extern int pthread_attr_destroy (pthread_attr_t *__attr) |
303 | __THROW __nonnull ((1)); | |
76a50749 UD |
304 | |
305 | /* Get detach state attribute. */ | |
a784e502 | 306 | extern int pthread_attr_getdetachstate (const pthread_attr_t *__attr, |
feb37183 UD |
307 | int *__detachstate) |
308 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
309 | |
310 | /* Set detach state attribute. */ | |
311 | extern int pthread_attr_setdetachstate (pthread_attr_t *__attr, | |
feb37183 UD |
312 | int __detachstate) |
313 | __THROW __nonnull ((1)); | |
76a50749 UD |
314 | |
315 | ||
316 | /* Get the size of the guard area created for stack overflow protection. */ | |
a784e502 | 317 | extern int pthread_attr_getguardsize (const pthread_attr_t *__attr, |
feb37183 UD |
318 | size_t *__guardsize) |
319 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
320 | |
321 | /* Set the size of the guard area created for stack overflow protection. */ | |
322 | extern int pthread_attr_setguardsize (pthread_attr_t *__attr, | |
feb37183 UD |
323 | size_t __guardsize) |
324 | __THROW __nonnull ((1)); | |
76a50749 UD |
325 | |
326 | ||
327 | /* Return in *PARAM the scheduling parameters of *ATTR. */ | |
a784e502 | 328 | extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict __attr, |
76a50749 | 329 | struct sched_param *__restrict __param) |
feb37183 | 330 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
331 | |
332 | /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */ | |
333 | extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr, | |
a784e502 | 334 | const struct sched_param *__restrict |
feb37183 | 335 | __param) __THROW __nonnull ((1, 2)); |
76a50749 UD |
336 | |
337 | /* Return in *POLICY the scheduling policy of *ATTR. */ | |
a784e502 | 338 | extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict |
76a50749 | 339 | __attr, int *__restrict __policy) |
feb37183 | 340 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
341 | |
342 | /* Set scheduling policy in *ATTR according to POLICY. */ | |
343 | extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy) | |
feb37183 | 344 | __THROW __nonnull ((1)); |
76a50749 UD |
345 | |
346 | /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */ | |
a784e502 | 347 | extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict |
76a50749 | 348 | __attr, int *__restrict __inherit) |
feb37183 | 349 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
350 | |
351 | /* Set scheduling inheritance mode in *ATTR according to INHERIT. */ | |
352 | extern int pthread_attr_setinheritsched (pthread_attr_t *__attr, | |
feb37183 UD |
353 | int __inherit) |
354 | __THROW __nonnull ((1)); | |
76a50749 UD |
355 | |
356 | ||
357 | /* Return in *SCOPE the scheduling contention scope of *ATTR. */ | |
a784e502 | 358 | extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr, |
feb37183 UD |
359 | int *__restrict __scope) |
360 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
361 | |
362 | /* Set scheduling contention scope in *ATTR according to SCOPE. */ | |
363 | extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope) | |
feb37183 | 364 | __THROW __nonnull ((1)); |
76a50749 UD |
365 | |
366 | /* Return the previously set address for the stack. */ | |
a784e502 | 367 | extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict |
76a50749 | 368 | __attr, void **__restrict __stackaddr) |
feb37183 | 369 | __THROW __nonnull ((1, 2)) __attribute_deprecated__; |
76a50749 UD |
370 | |
371 | /* Set the starting address of the stack of the thread to be created. | |
372 | Depending on whether the stack grows up or down the value must either | |
373 | be higher or lower than all the address in the memory block. The | |
973d66e4 | 374 | minimal size of the block must be PTHREAD_STACK_MIN. */ |
76a50749 | 375 | extern int pthread_attr_setstackaddr (pthread_attr_t *__attr, |
3b7ed871 | 376 | void *__stackaddr) |
feb37183 | 377 | __THROW __nonnull ((1)) __attribute_deprecated__; |
76a50749 UD |
378 | |
379 | /* Return the currently used minimal stack size. */ | |
a784e502 | 380 | extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict |
76a50749 | 381 | __attr, size_t *__restrict __stacksize) |
feb37183 | 382 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
383 | |
384 | /* Add information about the minimum stack size needed for the thread | |
973d66e4 | 385 | to be started. This size must never be less than PTHREAD_STACK_MIN |
76a50749 UD |
386 | and must also not exceed the system limits. */ |
387 | extern int pthread_attr_setstacksize (pthread_attr_t *__attr, | |
feb37183 UD |
388 | size_t __stacksize) |
389 | __THROW __nonnull ((1)); | |
76a50749 UD |
390 | |
391 | #ifdef __USE_XOPEN2K | |
392 | /* Return the previously set address for the stack. */ | |
a784e502 | 393 | extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr, |
76a50749 | 394 | void **__restrict __stackaddr, |
feb37183 UD |
395 | size_t *__restrict __stacksize) |
396 | __THROW __nonnull ((1, 2, 3)); | |
76a50749 UD |
397 | |
398 | /* The following two interfaces are intended to replace the last two. They | |
399 | require setting the address as well as the size since only setting the | |
400 | address will make the implementation on some architectures impossible. */ | |
401 | extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr, | |
feb37183 | 402 | size_t __stacksize) __THROW __nonnull ((1)); |
76a50749 UD |
403 | #endif |
404 | ||
405 | #ifdef __USE_GNU | |
80f536db UD |
406 | /* Thread created with attribute ATTR will be limited to run only on |
407 | the processors represented in CPUSET. */ | |
408 | extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr, | |
439ff07b | 409 | size_t __cpusetsize, |
a784e502 | 410 | const cpu_set_t *__cpuset) |
feb37183 | 411 | __THROW __nonnull ((1, 3)); |
80f536db UD |
412 | |
413 | /* Get bit set in CPUSET representing the processors threads created with | |
414 | ATTR can run on. */ | |
a784e502 | 415 | extern int pthread_attr_getaffinity_np (const pthread_attr_t *__attr, |
439ff07b | 416 | size_t __cpusetsize, |
feb37183 UD |
417 | cpu_set_t *__cpuset) |
418 | __THROW __nonnull ((1, 3)); | |
80f536db | 419 | |
61dd6208 SP |
420 | /* Get the default attributes used by pthread_create in this process. */ |
421 | extern int pthread_getattr_default_np (pthread_attr_t *__attr) | |
422 | __THROW __nonnull ((1)); | |
423 | ||
424 | /* Set the default attributes to be used by pthread_create in this | |
425 | process. */ | |
426 | extern int pthread_setattr_default_np (const pthread_attr_t *__attr) | |
427 | __THROW __nonnull ((1)); | |
80f536db | 428 | |
9ba96eda | 429 | /* Initialize thread attribute *ATTR with attributes corresponding to the |
e4d6e7f5 | 430 | already running thread TH. It shall be called on uninitialized ATTR |
9ba96eda | 431 | and destroyed with pthread_attr_destroy when no longer needed. */ |
feb37183 UD |
432 | extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) |
433 | __THROW __nonnull ((2)); | |
76a50749 UD |
434 | #endif |
435 | ||
436 | ||
437 | /* Functions for scheduling control. */ | |
438 | ||
439 | /* Set the scheduling parameters for TARGET_THREAD according to POLICY | |
440 | and *PARAM. */ | |
441 | extern int pthread_setschedparam (pthread_t __target_thread, int __policy, | |
a784e502 | 442 | const struct sched_param *__param) |
feb37183 | 443 | __THROW __nonnull ((3)); |
76a50749 UD |
444 | |
445 | /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */ | |
446 | extern int pthread_getschedparam (pthread_t __target_thread, | |
447 | int *__restrict __policy, | |
448 | struct sched_param *__restrict __param) | |
feb37183 | 449 | __THROW __nonnull ((2, 3)); |
76a50749 | 450 | |
f1f2cafc UD |
451 | /* Set the scheduling priority for TARGET_THREAD. */ |
452 | extern int pthread_setschedprio (pthread_t __target_thread, int __prio) | |
453 | __THROW; | |
454 | ||
76a50749 | 455 | |
86a4c67f UD |
456 | #ifdef __USE_GNU |
457 | /* Get thread name visible in the kernel and its interfaces. */ | |
458 | extern int pthread_getname_np (pthread_t __target_thread, char *__buf, | |
459 | size_t __buflen) | |
460 | __THROW __nonnull ((2)); | |
461 | ||
462 | /* Set thread name visible in the kernel and its interfaces. */ | |
a784e502 | 463 | extern int pthread_setname_np (pthread_t __target_thread, const char *__name) |
86a4c67f UD |
464 | __THROW __nonnull ((2)); |
465 | #endif | |
466 | ||
467 | ||
76a50749 UD |
468 | #ifdef __USE_UNIX98 |
469 | /* Determine level of concurrency. */ | |
470 | extern int pthread_getconcurrency (void) __THROW; | |
471 | ||
472 | /* Set new concurrency level to LEVEL. */ | |
473 | extern int pthread_setconcurrency (int __level) __THROW; | |
474 | #endif | |
475 | ||
476 | #ifdef __USE_GNU | |
477 | /* Yield the processor to another thread or process. | |
478 | This function is similar to the POSIX `sched_yield' function but | |
479 | might be differently implemented in the case of a m-on-n thread | |
480 | implementation. */ | |
481 | extern int pthread_yield (void) __THROW; | |
949ec764 UD |
482 | |
483 | ||
484 | /* Limit specified thread TH to run only on the processors represented | |
485 | in CPUSET. */ | |
439ff07b | 486 | extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize, |
a784e502 | 487 | const cpu_set_t *__cpuset) |
feb37183 | 488 | __THROW __nonnull ((3)); |
949ec764 UD |
489 | |
490 | /* Get bit set in CPUSET representing the processors TH can run on. */ | |
439ff07b | 491 | extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize, |
feb37183 UD |
492 | cpu_set_t *__cpuset) |
493 | __THROW __nonnull ((3)); | |
76a50749 UD |
494 | #endif |
495 | ||
496 | ||
497 | /* Functions for handling initialization. */ | |
498 | ||
499 | /* Guarantee that the initialization function INIT_ROUTINE will be called | |
500 | only once, even if pthread_once is executed several times with the | |
501 | same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or | |
e0329987 UD |
502 | extern variable initialized to PTHREAD_ONCE_INIT. |
503 | ||
504 | The initialization functions might throw exception which is why | |
505 | this function is not marked with __THROW. */ | |
76a50749 | 506 | extern int pthread_once (pthread_once_t *__once_control, |
feb37183 | 507 | void (*__init_routine) (void)) __nonnull ((1, 2)); |
76a50749 UD |
508 | |
509 | ||
2c008571 UD |
510 | /* Functions for handling cancellation. |
511 | ||
512 | Note that these functions are explicitly not marked to not throw an | |
513 | exception in C++ code. If cancellation is implemented by unwinding | |
514 | this is necessary to have the compiler generate the unwind information. */ | |
76a50749 UD |
515 | |
516 | /* Set cancelability state of current thread to STATE, returning old | |
517 | state in *OLDSTATE if OLDSTATE is not NULL. */ | |
76a67697 | 518 | extern int pthread_setcancelstate (int __state, int *__oldstate); |
76a50749 UD |
519 | |
520 | /* Set cancellation state of current thread to TYPE, returning the old | |
521 | type in *OLDTYPE if OLDTYPE is not NULL. */ | |
76a67697 | 522 | extern int pthread_setcanceltype (int __type, int *__oldtype); |
76a50749 UD |
523 | |
524 | /* Cancel THREAD immediately or at the next possibility. */ | |
76a67697 | 525 | extern int pthread_cancel (pthread_t __th); |
76a50749 UD |
526 | |
527 | /* Test for pending cancellation for the current thread and terminate | |
528 | the thread as per pthread_exit(PTHREAD_CANCELED) if it has been | |
2c008571 | 529 | cancelled. */ |
7d74651e | 530 | extern void pthread_testcancel (void); |
76a50749 UD |
531 | |
532 | ||
09d65ff3 UD |
533 | /* Cancellation handling with integration into exception handling. */ |
534 | ||
535 | typedef struct | |
536 | { | |
2ec0e7ea CD |
537 | struct |
538 | { | |
539 | __jmp_buf __cancel_jmp_buf; | |
540 | int __mask_was_saved; | |
541 | } __cancel_jmp_buf[1]; | |
68107ec0 | 542 | void *__pad[4]; |
09d65ff3 UD |
543 | } __pthread_unwind_buf_t __attribute__ ((__aligned__)); |
544 | ||
545 | /* No special attributes by default. */ | |
546 | #ifndef __cleanup_fct_attribute | |
547 | # define __cleanup_fct_attribute | |
548 | #endif | |
549 | ||
550 | ||
7726edc2 UD |
551 | /* Structure to hold the cleanup handler information. */ |
552 | struct __pthread_cleanup_frame | |
553 | { | |
554 | void (*__cancel_routine) (void *); | |
555 | void *__cancel_arg; | |
556 | int __do_it; | |
557 | int __cancel_type; | |
558 | }; | |
559 | ||
560 | #if defined __GNUC__ && defined __EXCEPTIONS | |
561 | # ifdef __cplusplus | |
562 | /* Class to handle cancellation handler invocation. */ | |
563 | class __pthread_cleanup_class | |
564 | { | |
565 | void (*__cancel_routine) (void *); | |
566 | void *__cancel_arg; | |
567 | int __do_it; | |
568 | int __cancel_type; | |
569 | ||
570 | public: | |
571 | __pthread_cleanup_class (void (*__fct) (void *), void *__arg) | |
572 | : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { } | |
573 | ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); } | |
68b9e1ae UD |
574 | void __setdoit (int __newval) { __do_it = __newval; } |
575 | void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, | |
576 | &__cancel_type); } | |
577 | void __restore () const { pthread_setcanceltype (__cancel_type, 0); } | |
7726edc2 UD |
578 | }; |
579 | ||
580 | /* Install a cleanup handler: ROUTINE will be called with arguments ARG | |
581 | when the thread is canceled or calls pthread_exit. ROUTINE will also | |
582 | be called with arguments ARG when the matching pthread_cleanup_pop | |
583 | is executed with non-zero EXECUTE argument. | |
584 | ||
585 | pthread_cleanup_push and pthread_cleanup_pop are macros and must always | |
586 | be used in matching pairs at the same nesting level of braces. */ | |
587 | # define pthread_cleanup_push(routine, arg) \ | |
588 | do { \ | |
589 | __pthread_cleanup_class __clframe (routine, arg) | |
590 | ||
591 | /* Remove a cleanup handler installed by the matching pthread_cleanup_push. | |
592 | If EXECUTE is non-zero, the handler function is called. */ | |
593 | # define pthread_cleanup_pop(execute) \ | |
594 | __clframe.__setdoit (execute); \ | |
595 | } while (0) | |
596 | ||
597 | # ifdef __USE_GNU | |
598 | /* Install a cleanup handler as pthread_cleanup_push does, but also | |
599 | saves the current cancellation type and sets it to deferred | |
600 | cancellation. */ | |
601 | # define pthread_cleanup_push_defer_np(routine, arg) \ | |
602 | do { \ | |
603 | __pthread_cleanup_class __clframe (routine, arg); \ | |
604 | __clframe.__defer () | |
605 | ||
606 | /* Remove a cleanup handler as pthread_cleanup_pop does, but also | |
607 | restores the cancellation type that was in effect when the matching | |
608 | pthread_cleanup_push_defer was called. */ | |
609 | # define pthread_cleanup_pop_restore_np(execute) \ | |
610 | __clframe.__restore (); \ | |
611 | __clframe.__setdoit (execute); \ | |
612 | } while (0) | |
613 | # endif | |
614 | # else | |
615 | /* Function called to call the cleanup handler. As an extern inline | |
616 | function the compiler is free to decide inlining the change when | |
617 | needed or fall back on the copy which must exist somewhere | |
618 | else. */ | |
b037a293 | 619 | __extern_inline void |
7726edc2 UD |
620 | __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) |
621 | { | |
622 | if (__frame->__do_it) | |
623 | __frame->__cancel_routine (__frame->__cancel_arg); | |
624 | } | |
625 | ||
76a50749 | 626 | /* Install a cleanup handler: ROUTINE will be called with arguments ARG |
7726edc2 | 627 | when the thread is canceled or calls pthread_exit. ROUTINE will also |
76a50749 UD |
628 | be called with arguments ARG when the matching pthread_cleanup_pop |
629 | is executed with non-zero EXECUTE argument. | |
630 | ||
631 | pthread_cleanup_push and pthread_cleanup_pop are macros and must always | |
632 | be used in matching pairs at the same nesting level of braces. */ | |
7726edc2 UD |
633 | # define pthread_cleanup_push(routine, arg) \ |
634 | do { \ | |
635 | struct __pthread_cleanup_frame __clframe \ | |
636 | __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ | |
637 | = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ | |
638 | .__do_it = 1 }; | |
639 | ||
640 | /* Remove a cleanup handler installed by the matching pthread_cleanup_push. | |
641 | If EXECUTE is non-zero, the handler function is called. */ | |
642 | # define pthread_cleanup_pop(execute) \ | |
643 | __clframe.__do_it = (execute); \ | |
644 | } while (0) | |
645 | ||
646 | # ifdef __USE_GNU | |
647 | /* Install a cleanup handler as pthread_cleanup_push does, but also | |
648 | saves the current cancellation type and sets it to deferred | |
649 | cancellation. */ | |
650 | # define pthread_cleanup_push_defer_np(routine, arg) \ | |
651 | do { \ | |
652 | struct __pthread_cleanup_frame __clframe \ | |
653 | __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ | |
654 | = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ | |
655 | .__do_it = 1 }; \ | |
656 | (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \ | |
657 | &__clframe.__cancel_type) | |
658 | ||
659 | /* Remove a cleanup handler as pthread_cleanup_pop does, but also | |
660 | restores the cancellation type that was in effect when the matching | |
661 | pthread_cleanup_push_defer was called. */ | |
662 | # define pthread_cleanup_pop_restore_np(execute) \ | |
663 | (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \ | |
664 | __clframe.__do_it = (execute); \ | |
665 | } while (0) | |
666 | # endif | |
667 | # endif | |
668 | #else | |
669 | /* Install a cleanup handler: ROUTINE will be called with arguments ARG | |
670 | when the thread is canceled or calls pthread_exit. ROUTINE will also | |
671 | be called with arguments ARG when the matching pthread_cleanup_pop | |
672 | is executed with non-zero EXECUTE argument. | |
673 | ||
674 | pthread_cleanup_push and pthread_cleanup_pop are macros and must always | |
675 | be used in matching pairs at the same nesting level of braces. */ | |
676 | # define pthread_cleanup_push(routine, arg) \ | |
09d65ff3 UD |
677 | do { \ |
678 | __pthread_unwind_buf_t __cancel_buf; \ | |
679 | void (*__cancel_routine) (void *) = (routine); \ | |
680 | void *__cancel_arg = (arg); \ | |
c3758fee AS |
681 | int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ |
682 | __cancel_buf.__cancel_jmp_buf, 0); \ | |
4af3879c | 683 | if (__glibc_unlikely (__not_first_call)) \ |
09d65ff3 UD |
684 | { \ |
685 | __cancel_routine (__cancel_arg); \ | |
686 | __pthread_unwind_next (&__cancel_buf); \ | |
687 | /* NOTREACHED */ \ | |
688 | } \ | |
689 | \ | |
690 | __pthread_register_cancel (&__cancel_buf); \ | |
691 | do { | |
692 | extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf) | |
693 | __cleanup_fct_attribute; | |
76a50749 UD |
694 | |
695 | /* Remove a cleanup handler installed by the matching pthread_cleanup_push. | |
696 | If EXECUTE is non-zero, the handler function is called. */ | |
7726edc2 | 697 | # define pthread_cleanup_pop(execute) \ |
135460f4 | 698 | do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\ |
09d65ff3 UD |
699 | } while (0); \ |
700 | __pthread_unregister_cancel (&__cancel_buf); \ | |
701 | if (execute) \ | |
702 | __cancel_routine (__cancel_arg); \ | |
703 | } while (0) | |
704 | extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) | |
705 | __cleanup_fct_attribute; | |
76a50749 | 706 | |
7726edc2 | 707 | # ifdef __USE_GNU |
76a50749 UD |
708 | /* Install a cleanup handler as pthread_cleanup_push does, but also |
709 | saves the current cancellation type and sets it to deferred | |
710 | cancellation. */ | |
7726edc2 | 711 | # define pthread_cleanup_push_defer_np(routine, arg) \ |
09d65ff3 UD |
712 | do { \ |
713 | __pthread_unwind_buf_t __cancel_buf; \ | |
714 | void (*__cancel_routine) (void *) = (routine); \ | |
715 | void *__cancel_arg = (arg); \ | |
c3758fee AS |
716 | int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ |
717 | __cancel_buf.__cancel_jmp_buf, 0); \ | |
0d522f64 | 718 | if (__glibc_unlikely (__not_first_call)) \ |
09d65ff3 UD |
719 | { \ |
720 | __cancel_routine (__cancel_arg); \ | |
721 | __pthread_unwind_next (&__cancel_buf); \ | |
722 | /* NOTREACHED */ \ | |
723 | } \ | |
724 | \ | |
725 | __pthread_register_cancel_defer (&__cancel_buf); \ | |
726 | do { | |
727 | extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf) | |
728 | __cleanup_fct_attribute; | |
76a50749 UD |
729 | |
730 | /* Remove a cleanup handler as pthread_cleanup_pop does, but also | |
731 | restores the cancellation type that was in effect when the matching | |
732 | pthread_cleanup_push_defer was called. */ | |
7726edc2 | 733 | # define pthread_cleanup_pop_restore_np(execute) \ |
135460f4 | 734 | do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\ |
09d65ff3 UD |
735 | } while (0); \ |
736 | __pthread_unregister_cancel_restore (&__cancel_buf); \ | |
737 | if (execute) \ | |
738 | __cancel_routine (__cancel_arg); \ | |
739 | } while (0) | |
740 | extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf) | |
741 | __cleanup_fct_attribute; | |
7726edc2 | 742 | # endif |
76a50749 | 743 | |
09d65ff3 UD |
744 | /* Internal interface to initiate cleanup. */ |
745 | extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) | |
16feadf2 | 746 | __cleanup_fct_attribute __attribute__ ((__noreturn__)) |
7726edc2 | 747 | # ifndef SHARED |
16feadf2 | 748 | __attribute__ ((__weak__)) |
7726edc2 | 749 | # endif |
09d65ff3 | 750 | ; |
7726edc2 | 751 | #endif |
09d65ff3 UD |
752 | |
753 | /* Function used in the macros. */ | |
754 | struct __jmp_buf_tag; | |
97bc38d7 | 755 | extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL; |
76a50749 UD |
756 | |
757 | ||
758 | /* Mutex handling. */ | |
759 | ||
760 | /* Initialize a mutex. */ | |
761 | extern int pthread_mutex_init (pthread_mutex_t *__mutex, | |
a784e502 | 762 | const pthread_mutexattr_t *__mutexattr) |
feb37183 | 763 | __THROW __nonnull ((1)); |
76a50749 UD |
764 | |
765 | /* Destroy a mutex. */ | |
feb37183 UD |
766 | extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) |
767 | __THROW __nonnull ((1)); | |
76a50749 UD |
768 | |
769 | /* Try locking a mutex. */ | |
feb37183 | 770 | extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) |
3871f58f | 771 | __THROWNL __nonnull ((1)); |
76a50749 UD |
772 | |
773 | /* Lock a mutex. */ | |
feb37183 | 774 | extern int pthread_mutex_lock (pthread_mutex_t *__mutex) |
3871f58f | 775 | __THROWNL __nonnull ((1)); |
76a50749 UD |
776 | |
777 | #ifdef __USE_XOPEN2K | |
778 | /* Wait until lock becomes available, or specified time passes. */ | |
779 | extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, | |
a784e502 | 780 | const struct timespec *__restrict |
3871f58f | 781 | __abstime) __THROWNL __nonnull ((1, 2)); |
76a50749 UD |
782 | #endif |
783 | ||
9d20e22e MC |
784 | #ifdef __USE_GNU |
785 | extern int pthread_mutex_clocklock (pthread_mutex_t *__restrict __mutex, | |
786 | clockid_t __clockid, | |
787 | const struct timespec *__restrict | |
788 | __abstime) __THROWNL __nonnull ((1, 3)); | |
789 | #endif | |
790 | ||
76a50749 | 791 | /* Unlock a mutex. */ |
feb37183 | 792 | extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) |
3871f58f | 793 | __THROWNL __nonnull ((1)); |
76a50749 UD |
794 | |
795 | ||
a5f2bd86 | 796 | /* Get the priority ceiling of MUTEX. */ |
a784e502 | 797 | extern int pthread_mutex_getprioceiling (const pthread_mutex_t * |
a5f2bd86 RM |
798 | __restrict __mutex, |
799 | int *__restrict __prioceiling) | |
feb37183 | 800 | __THROW __nonnull ((1, 2)); |
a5f2bd86 RM |
801 | |
802 | /* Set the priority ceiling of MUTEX to PRIOCEILING, return old | |
803 | priority ceiling value in *OLD_CEILING. */ | |
804 | extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex, | |
805 | int __prioceiling, | |
806 | int *__restrict __old_ceiling) | |
feb37183 | 807 | __THROW __nonnull ((1, 3)); |
a5f2bd86 RM |
808 | |
809 | ||
77db439e | 810 | #ifdef __USE_XOPEN2K8 |
1bcfb5a5 | 811 | /* Declare the state protected by MUTEX as consistent. */ |
f095bb72 | 812 | extern int pthread_mutex_consistent (pthread_mutex_t *__mutex) |
feb37183 | 813 | __THROW __nonnull ((1)); |
77db439e UD |
814 | # ifdef __USE_GNU |
815 | extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex) | |
816 | __THROW __nonnull ((1)); | |
817 | # endif | |
1bcfb5a5 UD |
818 | #endif |
819 | ||
820 | ||
76a50749 UD |
821 | /* Functions for handling mutex attributes. */ |
822 | ||
823 | /* Initialize mutex attribute object ATTR with default attributes | |
824 | (kind is PTHREAD_MUTEX_TIMED_NP). */ | |
feb37183 UD |
825 | extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr) |
826 | __THROW __nonnull ((1)); | |
76a50749 UD |
827 | |
828 | /* Destroy mutex attribute object ATTR. */ | |
feb37183 UD |
829 | extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr) |
830 | __THROW __nonnull ((1)); | |
76a50749 UD |
831 | |
832 | /* Get the process-shared flag of the mutex attribute ATTR. */ | |
a784e502 | 833 | extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t * |
76a50749 | 834 | __restrict __attr, |
feb37183 UD |
835 | int *__restrict __pshared) |
836 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
837 | |
838 | /* Set the process-shared flag of the mutex attribute ATTR. */ | |
839 | extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr, | |
feb37183 UD |
840 | int __pshared) |
841 | __THROW __nonnull ((1)); | |
76a50749 | 842 | |
d3c7e686 | 843 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K8 |
76a50749 | 844 | /* Return in *KIND the mutex kind attribute in *ATTR. */ |
a784e502 | 845 | extern int pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict |
feb37183 UD |
846 | __attr, int *__restrict __kind) |
847 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
848 | |
849 | /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL, | |
850 | PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or | |
851 | PTHREAD_MUTEX_DEFAULT). */ | |
852 | extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) | |
feb37183 | 853 | __THROW __nonnull ((1)); |
d3c7e686 | 854 | #endif |
a5f2bd86 RM |
855 | |
856 | /* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */ | |
a784e502 | 857 | extern int pthread_mutexattr_getprotocol (const pthread_mutexattr_t * |
a5f2bd86 | 858 | __restrict __attr, |
feb37183 UD |
859 | int *__restrict __protocol) |
860 | __THROW __nonnull ((1, 2)); | |
a5f2bd86 RM |
861 | |
862 | /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either | |
863 | PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */ | |
864 | extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr, | |
feb37183 UD |
865 | int __protocol) |
866 | __THROW __nonnull ((1)); | |
a5f2bd86 RM |
867 | |
868 | /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */ | |
a784e502 | 869 | extern int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t * |
a5f2bd86 RM |
870 | __restrict __attr, |
871 | int *__restrict __prioceiling) | |
feb37183 | 872 | __THROW __nonnull ((1, 2)); |
a5f2bd86 RM |
873 | |
874 | /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */ | |
875 | extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr, | |
feb37183 UD |
876 | int __prioceiling) |
877 | __THROW __nonnull ((1)); | |
76a50749 | 878 | |
77db439e | 879 | #ifdef __USE_XOPEN2K |
1bcfb5a5 | 880 | /* Get the robustness flag of the mutex attribute ATTR. */ |
a784e502 | 881 | extern int pthread_mutexattr_getrobust (const pthread_mutexattr_t *__attr, |
77db439e UD |
882 | int *__robustness) |
883 | __THROW __nonnull ((1, 2)); | |
884 | # ifdef __USE_GNU | |
a784e502 | 885 | extern int pthread_mutexattr_getrobust_np (const pthread_mutexattr_t *__attr, |
feb37183 UD |
886 | int *__robustness) |
887 | __THROW __nonnull ((1, 2)); | |
77db439e | 888 | # endif |
1bcfb5a5 UD |
889 | |
890 | /* Set the robustness flag of the mutex attribute ATTR. */ | |
77db439e UD |
891 | extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr, |
892 | int __robustness) | |
893 | __THROW __nonnull ((1)); | |
894 | # ifdef __USE_GNU | |
1bcfb5a5 | 895 | extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr, |
feb37183 UD |
896 | int __robustness) |
897 | __THROW __nonnull ((1)); | |
77db439e | 898 | # endif |
1bcfb5a5 UD |
899 | #endif |
900 | ||
76a50749 | 901 | |
ccc63b07 | 902 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K |
76a50749 UD |
903 | /* Functions for handling read-write locks. */ |
904 | ||
905 | /* Initialize read-write lock RWLOCK using attributes ATTR, or use | |
906 | the default values if later is NULL. */ | |
907 | extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock, | |
a784e502 | 908 | const pthread_rwlockattr_t *__restrict |
feb37183 | 909 | __attr) __THROW __nonnull ((1)); |
76a50749 UD |
910 | |
911 | /* Destroy read-write lock RWLOCK. */ | |
feb37183 UD |
912 | extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) |
913 | __THROW __nonnull ((1)); | |
76a50749 UD |
914 | |
915 | /* Acquire read lock for RWLOCK. */ | |
feb37183 | 916 | extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) |
3871f58f | 917 | __THROWNL __nonnull ((1)); |
76a50749 UD |
918 | |
919 | /* Try to acquire read lock for RWLOCK. */ | |
feb37183 | 920 | extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) |
3871f58f | 921 | __THROWNL __nonnull ((1)); |
76a50749 UD |
922 | |
923 | # ifdef __USE_XOPEN2K | |
924 | /* Try to acquire read lock for RWLOCK or return after specfied time. */ | |
925 | extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock, | |
a784e502 | 926 | const struct timespec *__restrict |
3871f58f | 927 | __abstime) __THROWNL __nonnull ((1, 2)); |
76a50749 UD |
928 | # endif |
929 | ||
e996fa72 MC |
930 | # ifdef __USE_GNU |
931 | extern int pthread_rwlock_clockrdlock (pthread_rwlock_t *__restrict __rwlock, | |
932 | clockid_t __clockid, | |
933 | const struct timespec *__restrict | |
934 | __abstime) __THROWNL __nonnull ((1, 3)); | |
935 | # endif | |
936 | ||
76a50749 | 937 | /* Acquire write lock for RWLOCK. */ |
feb37183 | 938 | extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) |
3871f58f | 939 | __THROWNL __nonnull ((1)); |
76a50749 UD |
940 | |
941 | /* Try to acquire write lock for RWLOCK. */ | |
feb37183 | 942 | extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) |
3871f58f | 943 | __THROWNL __nonnull ((1)); |
76a50749 UD |
944 | |
945 | # ifdef __USE_XOPEN2K | |
946 | /* Try to acquire write lock for RWLOCK or return after specfied time. */ | |
947 | extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock, | |
a784e502 | 948 | const struct timespec *__restrict |
3871f58f | 949 | __abstime) __THROWNL __nonnull ((1, 2)); |
76a50749 UD |
950 | # endif |
951 | ||
e996fa72 MC |
952 | # ifdef __USE_GNU |
953 | extern int pthread_rwlock_clockwrlock (pthread_rwlock_t *__restrict __rwlock, | |
954 | clockid_t __clockid, | |
955 | const struct timespec *__restrict | |
956 | __abstime) __THROWNL __nonnull ((1, 3)); | |
957 | # endif | |
958 | ||
76a50749 | 959 | /* Unlock RWLOCK. */ |
feb37183 | 960 | extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) |
3871f58f | 961 | __THROWNL __nonnull ((1)); |
76a50749 UD |
962 | |
963 | ||
964 | /* Functions for handling read-write lock attributes. */ | |
965 | ||
966 | /* Initialize attribute object ATTR with default values. */ | |
feb37183 UD |
967 | extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr) |
968 | __THROW __nonnull ((1)); | |
76a50749 UD |
969 | |
970 | /* Destroy attribute object ATTR. */ | |
feb37183 UD |
971 | extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr) |
972 | __THROW __nonnull ((1)); | |
76a50749 UD |
973 | |
974 | /* Return current setting of process-shared attribute of ATTR in PSHARED. */ | |
a784e502 | 975 | extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * |
76a50749 | 976 | __restrict __attr, |
feb37183 UD |
977 | int *__restrict __pshared) |
978 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
979 | |
980 | /* Set process-shared attribute of ATTR to PSHARED. */ | |
981 | extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr, | |
feb37183 UD |
982 | int __pshared) |
983 | __THROW __nonnull ((1)); | |
76a50749 UD |
984 | |
985 | /* Return current setting of reader/writer preference. */ | |
a784e502 | 986 | extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t * |
76a50749 | 987 | __restrict __attr, |
feb37183 UD |
988 | int *__restrict __pref) |
989 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
990 | |
991 | /* Set reader/write preference. */ | |
992 | extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr, | |
feb37183 | 993 | int __pref) __THROW __nonnull ((1)); |
76a50749 UD |
994 | #endif |
995 | ||
996 | ||
997 | /* Functions for handling conditional variables. */ | |
998 | ||
999 | /* Initialize condition variable COND using attributes ATTR, or use | |
1000 | the default values if later is NULL. */ | |
1001 | extern int pthread_cond_init (pthread_cond_t *__restrict __cond, | |
a784e502 UD |
1002 | const pthread_condattr_t *__restrict __cond_attr) |
1003 | __THROW __nonnull ((1)); | |
76a50749 UD |
1004 | |
1005 | /* Destroy condition variable COND. */ | |
feb37183 UD |
1006 | extern int pthread_cond_destroy (pthread_cond_t *__cond) |
1007 | __THROW __nonnull ((1)); | |
76a50749 UD |
1008 | |
1009 | /* Wake up one thread waiting for condition variable COND. */ | |
feb37183 | 1010 | extern int pthread_cond_signal (pthread_cond_t *__cond) |
3871f58f | 1011 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1012 | |
1013 | /* Wake up all threads waiting for condition variables COND. */ | |
feb37183 | 1014 | extern int pthread_cond_broadcast (pthread_cond_t *__cond) |
3871f58f | 1015 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1016 | |
1017 | /* Wait for condition variable COND to be signaled or broadcast. | |
4e648ea3 UD |
1018 | MUTEX is assumed to be locked before. |
1019 | ||
1020 | This function is a cancellation point and therefore not marked with | |
1021 | __THROW. */ | |
76a50749 | 1022 | extern int pthread_cond_wait (pthread_cond_t *__restrict __cond, |
feb37183 UD |
1023 | pthread_mutex_t *__restrict __mutex) |
1024 | __nonnull ((1, 2)); | |
76a50749 UD |
1025 | |
1026 | /* Wait for condition variable COND to be signaled or broadcast until | |
1027 | ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an | |
1028 | absolute time specification; zero is the beginning of the epoch | |
4e648ea3 UD |
1029 | (00:00:00 GMT, January 1, 1970). |
1030 | ||
1031 | This function is a cancellation point and therefore not marked with | |
1032 | __THROW. */ | |
76a50749 UD |
1033 | extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond, |
1034 | pthread_mutex_t *__restrict __mutex, | |
a784e502 UD |
1035 | const struct timespec *__restrict __abstime) |
1036 | __nonnull ((1, 2, 3)); | |
76a50749 | 1037 | |
afe4de7d MC |
1038 | # ifdef __USE_GNU |
1039 | /* Wait for condition variable COND to be signaled or broadcast until | |
1040 | ABSTIME measured by the specified clock. MUTEX is assumed to be | |
1041 | locked before. CLOCK is the clock to use. ABSTIME is an absolute | |
1042 | time specification against CLOCK's epoch. | |
1043 | ||
1044 | This function is a cancellation point and therefore not marked with | |
1045 | __THROW. */ | |
1046 | extern int pthread_cond_clockwait (pthread_cond_t *__restrict __cond, | |
1047 | pthread_mutex_t *__restrict __mutex, | |
1048 | __clockid_t __clock_id, | |
1049 | const struct timespec *__restrict __abstime) | |
1050 | __nonnull ((1, 2, 4)); | |
1051 | # endif | |
1052 | ||
76a50749 UD |
1053 | /* Functions for handling condition variable attributes. */ |
1054 | ||
1055 | /* Initialize condition variable attribute ATTR. */ | |
feb37183 UD |
1056 | extern int pthread_condattr_init (pthread_condattr_t *__attr) |
1057 | __THROW __nonnull ((1)); | |
76a50749 UD |
1058 | |
1059 | /* Destroy condition variable attribute ATTR. */ | |
feb37183 UD |
1060 | extern int pthread_condattr_destroy (pthread_condattr_t *__attr) |
1061 | __THROW __nonnull ((1)); | |
76a50749 UD |
1062 | |
1063 | /* Get the process-shared flag of the condition variable attribute ATTR. */ | |
a784e502 | 1064 | extern int pthread_condattr_getpshared (const pthread_condattr_t * |
f095bb72 UD |
1065 | __restrict __attr, |
1066 | int *__restrict __pshared) | |
feb37183 | 1067 | __THROW __nonnull ((1, 2)); |
76a50749 UD |
1068 | |
1069 | /* Set the process-shared flag of the condition variable attribute ATTR. */ | |
1070 | extern int pthread_condattr_setpshared (pthread_condattr_t *__attr, | |
f095bb72 | 1071 | int __pshared) __THROW __nonnull ((1)); |
76a50749 | 1072 | |
86a9ee5e | 1073 | #ifdef __USE_XOPEN2K |
382466e0 | 1074 | /* Get the clock selected for the condition variable attribute ATTR. */ |
a784e502 | 1075 | extern int pthread_condattr_getclock (const pthread_condattr_t * |
86a9ee5e UD |
1076 | __restrict __attr, |
1077 | __clockid_t *__restrict __clock_id) | |
feb37183 | 1078 | __THROW __nonnull ((1, 2)); |
86a9ee5e | 1079 | |
382466e0 | 1080 | /* Set the clock selected for the condition variable attribute ATTR. */ |
86a9ee5e | 1081 | extern int pthread_condattr_setclock (pthread_condattr_t *__attr, |
feb37183 UD |
1082 | __clockid_t __clock_id) |
1083 | __THROW __nonnull ((1)); | |
86a9ee5e | 1084 | #endif |
76a50749 UD |
1085 | |
1086 | ||
1087 | #ifdef __USE_XOPEN2K | |
1088 | /* Functions to handle spinlocks. */ | |
1089 | ||
1090 | /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can | |
1091 | be shared between different processes. */ | |
1092 | extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) | |
feb37183 | 1093 | __THROW __nonnull ((1)); |
76a50749 UD |
1094 | |
1095 | /* Destroy the spinlock LOCK. */ | |
feb37183 UD |
1096 | extern int pthread_spin_destroy (pthread_spinlock_t *__lock) |
1097 | __THROW __nonnull ((1)); | |
76a50749 UD |
1098 | |
1099 | /* Wait until spinlock LOCK is retrieved. */ | |
feb37183 | 1100 | extern int pthread_spin_lock (pthread_spinlock_t *__lock) |
3871f58f | 1101 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1102 | |
1103 | /* Try to lock spinlock LOCK. */ | |
feb37183 | 1104 | extern int pthread_spin_trylock (pthread_spinlock_t *__lock) |
3871f58f | 1105 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1106 | |
1107 | /* Release spinlock LOCK. */ | |
feb37183 | 1108 | extern int pthread_spin_unlock (pthread_spinlock_t *__lock) |
3871f58f | 1109 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1110 | |
1111 | ||
1112 | /* Functions to handle barriers. */ | |
1113 | ||
1114 | /* Initialize BARRIER with the attributes in ATTR. The barrier is | |
1115 | opened when COUNT waiters arrived. */ | |
1116 | extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier, | |
a784e502 | 1117 | const pthread_barrierattr_t *__restrict |
feb37183 UD |
1118 | __attr, unsigned int __count) |
1119 | __THROW __nonnull ((1)); | |
76a50749 UD |
1120 | |
1121 | /* Destroy a previously dynamically initialized barrier BARRIER. */ | |
feb37183 UD |
1122 | extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) |
1123 | __THROW __nonnull ((1)); | |
76a50749 UD |
1124 | |
1125 | /* Wait on barrier BARRIER. */ | |
feb37183 | 1126 | extern int pthread_barrier_wait (pthread_barrier_t *__barrier) |
3871f58f | 1127 | __THROWNL __nonnull ((1)); |
76a50749 UD |
1128 | |
1129 | ||
1130 | /* Initialize barrier attribute ATTR. */ | |
feb37183 UD |
1131 | extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr) |
1132 | __THROW __nonnull ((1)); | |
76a50749 UD |
1133 | |
1134 | /* Destroy previously dynamically initialized barrier attribute ATTR. */ | |
feb37183 UD |
1135 | extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr) |
1136 | __THROW __nonnull ((1)); | |
76a50749 UD |
1137 | |
1138 | /* Get the process-shared flag of the barrier attribute ATTR. */ | |
a784e502 | 1139 | extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t * |
76a50749 | 1140 | __restrict __attr, |
feb37183 UD |
1141 | int *__restrict __pshared) |
1142 | __THROW __nonnull ((1, 2)); | |
76a50749 UD |
1143 | |
1144 | /* Set the process-shared flag of the barrier attribute ATTR. */ | |
1145 | extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr, | |
f095bb72 | 1146 | int __pshared) |
feb37183 | 1147 | __THROW __nonnull ((1)); |
76a50749 UD |
1148 | #endif |
1149 | ||
1150 | ||
1151 | /* Functions for handling thread-specific data. */ | |
1152 | ||
1153 | /* Create a key value identifying a location in the thread-specific | |
1154 | data area. Each thread maintains a distinct thread-specific data | |
1155 | area. DESTR_FUNCTION, if non-NULL, is called with the value | |
1156 | associated to that key when the key is destroyed. | |
1157 | DESTR_FUNCTION is not called if the value associated is NULL when | |
1158 | the key is destroyed. */ | |
1159 | extern int pthread_key_create (pthread_key_t *__key, | |
feb37183 UD |
1160 | void (*__destr_function) (void *)) |
1161 | __THROW __nonnull ((1)); | |
76a50749 UD |
1162 | |
1163 | /* Destroy KEY. */ | |
1164 | extern int pthread_key_delete (pthread_key_t __key) __THROW; | |
1165 | ||
1166 | /* Return current value of the thread-specific data slot identified by KEY. */ | |
1167 | extern void *pthread_getspecific (pthread_key_t __key) __THROW; | |
1168 | ||
1169 | /* Store POINTER in the thread-specific data slot identified by KEY. */ | |
1170 | extern int pthread_setspecific (pthread_key_t __key, | |
a784e502 | 1171 | const void *__pointer) __THROW ; |
76a50749 UD |
1172 | |
1173 | ||
76a50749 UD |
1174 | #ifdef __USE_XOPEN2K |
1175 | /* Get ID of CPU-time clock for thread THREAD_ID. */ | |
1176 | extern int pthread_getcpuclockid (pthread_t __thread_id, | |
feb37183 UD |
1177 | __clockid_t *__clock_id) |
1178 | __THROW __nonnull ((2)); | |
76a50749 UD |
1179 | #endif |
1180 | ||
1181 | ||
1182 | /* Install handlers to be called when a new process is created with FORK. | |
1183 | The PREPARE handler is called in the parent process just before performing | |
1184 | FORK. The PARENT handler is called in the parent process just after FORK. | |
1185 | The CHILD handler is called in the child process. Each of the three | |
1186 | handlers can be NULL, meaning that no handler needs to be called at that | |
1187 | point. | |
1188 | PTHREAD_ATFORK can be called several times, in which case the PREPARE | |
1189 | handlers are called in LIFO order (last added with PTHREAD_ATFORK, | |
1190 | first called before FORK), and the PARENT and CHILD handlers are called | |
1191 | in FIFO (first added, first called). */ | |
1192 | ||
1193 | extern int pthread_atfork (void (*__prepare) (void), | |
1194 | void (*__parent) (void), | |
1195 | void (*__child) (void)) __THROW; | |
1196 | ||
c26ca5e1 UD |
1197 | |
1198 | #ifdef __USE_EXTERN_INLINES | |
1199 | /* Optimizations. */ | |
b037a293 | 1200 | __extern_inline int |
c26ca5e1 UD |
1201 | __NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2)) |
1202 | { | |
1203 | return __thread1 == __thread2; | |
1204 | } | |
1205 | #endif | |
1206 | ||
76a50749 UD |
1207 | __END_DECLS |
1208 | ||
1209 | #endif /* pthread.h */ |