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