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