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