Revert "hurd: Stop depending on the default_pager stubs provided by gnumach"
[glibc.git] / sysdeps / htl / pthread.h
blob65837d10cfe0dcb7934df09266d8f2f5b674f424
1 /* Posix threads. Hurd version.
2 Copyright (C) 2000-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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
13 Lesser General Public License for more details.
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 <https://www.gnu.org/licenses/>. */
20 * POSIX Threads Extension: ??? <pthread.h>
23 #ifndef _PTHREAD_H
24 #define _PTHREAD_H 1
26 #include <features.h>
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
49 #include <sched.h>
50 #include <time.h>
52 __BEGIN_DECLS
54 #include <bits/pthreadtypes.h>
56 #include <bits/pthread.h>
58 /* Possible values for the process shared attribute. */
59 #define PTHREAD_PROCESS_PRIVATE __PTHREAD_PROCESS_PRIVATE
60 #define PTHREAD_PROCESS_SHARED __PTHREAD_PROCESS_SHARED
63 /* Thread attributes. */
65 /* Possible values for the inheritsched attribute. */
66 #define PTHREAD_EXPLICIT_SCHED __PTHREAD_EXPLICIT_SCHED
67 #define PTHREAD_INHERIT_SCHED __PTHREAD_INHERIT_SCHED
69 /* Possible values for the `contentionscope' attribute. */
70 #define PTHREAD_SCOPE_SYSTEM __PTHREAD_SCOPE_SYSTEM
71 #define PTHREAD_SCOPE_PROCESS __PTHREAD_SCOPE_PROCESS
73 /* Possible values for the `detachstate' attribute. */
74 #define PTHREAD_CREATE_JOINABLE __PTHREAD_CREATE_JOINABLE
75 #define PTHREAD_CREATE_DETACHED __PTHREAD_CREATE_DETACHED
77 #include <bits/types/struct___pthread_attr.h>
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));
83 /* Destroy the thread attribute object in *ATTR. */
84 extern int pthread_attr_destroy (pthread_attr_t *__attr)
85 __THROW __nonnull ((1));
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));
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));
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));
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));
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));
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));
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));
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));
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));
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));
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));
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
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));
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));
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));
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));
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));
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));
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
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));
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__));
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);
225 #ifdef __USE_GNU
226 /* Check whether thread TH has terminated. If yes return the status of
227 the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
228 extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
230 /* Make calling thread wait for termination of the thread TH, but only
231 until TIMEOUT. The exit status of the thread is stored in
232 *THREAD_RETURN, if THREAD_RETURN is not NULL.
234 This function is a cancellation point and therefore not marked with
235 __THROW. */
236 extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
237 const struct timespec *__abstime);
239 /* Make calling thread wait for termination of the thread TH, but only
240 until TIMEOUT measured against the clock specified by CLOCKID. The
241 exit status of the thread is stored in *THREAD_RETURN, if
242 THREAD_RETURN is not NULL.
244 This function is a cancellation point and therefore not marked with
245 __THROW. */
246 extern int pthread_clockjoin_np (pthread_t __th, void **__thread_return,
247 clockid_t __clockid,
248 const struct timespec *__abstime);
249 #endif
251 /* Indicate that the storage for THREAD can be reclaimed when it
252 terminates. */
253 extern int pthread_detach (pthread_t __threadp);
255 /* Compare thread IDs T1 and T2. Return nonzero if they are equal, 0
256 if they are not. */
257 extern int pthread_equal (pthread_t __t1, pthread_t __t2);
259 #ifdef __USE_EXTERN_INLINES
261 __extern_inline int
262 pthread_equal (pthread_t __t1, pthread_t __t2)
264 return __pthread_equal (__t1, __t2);
267 #endif /* Use extern inlines. */
270 /* Return the thread ID of the calling thread. */
271 extern pthread_t pthread_self (void) __THROW;
274 /* Mutex attributes. */
276 #define PTHREAD_PRIO_NONE_NP __PTHREAD_PRIO_NONE
277 #define PTHREAD_PRIO_INHERIT_NP __PTHREAD_PRIO_INHERIT
278 #define PTHREAD_PRIO_PROTECT_NP __PTHREAD_PRIO_PROTECT
279 #ifdef __USE_UNIX98
280 # define PTHREAD_PRIO_NONE PTHREAD_PRIO_NONE_NP
281 # define PTHREAD_PRIO_INHERIT PTHREAD_PRIO_INHERIT_NP
282 # define PTHREAD_PRIO_PROTECT PTHREAD_PRIO_PROTECT_NP
283 #endif
285 #define PTHREAD_MUTEX_TIMED_NP __PTHREAD_MUTEX_TIMED
286 #define PTHREAD_MUTEX_ERRORCHECK_NP __PTHREAD_MUTEX_ERRORCHECK
287 #define PTHREAD_MUTEX_RECURSIVE_NP __PTHREAD_MUTEX_RECURSIVE
288 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
289 # define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_TIMED_NP
290 # define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP
291 # define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
292 # define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
293 #endif
294 #ifdef __USE_GNU
295 /* For compatibility. */
296 # define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_TIMED_NP
297 #endif
299 #ifdef __USE_XOPEN2K
300 # define PTHREAD_MUTEX_STALLED __PTHREAD_MUTEX_STALLED
301 # define PTHREAD_MUTEX_ROBUST __PTHREAD_MUTEX_ROBUST
302 # define PTHREAD_MUTEX_ROBUST_NP __PTHREAD_MUTEX_ROBUST
303 #endif
305 #include <bits/types/struct___pthread_mutexattr.h>
307 /* Initialize the mutex attribute object in *ATTR to the default
308 values. */
309 extern int pthread_mutexattr_init(pthread_mutexattr_t *__attr)
310 __THROW __nonnull ((1));
312 /* Destroy the mutex attribute structure in *ATTR. */
313 extern int pthread_mutexattr_destroy(pthread_mutexattr_t *__attr)
314 __THROW __nonnull ((1));
317 #ifdef __USE_UNIX98
318 /* Return the value of the prioceiling attribute in *ATTR in
319 *PRIOCEILING. */
320 extern int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict __attr,
321 int *__restrict __prioceiling)
322 __THROW __nonnull ((1, 2));
324 /* Set the value of the prioceiling attribute in *ATTR to
325 PRIOCEILING. */
326 extern int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *__attr,
327 int __prioceiling)
328 __THROW __nonnull ((1));
331 /* Return the value of the protocol attribute in *ATTR in
332 *PROTOCOL. */
333 extern int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict __attr,
334 int *__restrict __protocol)
335 __THROW __nonnull ((1, 2));
337 /* Set the value of the protocol attribute in *ATTR to PROTOCOL. */
338 extern int pthread_mutexattr_setprotocol(pthread_mutexattr_t *__attr,
339 int __protocol)
340 __THROW __nonnull ((1));
341 #endif
343 #ifdef __USE_XOPEN2K
344 /* Get the robustness flag of the mutex attribute ATTR. */
345 extern int pthread_mutexattr_getrobust (const pthread_mutexattr_t *__attr,
346 int *__robustness)
347 __THROW __nonnull ((1, 2));
348 # ifdef __USE_GNU
349 extern int pthread_mutexattr_getrobust_np (const pthread_mutexattr_t *__attr,
350 int *__robustness)
351 __THROW __nonnull ((1, 2));
352 # endif
354 /* Set the robustness flag of the mutex attribute ATTR. */
355 extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr,
356 int __robustness)
357 __THROW __nonnull ((1));
358 # ifdef __USE_GNU
359 extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr,
360 int __robustness)
361 __THROW __nonnull ((1));
362 # endif
363 #endif
366 /* Return the value of the process shared attribute in *ATTR in
367 *PSHARED. */
368 extern int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict __attr,
369 int *__restrict __pshared)
370 __THROW __nonnull ((1, 2));
372 /* Set the value of the process shared attribute in *ATTR to
373 PSHARED. */
374 extern int pthread_mutexattr_setpshared(pthread_mutexattr_t *__attr,
375 int __pshared)
376 __THROW __nonnull ((1));
379 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
380 /* Return the value of the type attribute in *ATTR in *TYPE. */
381 extern int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict __attr,
382 int *__restrict __type)
383 __THROW __nonnull ((1, 2));
385 /* Set the value of the type attribute in *ATTR to TYPE. */
386 extern int pthread_mutexattr_settype(pthread_mutexattr_t *__attr,
387 int __type)
388 __THROW __nonnull ((1));
389 #endif
392 /* Mutexes. */
394 #include <bits/types/struct___pthread_mutex.h>
396 #define PTHREAD_MUTEX_INITIALIZER __PTHREAD_MUTEX_INITIALIZER
397 /* Static initializer for recursive mutexes. */
399 #ifdef __USE_GNU
400 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
401 __PTHREAD_ERRORCHECK_MUTEX_INITIALIZER
402 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
403 __PTHREAD_RECURSIVE_MUTEX_INITIALIZER
404 #endif
406 /* Create a mutex with attributes given by ATTR and store it in
407 *__MUTEX. */
408 extern int pthread_mutex_init (struct __pthread_mutex *__restrict __mutex,
409 const pthread_mutexattr_t *__restrict __attr)
410 __THROW __nonnull ((1));
412 /* Destroy the mutex __MUTEX. */
413 extern int pthread_mutex_destroy (struct __pthread_mutex *__mutex)
414 __THROW __nonnull ((1));
416 /* Wait until lock for MUTEX becomes available and lock it. */
417 extern int pthread_mutex_lock (pthread_mutex_t *__mutex);
419 /* Try to lock MUTEX. */
420 extern int pthread_mutex_trylock (pthread_mutex_t *__mutex)
421 __THROWNL __nonnull ((1));
423 #ifdef __USE_XOPEN2K
424 /* Try to lock MUTEX, block until *ABSTIME if it is already held. */
425 extern int pthread_mutex_timedlock (struct __pthread_mutex *__restrict __mutex,
426 const struct timespec *__restrict __abstime)
427 __THROWNL __nonnull ((1, 2));
428 #endif
430 #ifdef __USE_GNU
431 extern int pthread_mutex_clocklock (pthread_mutex_t *__restrict __mutex,
432 clockid_t __clockid,
433 const struct timespec *__restrict
434 __abstime) __THROWNL __nonnull ((1, 3));
435 #endif
437 /* Unlock MUTEX. */
438 extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
439 __THROWNL __nonnull ((1));
441 /* Transfer ownership of the mutex MUTEX to the thread TID. The
442 caller must own the lock. */
443 extern int __pthread_mutex_transfer_np (struct __pthread_mutex *__mutex,
444 pthread_t __tid)
445 __THROWNL __nonnull ((1));
448 #ifdef __USE_UNIX98
449 /* Return the priority ceiling of mutex *MUTEX in *PRIOCEILING. */
450 extern int pthread_mutex_getprioceiling (const pthread_mutex_t *__restrict __mutex,
451 int *__restrict __prioceiling)
452 __THROW __nonnull ((1, 2));
454 /* After acquiring the mutex *MUTEX, set its priority ceiling to PRIO
455 and return the old priority ceiling in *OLDPRIO. Before returning,
456 release the mutex. */
457 extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex,
458 int __prio, int *__restrict __oldprio)
459 __THROW __nonnull ((1, 3));
460 #endif
462 #ifdef __USE_XOPEN2K8
464 /* Declare the state protected by robust mutex MTXP as consistent. */
465 extern int pthread_mutex_consistent (pthread_mutex_t *__mtxp)
466 __THROW __nonnull ((1));
468 # ifdef __USE_GNU
469 extern int pthread_mutex_consistent_np (pthread_mutex_t *__mtxp)
470 __THROW __nonnull ((1));
471 # endif
472 #endif
476 /* Condition attributes. */
478 #include <bits/types/struct___pthread_condattr.h>
480 /* Initialize the condition attribute in *ATTR to the default
481 values. */
482 extern int pthread_condattr_init (pthread_condattr_t *__attr)
483 __THROW __nonnull ((1));
485 /* Destroy the condition attribute structure in *ATTR. */
486 extern int pthread_condattr_destroy (pthread_condattr_t *__attr)
487 __THROW __nonnull ((1));
490 #ifdef __USE_XOPEN2K
491 /* Return the value of the clock attribute in *ATTR in *CLOCK_ID. */
492 extern int pthread_condattr_getclock (const pthread_condattr_t *__restrict __attr,
493 __clockid_t *__restrict __clock_id)
494 __THROW __nonnull ((1, 2));
496 /* Set the value of the clock attribute in *ATTR to CLOCK_ID. */
497 extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
498 __clockid_t __clock_id)
499 __THROW __nonnull ((1));
500 #endif
503 /* Return the value of the process shared attribute in *ATTR in
504 *PSHARED. */
505 extern int pthread_condattr_getpshared (const pthread_condattr_t *__restrict __attr,
506 int *__restrict __pshared)
507 __THROW __nonnull ((1, 2));
509 /* Set the value of the process shared attribute in *ATTR to
510 PSHARED. */
511 extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
512 int __pshared)
513 __THROW __nonnull ((1));
516 /* Condition variables. */
518 #include <bits/types/struct___pthread_cond.h>
520 #define PTHREAD_COND_INITIALIZER __PTHREAD_COND_INITIALIZER
522 extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
523 const pthread_condattr_t *__restrict __attr)
524 __THROW __nonnull ((1));
526 extern int pthread_cond_destroy (pthread_cond_t *__cond)
527 __THROW __nonnull ((1));
529 /* Unblock at least one of the threads that are blocked on condition
530 variable COND. */
531 extern int pthread_cond_signal (pthread_cond_t *__cond)
532 __THROWNL __nonnull ((1));
534 /* Unblock all threads that are blocked on condition variable COND. */
535 extern int pthread_cond_broadcast (pthread_cond_t *__cond)
536 __THROWNL __nonnull ((1));
538 /* Block on condition variable COND. MUTEX should be held by the
539 calling thread. On success, MUTEX will be held by the calling
540 thread. */
541 extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
542 pthread_mutex_t *__restrict __mutex)
543 __nonnull ((1, 2));
545 /* Block on condition variable COND. MUTEX should be held by the
546 calling thread. On success, MUTEX will be held by the calling
547 thread. If the time specified by ABSTIME passes, ETIMEDOUT is
548 returned, and MUTEX will nevertheless be held. */
549 extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
550 pthread_mutex_t *__restrict __mutex,
551 __const struct timespec *__restrict __abstime)
552 __nonnull ((1, 2, 3));
554 # ifdef __USE_GNU
555 /* Wait for condition variable COND to be signaled or broadcast until
556 ABSTIME measured by the specified clock. MUTEX is assumed to be
557 locked before. CLOCK is the clock to use. ABSTIME is an absolute
558 time specification against CLOCK's epoch.
560 This function is a cancellation point and therefore not marked with
561 __THROW. */
562 extern int pthread_cond_clockwait (pthread_cond_t *__restrict __cond,
563 pthread_mutex_t *__restrict __mutex,
564 __clockid_t __clock_id,
565 const struct timespec *__restrict __abstime)
566 __nonnull ((1, 2, 4));
567 # endif
570 /* Spin locks. */
572 #ifdef __USE_XOPEN2K
574 # include <bits/types/__pthread_spinlock_t.h>
576 # define PTHREAD_SPINLOCK_INITIALIZER __PTHREAD_SPIN_LOCK_INITIALIZER
578 /* Destroy the spin lock object LOCK. */
579 extern int pthread_spin_destroy (pthread_spinlock_t *__lock)
580 __nonnull ((1));
582 /* Initialize the spin lock object LOCK. PSHARED determines whether
583 the spin lock can be operated upon by multiple processes. */
584 extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
585 __nonnull ((1));
587 /* Lock the spin lock object LOCK. If the lock is held by another
588 thread spin until it becomes available. */
589 extern int pthread_spin_lock (pthread_spinlock_t *__lock)
590 __nonnull ((1));
592 /* Lock the spin lock object LOCK. Fail if the lock is held by
593 another thread. */
594 extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
595 __nonnull ((1));
597 /* Unlock the spin lock object LOCK. */
598 extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
599 __nonnull ((1));
601 #endif /* XPG6. */
604 /* rwlock attributes. */
606 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
608 # include <bits/types/struct___pthread_rwlockattr.h>
610 /* Initialize rwlock attribute object in *ATTR to the default
611 values. */
612 extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr)
613 __THROW __nonnull ((1));
615 /* Destroy the rwlock attribute object in *ATTR. */
616 extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr)
617 __THROW __nonnull ((1));
620 /* Return the value of the process shared attribute in *ATTR in
621 *PSHARED. */
622 extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *__restrict __attr,
623 int *__restrict __pshared)
624 __THROW __nonnull ((1, 2));
626 /* Set the value of the process shared attribute in *ATTR to
627 PSHARED. */
628 extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
629 int __pshared)
630 __THROW __nonnull ((1));
632 /* Return current setting of reader/writer preference. */
633 extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t *
634 __restrict __attr,
635 int *__restrict __pref)
636 __THROW __nonnull ((1, 2));
638 /* Set reader/write preference. */
639 extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
640 int __pref) __THROW __nonnull ((1));
643 /* rwlocks. */
645 # include <bits/types/struct___pthread_rwlock.h>
647 # define PTHREAD_RWLOCK_INITIALIZER __PTHREAD_RWLOCK_INITIALIZER
648 /* Create a rwlock object with attributes given by ATTR and store the
649 result in *RWLOCK. */
650 extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
651 const pthread_rwlockattr_t *__restrict __attr)
652 __THROW __nonnull ((1));
654 /* Destroy the rwlock *RWLOCK. */
655 extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock)
656 __THROW __nonnull ((1));
658 /* Acquire the rwlock *RWLOCK for reading. */
659 extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock)
660 __THROWNL __nonnull ((1));
662 /* Acquire the rwlock *RWLOCK for reading. */
663 extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
664 __THROWNL __nonnull ((1));
666 # ifdef __USE_XOPEN2K
667 /* Acquire the rwlock *RWLOCK for reading blocking until *ABSTIME if
668 it is already held. */
669 extern int pthread_rwlock_timedrdlock (struct __pthread_rwlock *__restrict __rwlock,
670 const struct timespec *__restrict __abstime)
671 __THROWNL __nonnull ((1, 2));
672 # endif
674 # ifdef __USE_GNU
675 extern int pthread_rwlock_clockrdlock (pthread_rwlock_t *__restrict __rwlock,
676 clockid_t __clockid,
677 const struct timespec *__restrict
678 __abstime) __THROWNL __nonnull ((1, 3));
679 # endif
681 /* Acquire the rwlock *RWLOCK for writing. */
682 extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
683 __THROWNL __nonnull ((1));
685 /* Try to acquire the rwlock *RWLOCK for writing. */
686 extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
687 __THROWNL __nonnull ((1));
689 # ifdef __USE_XOPEN2K
690 /* Acquire the rwlock *RWLOCK for writing blocking until *ABSTIME if
691 it is already held. */
692 extern int pthread_rwlock_timedwrlock (struct __pthread_rwlock *__restrict __rwlock,
693 const struct timespec *__restrict __abstime)
694 __THROWNL __nonnull ((1, 2));
695 # endif
697 # ifdef __USE_GNU
698 extern int pthread_rwlock_clockwrlock (pthread_rwlock_t *__restrict __rwlock,
699 clockid_t __clockid,
700 const struct timespec *__restrict
701 __abstime) __THROWNL __nonnull ((1, 3));
702 # endif
704 /* Release the lock held by the current thread on *RWLOCK. */
705 extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
706 __THROWNL __nonnull ((1));
708 #endif /* __USE_UNIX98 || __USE_XOPEN2K */
712 /* Cancellation. */
714 /* Register a cleanup handler. */
715 extern void pthread_cleanup_push (void (*__routine) (void *), void *__arg);
717 /* Unregister a cleanup handler. */
718 extern void pthread_cleanup_pop (int __execute);
720 #include <bits/cancelation.h>
722 #define pthread_cleanup_push(rt, rtarg) __pthread_cleanup_push(rt, rtarg)
723 #define pthread_cleanup_pop(execute) __pthread_cleanup_pop(execute)
725 #define PTHREAD_CANCEL_DISABLE 0
726 #define PTHREAD_CANCEL_ENABLE 1
728 /* Return the calling thread's cancelation state in *OLDSTATE and set
729 its state to STATE. */
730 extern int pthread_setcancelstate (int __state, int *__oldstate);
732 #define PTHREAD_CANCEL_DEFERRED 0
733 #define PTHREAD_CANCEL_ASYNCHRONOUS 1
735 /* Return the calling thread's cancelation type in *OLDTYPE and set
736 its type to TYPE. */
737 extern int pthread_setcanceltype (int __type, int *__oldtype);
739 /* Value returned by pthread_join if the target thread was
740 canceled. */
741 #define PTHREAD_CANCELED ((void *) -1)
743 /* Cancel THEAD. */
744 extern int pthread_cancel (pthread_t __thr);
746 /* Add an explicit cancelation point. */
747 extern void pthread_testcancel (void);
750 /* Barriers attributes. */
752 #ifdef __USE_XOPEN2K
754 # include <bits/types/struct___pthread_barrierattr.h>
756 /* Initialize barrier attribute object in *ATTR to the default
757 values. */
758 extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr)
759 __THROW __nonnull ((1));
761 /* Destroy the barrier attribute object in *ATTR. */
762 extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr)
763 __THROW __nonnull ((1));
766 /* Return the value of the process shared attribute in *ATTR in
767 *PSHARED. */
768 extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t *__restrict __attr,
769 int *__restrict __pshared)
770 __THROW __nonnull ((1, 2));
772 /* Set the value of the process shared attribute in *ATTR to
773 PSHARED. */
774 extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
775 int __pshared)
776 __THROW __nonnull ((1));
779 /* Barriers. */
781 # include <bits/types/struct___pthread_barrier.h>
783 /* Returned by pthread_barrier_wait to exactly one thread each time a
784 barrier is passed. */
785 # define PTHREAD_BARRIER_SERIAL_THREAD -1
787 /* Initialize barrier BARRIER. */
788 extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
789 const pthread_barrierattr_t *__restrict __attr,
790 unsigned __count)
791 __THROW __nonnull ((1));
793 /* Destroy barrier BARRIER. */
794 extern int pthread_barrier_destroy (pthread_barrier_t *__barrier)
795 __THROW __nonnull ((1));
797 /* Wait on barrier BARRIER. */
798 extern int pthread_barrier_wait (pthread_barrier_t *__barrier)
799 __THROWNL __nonnull ((1));
801 #endif /* __USE_XOPEN2K */
805 /* Thread specific data. */
807 #include <bits/types/__pthread_key.h>
809 /* Create a thread specific data key in KEY visible to all threads.
810 On thread destruction, DESTRUCTOR shall be called with the thread
811 specific data associate with KEY if it is not NULL. */
812 extern int pthread_key_create (pthread_key_t *__key,
813 void (*__destructor) (void *))
814 __THROW __nonnull ((1));
816 /* Delete the thread specific data key KEY. The associated destructor
817 function is not called. */
818 extern int pthread_key_delete (pthread_key_t __key) __THROW;
820 /* Return the caller thread's thread specific value of KEY. */
821 extern void *pthread_getspecific (pthread_key_t __key) __THROW;
823 /* Set the caller thread's thread specific value of KEY to VALUE. */
824 extern int pthread_setspecific (pthread_key_t __key, const void *__value)
825 __THROW __attr_access_none (2);
828 /* Dynamic package initialization. */
830 #include <bits/types/struct___pthread_once.h>
832 #define PTHREAD_ONCE_INIT (struct __pthread_once) { __PTHREAD_ONCE_INIT }
834 /* Call INIT_ROUTINE if this function has never been called with
835 *ONCE_CONTROL, otherwise do nothing. */
836 extern int pthread_once (pthread_once_t *__once_control,
837 void (*__init_routine) (void)) __nonnull ((1, 2));
840 /* Concurrency. */
842 #ifdef __USE_UNIX98
843 /* Set the desired concurrency level to NEW_LEVEL. */
844 extern int pthread_setconcurrency (int __new_level) __THROW;
846 /* Get the current concurrency level. */
847 extern int pthread_getconcurrency (void) __THROW;
848 #endif
851 /* Forking. */
853 /* Register the function PREPARE to be run before the process forks,
854 the function PARENT to be run after a fork in the parent and the
855 function CHILD to be run in the child after the fork. If no
856 handling is desired then any of PREPARE, PARENT and CHILD may be
857 NULL. The prepare handles will be called in the reverse order
858 which they were registered and the parent and child handlers in the
859 order in which they were registered. */
860 extern int pthread_atfork (void (*__prepare) (void), void (*__parent) (void),
861 void (*__child) (void)) __THROW;
864 /* Signals (should be in <signal.h>). */
866 /* Send signal SIGNO to thread THREAD. */
867 extern int pthread_kill (pthread_t __thr, int __signo) __THROW;
870 /* Time. */
872 #ifdef __USE_XOPEN2K
873 /* Return the thread cpu clock. */
874 extern int pthread_getcpuclockid (pthread_t __thr, __clockid_t *__clock)
875 __THROW __nonnull ((2));
876 #endif
879 /* Scheduling. */
881 /* Return thread THREAD's scheduling parameters. */
882 extern int pthread_getschedparam (pthread_t __thr, int *__restrict __policy,
883 struct sched_param *__restrict __param)
884 __THROW __nonnull ((2, 3));
886 /* Set thread THREAD's scheduling parameters. */
887 extern int pthread_setschedparam (pthread_t __thr, int __policy,
888 const struct sched_param *__param)
889 __THROW __nonnull ((3));
891 /* Set thread THREAD's scheduling priority. */
892 extern int pthread_setschedprio (pthread_t __thr, int __prio) __THROW;
894 #ifdef __USE_GNU
895 /* Get thread name visible in the kernel and its interfaces. */
896 extern int pthread_getname_np (pthread_t __target_thread, char *__buf,
897 size_t __buflen)
898 __THROW __nonnull ((2)) __attr_access ((__write_only__, 2));
900 /* Set thread name visible in the kernel and its interfaces. */
901 extern int pthread_setname_np (pthread_t __target_thread, const char *__name)
902 __THROW __nonnull ((2)) __attr_access ((__read_only__, 2));
903 #endif
905 #ifdef __USE_GNU
906 /* Yield the processor to another thread or process.
907 This function is similar to the POSIX `sched_yield' function but
908 might be differently implemented in the case of a m-on-n thread
909 implementation. */
910 extern int pthread_yield (void) __THROW;
911 #endif
914 /* Kernel-specific interfaces. */
916 #include <bits/pthread-np.h>
919 __END_DECLS
921 #endif /* pthread.h */