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