]>
Commit | Line | Data |
---|---|---|
33574c17 | 1 | /* Posix threads. Hurd version. |
04277e02 | 2 | Copyright (C) 2000-2019 Free Software Foundation, Inc. |
33574c17 ST |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
ad2b41bf ST |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
33574c17 ST |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
ad2b41bf | 13 | Lesser General Public License for more details. |
33574c17 | 14 | |
ad2b41bf ST |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see | |
17 | <http://www.gnu.org/licenses/>. */ | |
33574c17 ST |
18 | |
19 | /* | |
20 | * POSIX Threads Extension: ??? <pthread.h> | |
21 | */ | |
22 | ||
23 | #ifndef _PTHREAD_H | |
24 | #define _PTHREAD_H 1 | |
25 | ||
26 | #include <features.h> | |
27 | ||
28 | #include <sys/cdefs.h> | |
29 | #ifndef __extern_inline | |
30 | /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 | |
31 | inline semantics, unless -fgnu89-inline is used. */ | |
32 | # if !defined __cplusplus || __GNUC_PREREQ (4,3) | |
33 | # if defined __GNUC_STDC_INLINE__ || defined __cplusplus | |
34 | # define __extern_inline extern __inline __attribute__ ((__gnu_inline__)) | |
35 | # if __GNUC_PREREQ (4,3) | |
36 | # define __extern_always_inline \ | |
37 | extern __always_inline __attribute__ ((__gnu_inline__, __artificial__)) | |
38 | # else | |
39 | # define __extern_always_inline \ | |
40 | extern __always_inline __attribute__ ((__gnu_inline__)) | |
41 | # endif | |
42 | # else | |
43 | # define __extern_inline extern __inline | |
44 | # define __extern_always_inline extern __always_inline | |
45 | # endif | |
46 | # endif | |
47 | #endif | |
48 | ||
49 | #include <sched.h> | |
50 | #include <time.h> | |
51 | ||
52 | __BEGIN_DECLS | |
53 | ||
54 | #include <bits/pthreadtypes.h> | |
55 | ||
56 | #include <bits/pthread.h> | |
57 | ||
58 | /* Possible values for the process shared attribute. */ | |
59 | #define PTHREAD_PROCESS_PRIVATE __PTHREAD_PROCESS_PRIVATE | |
60 | #define PTHREAD_PROCESS_SHARED __PTHREAD_PROCESS_SHARED | |
61 | \f | |
62 | ||
63 | /* Thread attributes. */ | |
64 | ||
65 | /* Possible values for the inheritsched attribute. */ | |
66 | #define PTHREAD_EXPLICIT_SCHED __PTHREAD_EXPLICIT_SCHED | |
67 | #define PTHREAD_INHERIT_SCHED __PTHREAD_INHERIT_SCHED | |
68 | ||
69 | /* Possible values for the `contentionscope' attribute. */ | |
70 | #define PTHREAD_SCOPE_SYSTEM __PTHREAD_SCOPE_SYSTEM | |
71 | #define PTHREAD_SCOPE_PROCESS __PTHREAD_SCOPE_PROCESS | |
72 | ||
73 | /* Possible values for the `detachstate' attribute. */ | |
74 | #define PTHREAD_CREATE_JOINABLE __PTHREAD_CREATE_JOINABLE | |
75 | #define PTHREAD_CREATE_DETACHED __PTHREAD_CREATE_DETACHED | |
76 | ||
77 | #include <bits/types/struct___pthread_attr.h> | |
78 | ||
79 | /* Initialize the thread attribute object in *ATTR to the default | |
80 | values. */ | |
81 | extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1)); | |
82 | ||
83 | /* Destroy the thread attribute object in *ATTR. */ | |
84 | extern int pthread_attr_destroy (pthread_attr_t *__attr) | |
85 | __THROW __nonnull ((1)); | |
86 | ||
87 | ||
88 | /* Return the value of the inheritsched attribute in *ATTR in | |
89 | *INHERITSCHED. */ | |
90 | extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict __attr, | |
91 | int *__restrict __inheritsched) | |
92 | __THROW __nonnull ((1, 2)); | |
93 | ||
94 | /* Set the value of the inheritsched attribute in *ATTR to | |
95 | INHERITSCHED. */ | |
96 | extern int pthread_attr_setinheritsched (pthread_attr_t *__attr, | |
97 | int __inheritsched) | |
98 | __THROW __nonnull ((1)); | |
99 | ||
100 | ||
101 | /* Return the value of the schedparam attribute in *ATTR in *PARAM. */ | |
102 | extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict __attr, | |
103 | struct sched_param *__restrict __param) | |
104 | __THROW __nonnull ((1, 2)); | |
105 | ||
106 | /* Set the value of the schedparam attribute in *ATTR to PARAM. */ | |
107 | extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr, | |
108 | const struct sched_param *__restrict | |
109 | __param) __THROW __nonnull ((1, 2)); | |
110 | ||
111 | ||
112 | /* Return the value of the schedpolicy attribute in *ATTR to *POLICY. */ | |
113 | extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict __attr, | |
114 | int *__restrict __policy) | |
115 | __THROW __nonnull ((1, 2)); | |
116 | ||
117 | /* Set the value of the schedpolicy attribute in *ATTR to POLICY. */ | |
118 | extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, | |
119 | int __policy) | |
120 | __THROW __nonnull ((1)); | |
121 | ||
122 | ||
123 | /* Return the value of the contentionscope attribute in *ATTR in | |
124 | *CONTENTIONSCOPE. */ | |
125 | extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr, | |
126 | int *__restrict __contentionscope) | |
127 | __THROW __nonnull ((1, 2)); | |
128 | ||
129 | /* Set the value of the contentionscope attribute in *ATTR to | |
130 | CONTENTIONSCOPE. */ | |
131 | extern int pthread_attr_setscope (pthread_attr_t *__attr, | |
132 | int __contentionscope) | |
133 | __THROW __nonnull ((1)); | |
134 | ||
135 | ||
136 | /* Return the value of the stackaddr attribute in *ATTR in | |
137 | *STACKADDR. */ | |
138 | extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict __attr, | |
139 | void **__restrict __stackaddr) | |
140 | __THROW __nonnull ((1, 2)); | |
141 | ||
142 | /* Set the value of the stackaddr attribute in *ATTR to STACKADDR. */ | |
143 | extern int pthread_attr_setstackaddr (pthread_attr_t *__attr, | |
144 | void *__stackaddr) | |
145 | __THROW __nonnull ((1)); | |
146 | ||
147 | ||
148 | #ifdef __USE_XOPEN2K | |
149 | /* Return the value of the stackaddr and stacksize attributes in *ATTR | |
150 | in *STACKADDR and *STACKSIZE respectively. */ | |
151 | extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr, | |
152 | void **__restrict __stackaddr, | |
153 | size_t *__restrict __stacksize) | |
154 | __THROW __nonnull ((1, 2, 3)); | |
155 | ||
156 | /* Set the value of the stackaddr and stacksize attributes in *ATTR to | |
157 | STACKADDR and STACKSIZE respectively. */ | |
158 | extern int pthread_attr_setstack (pthread_attr_t *__attr, | |
159 | void *__stackaddr, | |
160 | size_t __stacksize) | |
161 | __THROW __nonnull ((1)); | |
162 | #endif | |
163 | ||
164 | ||
165 | /* Return the value of the detachstate attribute in *ATTR in | |
166 | *DETACHSTATE. */ | |
167 | extern int pthread_attr_getdetachstate (const pthread_attr_t *__attr, | |
168 | int *__detachstate) | |
169 | __THROW __nonnull ((1, 2)); | |
170 | ||
171 | /* Set the value of the detachstate attribute in *ATTR to | |
172 | DETACHSTATE. */ | |
173 | extern int pthread_attr_setdetachstate (pthread_attr_t *__attr, | |
174 | int __detachstate) | |
175 | __THROW __nonnull ((1)); | |
176 | ||
177 | ||
178 | /* Return the value of the guardsize attribute in *ATTR in | |
179 | *GUARDSIZE. */ | |
180 | extern int pthread_attr_getguardsize (const pthread_attr_t *__restrict __attr, | |
181 | size_t *__restrict __guardsize) | |
182 | __THROW __nonnull ((1, 2)); | |
183 | ||
184 | /* Set the value of the guardsize attribute in *ATTR to GUARDSIZE. */ | |
185 | extern int pthread_attr_setguardsize (pthread_attr_t *__attr, | |
186 | size_t __guardsize) | |
187 | __THROW __nonnull ((1)); | |
188 | ||
189 | ||
190 | /* Return the value of the stacksize attribute in *ATTR in | |
191 | *STACKSIZE. */ | |
192 | extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict __attr, | |
193 | size_t *__restrict __stacksize) | |
194 | __THROW __nonnull ((1, 2)); | |
195 | ||
196 | /* Set the value of the stacksize attribute in *ATTR to STACKSIZE. */ | |
197 | extern int pthread_attr_setstacksize (pthread_attr_t *__attr, | |
198 | size_t __stacksize) | |
199 | __THROW __nonnull ((1)); | |
200 | ||
201 | #ifdef __USE_GNU | |
202 | /* Initialize thread attribute *ATTR with attributes corresponding to the | |
203 | already running thread THREAD. It shall be called on an uninitialized ATTR | |
204 | and destroyed with pthread_attr_destroy when no longer needed. */ | |
205 | extern int pthread_getattr_np (pthread_t __thr, pthread_attr_t *__attr) | |
206 | __THROW __nonnull ((2)); | |
207 | #endif | |
208 | \f | |
209 | ||
210 | /* Create a thread with attributes given by ATTR, executing | |
211 | START_ROUTINE with argument ARG. */ | |
212 | extern int pthread_create (pthread_t *__restrict __threadp, | |
213 | __const pthread_attr_t *__restrict __attr, | |
214 | void *(*__start_routine)(void *), | |
215 | void *__restrict __arg) __THROWNL __nonnull ((1, 3)); | |
216 | ||
217 | /* Terminate the current thread and make STATUS available to any | |
218 | thread that might join us. */ | |
219 | extern void pthread_exit (void *__status) __attribute__ ((__noreturn__)); | |
220 | ||
221 | /* Make calling thread wait for termination of thread THREAD. Return | |
222 | the exit status of the thread in *STATUS. */ | |
223 | extern int pthread_join (pthread_t __threadp, void **__status); | |
224 | ||
225 | /* Indicate that the storage for THREAD can be reclaimed when it | |
226 | terminates. */ | |
227 | extern int pthread_detach (pthread_t __threadp); | |
228 | ||
229 | /* Compare thread IDs T1 and T2. Return nonzero if they are equal, 0 | |
230 | if they are not. */ | |
231 | extern int pthread_equal (pthread_t __t1, pthread_t __t2); | |
232 | ||
233 | #ifdef __USE_EXTERN_INLINES | |
234 | ||
235 | __extern_inline int | |
236 | pthread_equal (pthread_t __t1, pthread_t __t2) | |
237 | { | |
238 | return __pthread_equal (__t1, __t2); | |
239 | } | |
240 | ||
241 | #endif /* Use extern inlines. */ | |
242 | ||
243 | ||
244 | /* Return the thread ID of the calling thread. */ | |
245 | extern pthread_t pthread_self (void) __THROW; | |
246 | \f | |
247 | ||
248 | /* Mutex attributes. */ | |
249 | ||
250 | #define PTHREAD_PRIO_NONE_NP __PTHREAD_PRIO_NONE | |
251 | #define PTHREAD_PRIO_INHERIT_NP __PTHREAD_PRIO_INHERIT | |
252 | #define PTHREAD_PRIO_PROTECT_NP __PTHREAD_PRIO_PROTECT | |
253 | #ifdef __USE_UNIX98 | |
254 | # define PTHREAD_PRIO_NONE PTHREAD_PRIO_NONE_NP | |
255 | # define PTHREAD_PRIO_INHERIT PTHREAD_PRIO_INHERIT_NP | |
256 | # define PTHREAD_PRIO_PROTECT PTHREAD_PRIO_PROTECT_NP | |
257 | #endif | |
258 | ||
259 | #define PTHREAD_MUTEX_TIMED_NP __PTHREAD_MUTEX_TIMED | |
260 | #define PTHREAD_MUTEX_ERRORCHECK_NP __PTHREAD_MUTEX_ERRORCHECK | |
261 | #define PTHREAD_MUTEX_RECURSIVE_NP __PTHREAD_MUTEX_RECURSIVE | |
262 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K8 | |
263 | # define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_TIMED_NP | |
264 | # define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP | |
265 | # define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP | |
266 | # define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL | |
267 | #endif | |
268 | #ifdef __USE_GNU | |
269 | /* For compatibility. */ | |
270 | # define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_TIMED_NP | |
271 | #endif | |
272 | ||
273 | #ifdef __USE_XOPEN2K | |
274 | # define PTHREAD_MUTEX_STALLED __PTHREAD_MUTEX_STALLED | |
275 | # define PTHREAD_MUTEX_ROBUST __PTHREAD_MUTEX_ROBUST | |
276 | #endif | |
277 | ||
278 | #include <bits/types/struct___pthread_mutexattr.h> | |
279 | ||
280 | /* Initialize the mutex attribute object in *ATTR to the default | |
281 | values. */ | |
282 | extern int pthread_mutexattr_init(pthread_mutexattr_t *__attr) | |
283 | __THROW __nonnull ((1)); | |
284 | ||
285 | /* Destroy the mutex attribute structure in *ATTR. */ | |
286 | extern int pthread_mutexattr_destroy(pthread_mutexattr_t *__attr) | |
287 | __THROW __nonnull ((1)); | |
288 | ||
289 | ||
290 | #ifdef __USE_UNIX98 | |
291 | /* Return the value of the prioceiling attribute in *ATTR in | |
292 | *PRIOCEILING. */ | |
293 | extern int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict __attr, | |
294 | int *__restrict __prioceiling) | |
295 | __THROW __nonnull ((1, 2)); | |
296 | ||
297 | /* Set the value of the prioceiling attribute in *ATTR to | |
298 | PRIOCEILING. */ | |
299 | extern int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *__attr, | |
300 | int __prioceiling) | |
301 | __THROW __nonnull ((1)); | |
302 | ||
303 | ||
304 | /* Return the value of the protocol attribute in *ATTR in | |
305 | *PROTOCOL. */ | |
306 | extern int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict __attr, | |
307 | int *__restrict __protocol) | |
308 | __THROW __nonnull ((1, 2)); | |
309 | ||
310 | /* Set the value of the protocol attribute in *ATTR to PROTOCOL. */ | |
311 | extern int pthread_mutexattr_setprotocol(pthread_mutexattr_t *__attr, | |
312 | int __protocol) | |
313 | __THROW __nonnull ((1)); | |
314 | #endif | |
315 | ||
316 | #ifdef __USE_XOPEN2K | |
317 | /* Get the robustness flag of the mutex attribute ATTR. */ | |
318 | extern int pthread_mutexattr_getrobust (const pthread_mutexattr_t *__attr, | |
319 | int *__robustness) | |
320 | __THROW __nonnull ((1, 2)); | |
321 | # ifdef __USE_GNU | |
322 | extern int pthread_mutexattr_getrobust_np (const pthread_mutexattr_t *__attr, | |
323 | int *__robustness) | |
324 | __THROW __nonnull ((1, 2)); | |
325 | # endif | |
326 | ||
327 | /* Set the robustness flag of the mutex attribute ATTR. */ | |
328 | extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr, | |
329 | int __robustness) | |
330 | __THROW __nonnull ((1)); | |
331 | # ifdef __USE_GNU | |
332 | extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr, | |
333 | int __robustness) | |
334 | __THROW __nonnull ((1)); | |
335 | # endif | |
336 | #endif | |
337 | ||
338 | ||
339 | /* Return the value of the process shared attribute in *ATTR in | |
340 | *PSHARED. */ | |
341 | extern int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict __attr, | |
342 | int *__restrict __pshared) | |
343 | __THROW __nonnull ((1, 2)); | |
344 | ||
345 | /* Set the value of the process shared attribute in *ATTR to | |
346 | PSHARED. */ | |
347 | extern int pthread_mutexattr_setpshared(pthread_mutexattr_t *__attr, | |
348 | int __pshared) | |
349 | __THROW __nonnull ((1)); | |
350 | ||
351 | ||
352 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K8 | |
353 | /* Return the value of the type attribute in *ATTR in *TYPE. */ | |
354 | extern int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict __attr, | |
355 | int *__restrict __type) | |
356 | __THROW __nonnull ((1, 2)); | |
357 | ||
358 | /* Set the value of the type attribute in *ATTR to TYPE. */ | |
359 | extern int pthread_mutexattr_settype(pthread_mutexattr_t *__attr, | |
360 | int __type) | |
361 | __THROW __nonnull ((1)); | |
362 | #endif | |
363 | \f | |
364 | ||
365 | /* Mutexes. */ | |
366 | ||
367 | #include <bits/types/struct___pthread_mutex.h> | |
368 | ||
369 | #define PTHREAD_MUTEX_INITIALIZER __PTHREAD_MUTEX_INITIALIZER | |
370 | /* Static initializer for recursive mutexes. */ | |
371 | ||
372 | #ifdef __USE_GNU | |
373 | # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ | |
374 | __PTHREAD_ERRORCHECK_MUTEX_INITIALIZER | |
375 | # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ | |
376 | __PTHREAD_RECURSIVE_MUTEX_INITIALIZER | |
377 | #endif | |
378 | ||
379 | /* Create a mutex with attributes given by ATTR and store it in | |
380 | *__MUTEX. */ | |
381 | extern int pthread_mutex_init (struct __pthread_mutex *__restrict __mutex, | |
382 | const pthread_mutexattr_t *__restrict __attr) | |
383 | __THROW __nonnull ((1)); | |
384 | ||
385 | /* Destroy the mutex __MUTEX. */ | |
386 | extern int pthread_mutex_destroy (struct __pthread_mutex *__mutex) | |
387 | __THROW __nonnull ((1)); | |
388 | ||
389 | /* Wait until lock for MUTEX becomes available and lock it. */ | |
390 | extern int pthread_mutex_lock (pthread_mutex_t *__mutex); | |
391 | ||
392 | /* Try to lock MUTEX. */ | |
393 | extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) | |
394 | __THROWNL __nonnull ((1)); | |
395 | ||
396 | #ifdef __USE_XOPEN2K | |
397 | /* Try to lock MUTEX, block until *ABSTIME if it is already held. */ | |
398 | extern int pthread_mutex_timedlock (struct __pthread_mutex *__restrict __mutex, | |
399 | const struct timespec *__restrict __abstime) | |
400 | __THROWNL __nonnull ((1, 2)); | |
401 | #endif | |
402 | ||
403 | /* Unlock MUTEX. */ | |
404 | extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) | |
405 | __THROWNL __nonnull ((1)); | |
406 | ||
407 | /* Transfer ownership of the mutex MUTEX to the thread TID. The | |
408 | caller must own the lock. */ | |
409 | extern int __pthread_mutex_transfer_np (struct __pthread_mutex *__mutex, | |
410 | pthread_t __tid) | |
411 | __THROWNL __nonnull ((1)); | |
412 | ||
413 | ||
414 | #ifdef __USE_UNIX98 | |
415 | /* Return the priority ceiling of mutex *MUTEX in *PRIOCEILING. */ | |
416 | extern int pthread_mutex_getprioceiling (const pthread_mutex_t *__restrict __mutex, | |
417 | int *__restrict __prioceiling) | |
418 | __THROW __nonnull ((1, 2)); | |
419 | ||
420 | /* After acquiring the mutex *MUTEX, set its priority ceiling to PRIO | |
421 | and return the old priority ceiling in *OLDPRIO. Before returning, | |
422 | release the mutex. */ | |
423 | extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex, | |
424 | int __prio, int *__restrict __oldprio) | |
425 | __THROW __nonnull ((1, 3)); | |
426 | #endif | |
427 | ||
428 | #ifdef __USE_XOPEN2K8 | |
429 | ||
430 | /* Declare the state protected by robust mutex MTXP as consistent. */ | |
431 | extern int pthread_mutex_consistent (pthread_mutex_t *__mtxp) | |
432 | __THROW __nonnull ((1)); | |
433 | ||
434 | # ifdef __USE_GNU | |
435 | extern int pthread_mutex_consistent_np (pthread_mutex_t *__mtxp) | |
436 | __THROW __nonnull ((1)); | |
437 | # endif | |
438 | #endif | |
439 | ||
440 | \f | |
441 | ||
442 | /* Condition attributes. */ | |
443 | ||
444 | #include <bits/types/struct___pthread_condattr.h> | |
445 | ||
446 | /* Initialize the condition attribute in *ATTR to the default | |
447 | values. */ | |
448 | extern int pthread_condattr_init (pthread_condattr_t *__attr) | |
449 | __THROW __nonnull ((1)); | |
450 | ||
451 | /* Destroy the condition attribute structure in *ATTR. */ | |
452 | extern int pthread_condattr_destroy (pthread_condattr_t *__attr) | |
453 | __THROW __nonnull ((1)); | |
454 | ||
455 | ||
456 | #ifdef __USE_XOPEN2K | |
457 | /* Return the value of the clock attribute in *ATTR in *CLOCK_ID. */ | |
458 | extern int pthread_condattr_getclock (const pthread_condattr_t *__restrict __attr, | |
459 | __clockid_t *__restrict __clock_id) | |
460 | __THROW __nonnull ((1, 2)); | |
461 | ||
462 | /* Set the value of the clock attribute in *ATTR to CLOCK_ID. */ | |
463 | extern int pthread_condattr_setclock (pthread_condattr_t *__attr, | |
464 | __clockid_t __clock_id) | |
465 | __THROW __nonnull ((1)); | |
466 | #endif | |
467 | ||
468 | ||
469 | /* Return the value of the process shared attribute in *ATTR in | |
470 | *PSHARED. */ | |
471 | extern int pthread_condattr_getpshared (const pthread_condattr_t *__restrict __attr, | |
472 | int *__restrict __pshared) | |
473 | __THROW __nonnull ((1, 2)); | |
474 | ||
475 | /* Set the value of the process shared attribute in *ATTR to | |
476 | PSHARED. */ | |
477 | extern int pthread_condattr_setpshared (pthread_condattr_t *__attr, | |
478 | int __pshared) | |
479 | __THROW __nonnull ((1)); | |
480 | \f | |
481 | ||
482 | /* Condition variables. */ | |
483 | ||
484 | #include <bits/types/struct___pthread_cond.h> | |
485 | ||
486 | #define PTHREAD_COND_INITIALIZER __PTHREAD_COND_INITIALIZER | |
487 | ||
488 | extern int pthread_cond_init (pthread_cond_t *__restrict __cond, | |
489 | const pthread_condattr_t *__restrict __attr) | |
490 | __THROW __nonnull ((1)); | |
491 | ||
492 | extern int pthread_cond_destroy (pthread_cond_t *__cond) | |
493 | __THROW __nonnull ((1)); | |
494 | ||
495 | /* Unblock at least one of the threads that are blocked on condition | |
496 | variable COND. */ | |
497 | extern int pthread_cond_signal (pthread_cond_t *__cond) | |
498 | __THROWNL __nonnull ((1)); | |
499 | ||
500 | /* Unblock all threads that are blocked on condition variable COND. */ | |
501 | extern int pthread_cond_broadcast (pthread_cond_t *__cond) | |
502 | __THROWNL __nonnull ((1)); | |
503 | ||
504 | /* Block on condition variable COND. MUTEX should be held by the | |
505 | calling thread. On success, MUTEX will be held by the calling | |
506 | thread. */ | |
507 | extern int pthread_cond_wait (pthread_cond_t *__restrict __cond, | |
508 | pthread_mutex_t *__restrict __mutex) | |
509 | __nonnull ((1, 2)); | |
510 | ||
511 | /* Block on condition variable COND. MUTEX should be held by the | |
512 | calling thread. On success, MUTEX will be held by the calling | |
513 | thread. If the time specified by ABSTIME passes, ETIMEDOUT is | |
514 | returned, and MUTEX will nevertheless be held. */ | |
515 | extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond, | |
516 | pthread_mutex_t *__restrict __mutex, | |
517 | __const struct timespec *__restrict __abstime) | |
518 | __nonnull ((1, 2, 3)); | |
519 | \f | |
520 | ||
521 | /* Spin locks. */ | |
522 | ||
523 | #ifdef __USE_XOPEN2K | |
524 | ||
525 | # include <bits/types/__pthread_spinlock_t.h> | |
526 | ||
527 | # define PTHREAD_SPINLOCK_INITIALIZER __PTHREAD_SPIN_LOCK_INITIALIZER | |
528 | ||
529 | /* Destroy the spin lock object LOCK. */ | |
530 | extern int pthread_spin_destroy (pthread_spinlock_t *__lock) | |
531 | __nonnull ((1)); | |
532 | ||
533 | /* Initialize the spin lock object LOCK. PSHARED determines whether | |
534 | the spin lock can be operated upon by multiple processes. */ | |
535 | extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) | |
536 | __nonnull ((1)); | |
537 | ||
538 | /* Lock the spin lock object LOCK. If the lock is held by another | |
539 | thread spin until it becomes available. */ | |
540 | extern int pthread_spin_lock (pthread_spinlock_t *__lock) | |
541 | __nonnull ((1)); | |
542 | ||
543 | /* Lock the spin lock object LOCK. Fail if the lock is held by | |
544 | another thread. */ | |
545 | extern int pthread_spin_trylock (pthread_spinlock_t *__lock) | |
546 | __nonnull ((1)); | |
547 | ||
548 | /* Unlock the spin lock object LOCK. */ | |
549 | extern int pthread_spin_unlock (pthread_spinlock_t *__lock) | |
550 | __nonnull ((1)); | |
551 | ||
552 | # if defined __USE_EXTERN_INLINES && defined _LIBC | |
553 | ||
554 | # include <bits/spin-lock-inline.h> | |
555 | ||
556 | __extern_inline int | |
557 | pthread_spin_destroy (pthread_spinlock_t *__lock) | |
558 | { | |
559 | return __pthread_spin_destroy (__lock); | |
560 | } | |
561 | ||
562 | __extern_inline int | |
563 | pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) | |
564 | { | |
565 | return __pthread_spin_init (__lock, __pshared); | |
566 | } | |
567 | ||
568 | __extern_inline int | |
569 | pthread_spin_lock (pthread_spinlock_t *__lock) | |
570 | { | |
571 | return __pthread_spin_lock (__lock); | |
572 | } | |
573 | ||
574 | __extern_inline int | |
575 | pthread_spin_trylock (pthread_spinlock_t *__lock) | |
576 | { | |
577 | return __pthread_spin_trylock (__lock); | |
578 | } | |
579 | ||
580 | __extern_inline int | |
581 | pthread_spin_unlock (pthread_spinlock_t *__lock) | |
582 | { | |
583 | return __pthread_spin_unlock (__lock); | |
584 | } | |
585 | ||
586 | # endif /* Use extern inlines. */ | |
587 | ||
588 | #endif /* XPG6. */ | |
589 | \f | |
590 | ||
591 | /* rwlock attributes. */ | |
592 | ||
593 | #if defined __USE_UNIX98 || defined __USE_XOPEN2K | |
594 | ||
595 | # include <bits/types/struct___pthread_rwlockattr.h> | |
596 | ||
597 | /* Initialize rwlock attribute object in *ATTR to the default | |
598 | values. */ | |
599 | extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr) | |
600 | __THROW __nonnull ((1)); | |
601 | ||
602 | /* Destroy the rwlock attribute object in *ATTR. */ | |
603 | extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr) | |
604 | __THROW __nonnull ((1)); | |
605 | ||
606 | ||
607 | /* Return the value of the process shared attribute in *ATTR in | |
608 | *PSHARED. */ | |
609 | extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *__restrict __attr, | |
610 | int *__restrict __pshared) | |
611 | __THROW __nonnull ((1, 2)); | |
612 | ||
613 | /* Set the value of the process shared atrribute in *ATTR to | |
614 | PSHARED. */ | |
615 | extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr, | |
616 | int __pshared) | |
617 | __THROW __nonnull ((1)); | |
618 | ||
619 | /* Return current setting of reader/writer preference. */ | |
620 | extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t * | |
621 | __restrict __attr, | |
622 | int *__restrict __pref) | |
623 | __THROW __nonnull ((1, 2)); | |
624 | ||
625 | /* Set reader/write preference. */ | |
626 | extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr, | |
627 | int __pref) __THROW __nonnull ((1)); | |
628 | \f | |
629 | ||
630 | /* rwlocks. */ | |
631 | ||
632 | # include <bits/types/struct___pthread_rwlock.h> | |
633 | ||
634 | # define PTHREAD_RWLOCK_INITIALIZER __PTHREAD_RWLOCK_INITIALIZER | |
635 | /* Create a rwlock object with attributes given by ATTR and strore the | |
636 | result in *RWLOCK. */ | |
637 | extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock, | |
638 | const pthread_rwlockattr_t *__restrict __attr) | |
639 | __THROW __nonnull ((1)); | |
640 | ||
641 | /* Destroy the rwlock *RWLOCK. */ | |
642 | extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) | |
643 | __THROW __nonnull ((1)); | |
644 | ||
645 | /* Acquire the rwlock *RWLOCK for reading. */ | |
646 | extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) | |
647 | __THROWNL __nonnull ((1)); | |
648 | ||
649 | /* Acquire the rwlock *RWLOCK for reading. */ | |
650 | extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) | |
651 | __THROWNL __nonnull ((1)); | |
652 | ||
653 | # ifdef __USE_XOPEN2K | |
654 | /* Acquire the rwlock *RWLOCK for reading blocking until *ABSTIME if | |
655 | it is already held. */ | |
656 | extern int pthread_rwlock_timedrdlock (struct __pthread_rwlock *__restrict __rwlock, | |
657 | const struct timespec *__restrict __abstime) | |
658 | __THROWNL __nonnull ((1, 2)); | |
659 | # endif | |
660 | ||
661 | /* Acquire the rwlock *RWLOCK for writing. */ | |
662 | extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) | |
663 | __THROWNL __nonnull ((1)); | |
664 | ||
665 | /* Try to acquire the rwlock *RWLOCK for writing. */ | |
666 | extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) | |
667 | __THROWNL __nonnull ((1)); | |
668 | ||
669 | # ifdef __USE_XOPEN2K | |
670 | /* Acquire the rwlock *RWLOCK for writing blocking until *ABSTIME if | |
671 | it is already held. */ | |
672 | extern int pthread_rwlock_timedwrlock (struct __pthread_rwlock *__restrict __rwlock, | |
673 | const struct timespec *__restrict __abstime) | |
674 | __THROWNL __nonnull ((1, 2)); | |
675 | # endif | |
676 | ||
677 | /* Release the lock held by the current thread on *RWLOCK. */ | |
678 | extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) | |
679 | __THROWNL __nonnull ((1)); | |
680 | ||
681 | #endif /* __USE_UNIX98 || __USE_XOPEN2K */ | |
682 | ||
683 | \f | |
684 | ||
685 | /* Cancelation. */ | |
686 | ||
687 | /* Register a cleanup handler. */ | |
688 | extern void pthread_cleanup_push (void (*__routine) (void *), void *__arg); | |
689 | ||
690 | /* Unregister a cleanup handler. */ | |
691 | extern void pthread_cleanup_pop (int __execute); | |
692 | ||
693 | #include <bits/cancelation.h> | |
694 | ||
695 | #define pthread_cleanup_push(rt, rtarg) __pthread_cleanup_push(rt, rtarg) | |
696 | #define pthread_cleanup_pop(execute) __pthread_cleanup_pop(execute) | |
697 | ||
698 | #define PTHREAD_CANCEL_DISABLE 0 | |
699 | #define PTHREAD_CANCEL_ENABLE 1 | |
700 | ||
701 | /* Return the calling thread's cancelation state in *OLDSTATE and set | |
702 | its state to STATE. */ | |
703 | extern int pthread_setcancelstate (int __state, int *__oldstate); | |
704 | ||
705 | #define PTHREAD_CANCEL_DEFERRED 0 | |
706 | #define PTHREAD_CANCEL_ASYNCHRONOUS 1 | |
707 | ||
708 | /* Return the calling thread's cancelation type in *OLDTYPE and set | |
709 | its type to TYPE. */ | |
710 | extern int pthread_setcanceltype (int __type, int *__oldtype); | |
711 | ||
712 | /* Value returned by pthread_join if the target thread was | |
713 | canceled. */ | |
714 | #define PTHREAD_CANCELED ((void *) -1) | |
715 | ||
716 | /* Cancel THEAD. */ | |
717 | extern int pthread_cancel (pthread_t __thr); | |
718 | ||
719 | /* Add an explicit cancelation point. */ | |
720 | extern void pthread_testcancel (void); | |
721 | \f | |
722 | ||
723 | /* Barriers attributes. */ | |
724 | ||
725 | #ifdef __USE_XOPEN2K | |
726 | ||
727 | # include <bits/types/struct___pthread_barrierattr.h> | |
728 | ||
729 | /* Initialize barrier attribute object in *ATTR to the default | |
730 | values. */ | |
731 | extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr) | |
732 | __THROW __nonnull ((1)); | |
733 | ||
734 | /* Destroy the barrier attribute object in *ATTR. */ | |
735 | extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr) | |
736 | __THROW __nonnull ((1)); | |
737 | ||
738 | ||
739 | /* Return the value of the process shared attribute in *ATTR in | |
740 | *PSHARED. */ | |
741 | extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t *__restrict __attr, | |
742 | int *__restrict __pshared) | |
743 | __THROW __nonnull ((1, 2)); | |
744 | ||
745 | /* Set the value of the process shared atrribute in *ATTR to | |
746 | PSHARED. */ | |
747 | extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr, | |
748 | int __pshared) | |
749 | __THROW __nonnull ((1)); | |
750 | \f | |
751 | ||
752 | /* Barriers. */ | |
753 | ||
754 | # include <bits/types/struct___pthread_barrier.h> | |
755 | ||
756 | /* Returned by pthread_barrier_wait to exactly one thread each time a | |
757 | barrier is passed. */ | |
758 | # define PTHREAD_BARRIER_SERIAL_THREAD -1 | |
759 | ||
760 | /* Initialize barrier BARRIER. */ | |
761 | extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier, | |
762 | const pthread_barrierattr_t *__restrict __attr, | |
763 | unsigned __count) | |
764 | __THROW __nonnull ((1)); | |
765 | ||
766 | /* Destroy barrier BARRIER. */ | |
767 | extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) | |
768 | __THROW __nonnull ((1)); | |
769 | ||
770 | /* Wait on barrier BARRIER. */ | |
771 | extern int pthread_barrier_wait (pthread_barrier_t *__barrier) | |
772 | __THROWNL __nonnull ((1)); | |
773 | ||
774 | #endif /* __USE_XOPEN2K */ | |
775 | ||
776 | \f | |
777 | ||
778 | /* Thread specific data. */ | |
779 | ||
780 | #include <bits/types/__pthread_key.h> | |
781 | ||
782 | /* Create a thread specific data key in KEY visible to all threads. | |
783 | On thread destruction, DESTRUCTOR shall be called with the thread | |
784 | specific data associate with KEY if it is not NULL. */ | |
785 | extern int pthread_key_create (pthread_key_t *__key, | |
786 | void (*__destructor) (void *)) | |
787 | __THROW __nonnull ((1)); | |
788 | ||
789 | /* Delete the thread specific data key KEY. The associated destructor | |
790 | function is not called. */ | |
791 | extern int pthread_key_delete (pthread_key_t __key) __THROW; | |
792 | ||
793 | /* Return the caller thread's thread specific value of KEY. */ | |
794 | extern void *pthread_getspecific (pthread_key_t __key) __THROW; | |
795 | ||
796 | /* Set the caller thread's thread specific value of KEY to VALUE. */ | |
797 | extern int pthread_setspecific (pthread_key_t __key, const void *__value) | |
798 | __THROW; | |
799 | \f | |
800 | ||
801 | /* Dynamic package initialization. */ | |
802 | ||
803 | #include <bits/types/struct___pthread_once.h> | |
804 | ||
805 | #define PTHREAD_ONCE_INIT __PTHREAD_ONCE_INIT | |
806 | ||
807 | /* Call INIT_ROUTINE if this function has never been called with | |
808 | *ONCE_CONTROL, otherwise do nothing. */ | |
809 | extern int pthread_once (pthread_once_t *__once_control, | |
810 | void (*__init_routine) (void)) __nonnull ((1, 2)); | |
811 | \f | |
812 | ||
813 | /* Concurrency. */ | |
814 | ||
815 | #ifdef __USE_UNIX98 | |
816 | /* Set the desired concurrency level to NEW_LEVEL. */ | |
817 | extern int pthread_setconcurrency (int __new_level) __THROW; | |
818 | ||
819 | /* Get the current concurrency level. */ | |
820 | extern int pthread_getconcurrency (void) __THROW; | |
821 | #endif | |
822 | \f | |
823 | ||
824 | /* Forking. */ | |
825 | ||
826 | /* Register the function PREPARE to be run before the process forks, | |
827 | the function PARENT to be run after a fork in the parent and the | |
828 | function CHILD to be run in the child after the fork. If no | |
829 | handling is desired then any of PREPARE, PARENT and CHILD may be | |
830 | NULL. The prepare handles will be called in the reverse order | |
831 | which they were registered and the parent and child handlers in the | |
832 | order in which they were registered. */ | |
833 | extern int pthread_atfork (void (*__prepare) (void), void (*__parent) (void), | |
834 | void (*__child) (void)) __THROW; | |
835 | \f | |
836 | ||
837 | /* Signals (should be in <signal.h>). */ | |
838 | ||
839 | /* Send signal SIGNO to thread THREAD. */ | |
840 | extern int pthread_kill (pthread_t __thr, int __signo) __THROW; | |
841 | \f | |
842 | ||
843 | /* Time. */ | |
844 | ||
845 | #ifdef __USE_XOPEN2K | |
846 | /* Return the thread cpu clock. */ | |
847 | extern int pthread_getcpuclockid (pthread_t __thr, __clockid_t *__clock) | |
848 | __THROW __nonnull ((2)); | |
849 | #endif | |
850 | \f | |
851 | ||
852 | /* Scheduling. */ | |
853 | ||
854 | /* Return thread THREAD's scheduling paramters. */ | |
855 | extern int pthread_getschedparam (pthread_t __thr, int *__restrict __policy, | |
856 | struct sched_param *__restrict __param) | |
857 | __THROW __nonnull ((2, 3)); | |
858 | ||
859 | /* Set thread THREAD's scheduling paramters. */ | |
860 | extern int pthread_setschedparam (pthread_t __thr, int __policy, | |
861 | const struct sched_param *__param) | |
862 | __THROW __nonnull ((3)); | |
863 | ||
864 | /* Set thread THREAD's scheduling priority. */ | |
865 | extern int pthread_setschedprio (pthread_t __thr, int __prio) __THROW; | |
866 | ||
867 | #ifdef __USE_GNU | |
868 | /* Yield the processor to another thread or process. | |
869 | This function is similar to the POSIX `sched_yield' function but | |
870 | might be differently implemented in the case of a m-on-n thread | |
871 | implementation. */ | |
872 | extern int pthread_yield (void) __THROW; | |
873 | #endif | |
874 | \f | |
875 | ||
876 | /* Kernel-specific interfaces. */ | |
877 | ||
878 | #include <bits/pthread-np.h> | |
879 | ||
880 | ||
881 | __END_DECLS | |
882 | ||
883 | #endif /* pthread.h */ |