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