]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/nptl/pthreadP.h
Remove --enable-tunables configure option
[thirdparty/glibc.git] / sysdeps / nptl / pthreadP.h
CommitLineData
6d7e8eda 1/* Copyright (C) 2002-2023 Free Software Foundation, Inc.
76a50749 2 This file is part of the GNU C Library.
76a50749
UD
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 _PTHREADP_H
19#define _PTHREADP_H 1
20
a25077a4
ST
21#define __PTHREAD_NPTL
22
76a50749
UD
23#include <pthread.h>
24#include <setjmp.h>
b758b9cb 25#include <stdbool.h>
76a50749 26#include <sys/syscall.h>
3c79234c 27#include <nptl/descr.h>
76a50749
UD
28#include <tls.h>
29#include <lowlevellock.h>
30#include <stackinfo.h>
31#include <internaltypes.h>
86246935 32#include <atomic.h>
0f6699ea 33#include <kernel-features.h>
da1304bc 34#include <errno.h>
92aabad9 35#include <internal-signals.h>
81621478 36#include <pthread_mutex_backoff.h>
6310e6be 37#include "pthread_mutex_conf.h"
23fe486b 38
76a50749 39
a1b5424f
UD
40/* Atomic operations on TLS memory. */
41#ifndef THREAD_ATOMIC_CMPXCHG_VAL
42# define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, new, old) \
43 atomic_compare_and_exchange_val_acq (&(descr)->member, new, old)
44#endif
45
6310e6be
KW
46static inline short max_adaptive_count (void)
47{
6310e6be 48 return __mutex_aconf.spin_count;
6310e6be 49}
2c0b891a
UD
50
51
1bcfb5a5 52/* Magic cookie representing robust mutex with dead owner. */
683040c3 53#define PTHREAD_MUTEX_INCONSISTENT INT_MAX
1bcfb5a5
UD
54/* Magic cookie representing not recoverable robust mutex. */
55#define PTHREAD_MUTEX_NOTRECOVERABLE (INT_MAX - 1)
56
57
58/* Internal mutex type value. */
59enum
60{
df47504c 61 PTHREAD_MUTEX_KIND_MASK_NP = 3,
b023e4ca
AK
62
63 PTHREAD_MUTEX_ELISION_NP = 256,
64 PTHREAD_MUTEX_NO_ELISION_NP = 512,
65
0f6699ea
UD
66 PTHREAD_MUTEX_ROBUST_NORMAL_NP = 16,
67 PTHREAD_MUTEX_ROBUST_RECURSIVE_NP
68 = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_RECURSIVE_NP,
69 PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP
70 = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
71 PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP
72 = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
df47504c
UD
73 PTHREAD_MUTEX_PRIO_INHERIT_NP = 32,
74 PTHREAD_MUTEX_PI_NORMAL_NP
75 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_NORMAL,
76 PTHREAD_MUTEX_PI_RECURSIVE_NP
77 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_RECURSIVE_NP,
78 PTHREAD_MUTEX_PI_ERRORCHECK_NP
79 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
80 PTHREAD_MUTEX_PI_ADAPTIVE_NP
81 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
82 PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP
83 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_NORMAL_NP,
84 PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP
85 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_RECURSIVE_NP,
86 PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP
87 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP,
88 PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP
89 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP,
f17efcb4
UD
90 PTHREAD_MUTEX_PRIO_PROTECT_NP = 64,
91 PTHREAD_MUTEX_PP_NORMAL_NP
92 = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_NORMAL,
93 PTHREAD_MUTEX_PP_RECURSIVE_NP
94 = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_RECURSIVE_NP,
95 PTHREAD_MUTEX_PP_ERRORCHECK_NP
96 = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
97 PTHREAD_MUTEX_PP_ADAPTIVE_NP
b023e4ca
AK
98 = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
99 PTHREAD_MUTEX_ELISION_FLAGS_NP
100 = PTHREAD_MUTEX_ELISION_NP | PTHREAD_MUTEX_NO_ELISION_NP,
101
102 PTHREAD_MUTEX_TIMED_ELISION_NP =
103 PTHREAD_MUTEX_TIMED_NP | PTHREAD_MUTEX_ELISION_NP,
104 PTHREAD_MUTEX_TIMED_NO_ELISION_NP =
105 PTHREAD_MUTEX_TIMED_NP | PTHREAD_MUTEX_NO_ELISION_NP,
1bcfb5a5 106};
5bd8a249 107#define PTHREAD_MUTEX_PSHARED_BIT 128
f17efcb4 108
403b4feb
SL
109/* See concurrency notes regarding __kind in struct __pthread_mutex_s
110 in sysdeps/nptl/bits/thread-shared-types.h. */
ae1ad3ae 111#define PTHREAD_MUTEX_TYPE(m) \
403b4feb 112 (atomic_load_relaxed (&((m)->__data.__kind)) & 127)
e8c659d7
AK
113/* Don't include NO_ELISION, as that type is always the same
114 as the underlying lock type. */
b023e4ca 115#define PTHREAD_MUTEX_TYPE_ELISION(m) \
403b4feb
SL
116 (atomic_load_relaxed (&((m)->__data.__kind)) \
117 & (127 | PTHREAD_MUTEX_ELISION_NP))
5bd8a249
UD
118
119#if LLL_PRIVATE == 0 && LLL_SHARED == 128
120# define PTHREAD_MUTEX_PSHARED(m) \
403b4feb 121 (atomic_load_relaxed (&((m)->__data.__kind)) & 128)
5bd8a249
UD
122#else
123# define PTHREAD_MUTEX_PSHARED(m) \
403b4feb
SL
124 ((atomic_load_relaxed (&((m)->__data.__kind)) & 128) \
125 ? LLL_SHARED : LLL_PRIVATE)
5bd8a249
UD
126#endif
127
128/* The kernel when waking robust mutexes on exit never uses
129 FUTEX_PRIVATE_FLAG FUTEX_WAKE. */
130#define PTHREAD_ROBUST_MUTEX_PSHARED(m) LLL_SHARED
ae1ad3ae 131
f17efcb4
UD
132/* Ceiling in __data.__lock. __data.__lock is signed, so don't
133 use the MSB bit in there, but in the mask also include that bit,
134 so that the compiler can optimize & PTHREAD_MUTEX_PRIO_CEILING_MASK
135 masking if the value is then shifted down by
136 PTHREAD_MUTEX_PRIO_CEILING_SHIFT. */
137#define PTHREAD_MUTEX_PRIO_CEILING_SHIFT 19
138#define PTHREAD_MUTEX_PRIO_CEILING_MASK 0xfff80000
1bcfb5a5
UD
139
140
141/* Flags in mutex attr. */
a5f2bd86
RM
142#define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT 28
143#define PTHREAD_MUTEXATTR_PROTOCOL_MASK 0x30000000
f17efcb4
UD
144#define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT 12
145#define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK 0x00fff000
a5f2bd86
RM
146#define PTHREAD_MUTEXATTR_FLAG_ROBUST 0x40000000
147#define PTHREAD_MUTEXATTR_FLAG_PSHARED 0x80000000
1bcfb5a5 148#define PTHREAD_MUTEXATTR_FLAG_BITS \
a5f2bd86
RM
149 (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \
150 | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
1bcfb5a5
UD
151
152
cc25c8b4
TR
153/* For the following, see pthread_rwlock_common.c. */
154#define PTHREAD_RWLOCK_WRPHASE 1
155#define PTHREAD_RWLOCK_WRLOCKED 2
156#define PTHREAD_RWLOCK_RWAITING 4
157#define PTHREAD_RWLOCK_READER_SHIFT 3
158#define PTHREAD_RWLOCK_READER_OVERFLOW ((unsigned int) 1 \
159 << (sizeof (unsigned int) * 8 - 1))
160#define PTHREAD_RWLOCK_WRHANDOVER ((unsigned int) 1 \
161 << (sizeof (unsigned int) * 8 - 1))
162#define PTHREAD_RWLOCK_FUTEX_USED 2
546346b6
UD
163
164
683040c3
UD
165/* Bits used in robust mutex implementation. */
166#define FUTEX_WAITERS 0x80000000
167#define FUTEX_OWNER_DIED 0x40000000
2035d91c 168#define FUTEX_TID_MASK 0x3fffffff
683040c3
UD
169
170
63668b70
TR
171/* pthread_once definitions. See __pthread_once for how these are used. */
172#define __PTHREAD_ONCE_INPROGRESS 1
173#define __PTHREAD_ONCE_DONE 2
174#define __PTHREAD_ONCE_FORK_GEN_INCR 4
175
ce7528f6
AZ
176/* Attribute to indicate thread creation was issued from C11 thrd_create. */
177#define ATTR_C11_THREAD ((void*)(uintptr_t)-1)
178
63668b70 179
ed19993b
TR
180/* Condition variable definitions. See __pthread_cond_wait_common.
181 Need to be defined here so there is one place from which
182 nptl_lock_constants can grab them. */
183#define __PTHREAD_COND_CLOCK_MONOTONIC_MASK 2
184#define __PTHREAD_COND_SHARED_MASK 1
185
186
76a50749
UD
187/* Internal variables. */
188
189
e903a713 190/* Default pthread attributes. */
8c1c0da3
FW
191extern union pthread_attr_transparent __default_pthread_attr;
192libc_hidden_proto (__default_pthread_attr)
193extern int __default_pthread_attr_lock;
194libc_hidden_proto (__default_pthread_attr_lock)
195/* Called from __libc_freeres to deallocate the default attribute. */
c79a31fb 196extern void __default_pthread_attr_freeres (void) attribute_hidden;
76a50749 197
76a50749
UD
198/* Attribute handling. */
199extern struct pthread_attr *__attr_list attribute_hidden;
e51deae7 200extern int __attr_list_lock attribute_hidden;
76a50749 201
76a50749
UD
202/* Concurrency handling. */
203extern int __concurrency_level attribute_hidden;
204
205/* Thread-local data key handling. */
fa9a4ff0 206extern struct pthread_key_struct __pthread_keys[PTHREAD_KEYS_MAX];
a91bf4e0 207libc_hidden_proto (__pthread_keys)
76a50749 208
47202270 209/* Number of threads running. */
43fe356d
FW
210extern unsigned int __nptl_nthreads;
211libc_hidden_proto (__nptl_nthreads)
47202270 212
0f6699ea 213#ifndef __ASSUME_SET_ROBUST_LIST
442e8a40
FW
214/* True if the set_robust_list system call works. Initialized in
215 __tls_init_tp. */
216extern bool __nptl_set_robust_list_avail;
217rtld_hidden_proto (__nptl_set_robust_list_avail)
0f6699ea
UD
218#endif
219
f17efcb4 220/* Thread Priority Protection. */
798cacde
FW
221extern int __sched_fifo_min_prio;
222libc_hidden_proto (__sched_fifo_min_prio)
223extern int __sched_fifo_max_prio;
224libc_hidden_proto (__sched_fifo_max_prio)
225extern void __init_sched_fifo_prio (void);
226libc_hidden_proto (__init_sched_fifo_prio)
227extern int __pthread_tpp_change_priority (int prev_prio, int new_prio);
228libc_hidden_proto (__pthread_tpp_change_priority)
229extern int __pthread_current_priority (void);
230libc_hidden_proto (__pthread_current_priority)
f17efcb4 231
d2af73a3
FW
232/* This will not catch all invalid descriptors but is better than
233 nothing. And if the test triggers the thread descriptor is
234 guaranteed to be invalid. */
235#define INVALID_TD_P(pd) __builtin_expect ((pd)->tid <= 0, 0)
236#define INVALID_NOT_TERMINATED_TD_P(pd) __builtin_expect ((pd)->tid < 0, 0)
76a50749 237
6efd4814
UD
238extern void __pthread_unwind (__pthread_unwind_buf_t *__buf)
239 __cleanup_fct_attribute __attribute ((__noreturn__))
ce9f10f7 240#if !defined SHARED && !IS_IN (libpthread)
6efd4814
UD
241 weak_function
242#endif
243 ;
1d95b035 244libc_hidden_proto (__pthread_unwind)
da0c02ee
UD
245extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
246 __cleanup_fct_attribute __attribute ((__noreturn__))
247#ifndef SHARED
248 weak_function
249#endif
250 ;
1d95b035
FW
251/* NB: No hidden proto for __pthread_unwind_next: inside glibc, the
252 legacy unwinding mechanism is used. */
253
da0c02ee
UD
254extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
255 __cleanup_fct_attribute;
3ec8b1c7 256libc_hidden_proto (__pthread_register_cancel)
da0c02ee
UD
257extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
258 __cleanup_fct_attribute;
3ec8b1c7 259libc_hidden_proto (__pthread_unregister_cancel)
6efd4814
UD
260
261/* Called when a thread reacts on a cancellation request. */
262static inline void
dd9423a6 263__attribute ((noreturn, always_inline))
6efd4814
UD
264__do_cancel (void)
265{
266 struct pthread *self = THREAD_SELF;
267
268 /* Make sure we get no more cancellations. */
a30e9603 269 atomic_fetch_or_relaxed (&self->cancelhandling, EXITING_BITMASK);
6efd4814
UD
270
271 __pthread_unwind ((__pthread_unwind_buf_t *)
272 THREAD_GETMEM (self, cleanup_jmp_buf));
273}
274
275
76a50749
UD
276/* Internal prototypes. */
277
76a50749
UD
278/* Deallocate a thread's stack after optionally making sure the thread
279 descriptor is still valid. */
8fbb33b3
FW
280extern void __nptl_free_tcb (struct pthread *pd);
281libc_hidden_proto (__nptl_free_tcb)
76a50749 282
2dd87703
FW
283/* Change the permissions of a thread stack. Called from
284 _dl_make_stacks_executable and pthread_create. */
285int
286__nptl_change_stack_perm (struct pthread *pd);
287rtld_hidden_proto (__nptl_change_stack_perm)
54ee14b3 288
76a50749
UD
289/* longjmp handling. */
290extern void __pthread_cleanup_upto (__jmp_buf target, char *targetframe);
4647ce82 291libc_hidden_proto (__pthread_cleanup_upto)
76a50749
UD
292
293
294/* Functions with versioned interfaces. */
f47f1d91
FW
295extern int __pthread_create (pthread_t *newthread,
296 const pthread_attr_t *attr,
297 void *(*start_routine) (void *), void *arg);
298libc_hidden_proto (__pthread_create)
76a50749
UD
299extern int __pthread_create_2_0 (pthread_t *newthread,
300 const pthread_attr_t *attr,
301 void *(*start_routine) (void *), void *arg);
3699ef99
FW
302extern int __pthread_attr_init (pthread_attr_t *attr);
303libc_hidden_proto (__pthread_attr_init)
76a50749
UD
304extern int __pthread_attr_init_2_0 (pthread_attr_t *attr);
305
a78e5979
FW
306/* Part of the legacy thread events interface (which has been
307 superseded by PTRACE_O_TRACECLONE). This can be set by the
308 debugger before initialization is complete. */
309extern bool __nptl_initial_report_events;
310rtld_hidden_proto (__nptl_initial_report_events)
76a50749
UD
311
312/* Event handlers for libthread_db interface. */
fa9a4ff0
RM
313extern void __nptl_create_event (void);
314extern void __nptl_death_event (void);
23ce1cf3
FW
315libc_hidden_proto (__nptl_create_event)
316libc_hidden_proto (__nptl_death_event)
76a50749 317
64786a70
ST
318/* The fork generation counter, defined in libpthread. */
319extern unsigned long int __fork_generation attribute_hidden;
320
321/* Pointer to the fork generation counter in the thread library. */
322extern unsigned long int *__fork_generation_pointer attribute_hidden;
323
2c1094bd 324extern size_t __pthread_get_minstack (const pthread_attr_t *attr);
b8cdc3bb 325libc_hidden_proto (__pthread_get_minstack)
76a50749
UD
326
327/* Namespace save aliases. */
8454830b
UD
328extern int __pthread_getschedparam (pthread_t thread_id, int *policy,
329 struct sched_param *param);
d12506b2 330libc_hidden_proto (__pthread_getschedparam)
8454830b
UD
331extern int __pthread_setschedparam (pthread_t thread_id, int policy,
332 const struct sched_param *param);
76a50749 333extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
a784e502 334 const pthread_mutexattr_t *__mutexattr);
27a44822 335libc_hidden_proto (__pthread_mutex_init)
76a50749 336extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
27a44822 337libc_hidden_proto (__pthread_mutex_destroy)
76a50749 338extern int __pthread_mutex_trylock (pthread_mutex_t *_mutex);
a2b0f2e1 339libc_hidden_proto (__pthread_mutex_trylock)
76a50749 340extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
27a44822 341libc_hidden_proto (__pthread_mutex_lock)
fa872e1b
AZ
342extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex,
343 const struct timespec *__abstime);
69431c9a 344extern int __pthread_mutex_cond_lock (pthread_mutex_t *__mutex)
83b09837 345 attribute_hidden;
b0948ffd 346extern void __pthread_mutex_cond_lock_adjust (pthread_mutex_t *__mutex)
83b09837 347 attribute_hidden;
76a50749 348extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
27a44822 349libc_hidden_proto (__pthread_mutex_unlock)
b758b9cb 350extern int __pthread_mutex_unlock_usercnt (pthread_mutex_t *__mutex,
27a44822
FW
351 int __decr);
352libc_hidden_proto (__pthread_mutex_unlock_usercnt)
76a50749 353extern int __pthread_mutexattr_init (pthread_mutexattr_t *attr);
f44c9a24 354libc_hidden_proto (__pthread_mutexattr_init)
76a50749
UD
355extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *attr);
356extern int __pthread_mutexattr_settype (pthread_mutexattr_t *attr, int kind);
f44c9a24 357libc_hidden_proto (__pthread_mutexattr_settype)
8454830b 358extern int __pthread_attr_destroy (pthread_attr_t *attr);
3699ef99 359libc_hidden_proto (__pthread_attr_destroy)
8454830b
UD
360extern int __pthread_attr_getdetachstate (const pthread_attr_t *attr,
361 int *detachstate);
362extern int __pthread_attr_setdetachstate (pthread_attr_t *attr,
363 int detachstate);
364extern int __pthread_attr_getinheritsched (const pthread_attr_t *attr,
365 int *inherit);
366extern int __pthread_attr_setinheritsched (pthread_attr_t *attr, int inherit);
367extern int __pthread_attr_getschedparam (const pthread_attr_t *attr,
368 struct sched_param *param);
369extern int __pthread_attr_setschedparam (pthread_attr_t *attr,
370 const struct sched_param *param);
371extern int __pthread_attr_getschedpolicy (const pthread_attr_t *attr,
372 int *policy);
373extern int __pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy);
374extern int __pthread_attr_getscope (const pthread_attr_t *attr, int *scope);
375extern int __pthread_attr_setscope (pthread_attr_t *attr, int scope);
a784e502 376extern int __pthread_attr_getstackaddr (const pthread_attr_t *__restrict
76a50749
UD
377 __attr, void **__restrict __stackaddr);
378extern int __pthread_attr_setstackaddr (pthread_attr_t *__attr,
379 void *__stackaddr);
a784e502 380extern int __pthread_attr_getstacksize (const pthread_attr_t *__restrict
76a50749
UD
381 __attr,
382 size_t *__restrict __stacksize);
383extern int __pthread_attr_setstacksize (pthread_attr_t *__attr,
384 size_t __stacksize);
a784e502 385extern int __pthread_attr_getstack (const pthread_attr_t *__restrict __attr,
76a50749
UD
386 void **__restrict __stackaddr,
387 size_t *__restrict __stacksize);
388extern int __pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
389 size_t __stacksize);
1979819d
FW
390int __pthread_attr_setaffinity_np (pthread_attr_t *, size_t, const cpu_set_t *);
391libc_hidden_proto (__pthread_attr_setaffinity_np)
dd05e154 392extern __typeof (pthread_getattr_default_np) __pthread_getattr_default_np;
8f72bed1 393libc_hidden_proto (__pthread_getattr_default_np)
76a50749 394extern int __pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
a784e502 395 const pthread_rwlockattr_t *__restrict
76a50749
UD
396 __attr);
397extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock);
398extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock);
eb29dcde 399libc_hidden_proto (__pthread_rwlock_rdlock)
76a50749
UD
400extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock);
401extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock);
eb29dcde 402libc_hidden_proto (__pthread_rwlock_wrlock)
76a50749
UD
403extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
404extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock);
8454830b 405extern int __pthread_cond_broadcast (pthread_cond_t *cond);
08129b15 406libc_hidden_proto (__pthread_cond_broadcast)
8454830b 407extern int __pthread_cond_destroy (pthread_cond_t *cond);
dc6cfdc9 408libc_hidden_proto (__pthread_cond_destroy)
8454830b
UD
409extern int __pthread_cond_init (pthread_cond_t *cond,
410 const pthread_condattr_t *cond_attr);
ad96df2c 411libc_hidden_proto (__pthread_cond_init)
8454830b 412extern int __pthread_cond_signal (pthread_cond_t *cond);
08129b15 413libc_hidden_proto (__pthread_cond_signal)
8454830b 414extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
08129b15 415libc_hidden_proto (__pthread_cond_wait)
4a14cb87
LM
416
417#if __TIMESIZE == 64
418# define __pthread_clockjoin_np64 __pthread_clockjoin_np
419# define __pthread_timedjoin_np64 __pthread_timedjoin_np
323592fd
LM
420# define __pthread_cond_timedwait64 __pthread_cond_timedwait
421# define __pthread_cond_clockwait64 __pthread_cond_clockwait
3102e28b
LM
422# define __pthread_rwlock_clockrdlock64 __pthread_rwlock_clockrdlock
423# define __pthread_rwlock_clockwrlock64 __pthread_rwlock_clockwrlock
424# define __pthread_rwlock_timedrdlock64 __pthread_rwlock_timedrdlock
425# define __pthread_rwlock_timedwrlock64 __pthread_rwlock_timedwrlock
29e9874a
LM
426# define __pthread_mutex_clocklock64 __pthread_mutex_clocklock
427# define __pthread_mutex_timedlock64 __pthread_mutex_timedlock
4a14cb87
LM
428#else
429extern int __pthread_clockjoin_np64 (pthread_t threadid, void **thread_return,
430 clockid_t clockid,
431 const struct __timespec64 *abstime);
ddd4a2d3 432libc_hidden_proto (__pthread_clockjoin_np64)
4a14cb87
LM
433extern int __pthread_timedjoin_np64 (pthread_t threadid, void **thread_return,
434 const struct __timespec64 *abstime);
ddd4a2d3 435libc_hidden_proto (__pthread_timedjoin_np64)
323592fd
LM
436extern int __pthread_cond_timedwait64 (pthread_cond_t *cond,
437 pthread_mutex_t *mutex,
438 const struct __timespec64 *abstime);
08129b15 439libc_hidden_proto (__pthread_cond_timedwait64)
323592fd
LM
440extern int __pthread_cond_clockwait64 (pthread_cond_t *cond,
441 pthread_mutex_t *mutex,
442 clockid_t clockid,
443 const struct __timespec64 *abstime);
08129b15 444libc_hidden_proto (__pthread_cond_clockwait64)
3102e28b
LM
445extern int __pthread_rwlock_clockrdlock64 (pthread_rwlock_t *rwlock,
446 clockid_t clockid,
447 const struct __timespec64 *abstime);
0ace9b19 448libc_hidden_proto (__pthread_rwlock_clockrdlock64)
3102e28b
LM
449extern int __pthread_rwlock_clockwrlock64 (pthread_rwlock_t *rwlock,
450 clockid_t clockid,
451 const struct __timespec64 *abstime);
2cf5b43b 452libc_hidden_proto (__pthread_rwlock_clockwrlock64)
3102e28b
LM
453extern int __pthread_rwlock_timedrdlock64 (pthread_rwlock_t *rwlock,
454 const struct __timespec64 *abstime);
2392feb1 455libc_hidden_proto (__pthread_rwlock_timedrdlock64)
3102e28b
LM
456extern int __pthread_rwlock_timedwrlock64 (pthread_rwlock_t *rwlock,
457 const struct __timespec64 *abstime);
e7d2d48e 458libc_hidden_proto (__pthread_rwlock_timedwrlock64)
29e9874a
LM
459extern int __pthread_mutex_clocklock64 (pthread_mutex_t *mutex,
460 clockid_t clockid,
461 const struct __timespec64 *abstime);
4372dc7e 462libc_hidden_proto (__pthread_mutex_clocklock64)
29e9874a
LM
463extern int __pthread_mutex_timedlock64 (pthread_mutex_t *mutex,
464 const struct __timespec64 *abstime);
4372dc7e 465libc_hidden_proto (__pthread_mutex_timedlock64)
4a14cb87
LM
466#endif
467
b5facfda
UD
468extern int __pthread_cond_timedwait (pthread_cond_t *cond,
469 pthread_mutex_t *mutex,
470 const struct timespec *abstime);
08129b15 471libc_hidden_proto (__pthread_cond_timedwait)
afe4de7d
MC
472extern int __pthread_cond_clockwait (pthread_cond_t *cond,
473 pthread_mutex_t *mutex,
474 clockid_t clockid,
475 const struct timespec *abstime)
476 __nonnull ((1, 2, 4));
08129b15 477libc_hidden_proto (__pthread_cond_clockwait)
4372dc7e
FW
478
479extern int __pthread_mutex_clocklock (pthread_mutex_t *mutex,
480 clockid_t clockid,
481 const struct timespec *abstime);
482libc_hidden_proto (__pthread_mutex_clocklock)
483extern int __pthread_mutex_timedlock (pthread_mutex_t *mutex,
484 const struct timespec *abstime);
485libc_hidden_proto (__pthread_mutex_timedlock)
486
8454830b
UD
487extern int __pthread_condattr_destroy (pthread_condattr_t *attr);
488extern int __pthread_condattr_init (pthread_condattr_t *attr);
76a50749 489extern int __pthread_key_create (pthread_key_t *key, void (*destr) (void *));
e4036b1c 490libc_hidden_proto (__pthread_key_create)
fa872e1b 491extern int __pthread_key_delete (pthread_key_t key);
9ce44f46 492libc_hidden_proto (__pthread_key_delete)
76a50749 493extern void *__pthread_getspecific (pthread_key_t key);
aae43acf 494libc_hidden_proto (__pthread_getspecific)
76a50749 495extern int __pthread_setspecific (pthread_key_t key, const void *value);
64a8990b 496libc_hidden_proto (__pthread_setspecific)
76a50749
UD
497extern int __pthread_once (pthread_once_t *once_control,
498 void (*init_routine) (void));
3fec7f18 499libc_hidden_proto (__pthread_once)
76a50749
UD
500extern int __pthread_atfork (void (*prepare) (void), void (*parent) (void),
501 void (*child) (void));
f779b1ef 502libc_hidden_proto (__pthread_self)
8454830b 503extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
fa872e1b 504extern int __pthread_detach (pthread_t th);
df65f897 505libc_hidden_proto (__pthread_detach)
09efc3ba 506extern int __pthread_kill (pthread_t threadid, int signo);
f779b1ef
AZ
507libc_hidden_proto (__pthread_kill)
508extern int __pthread_cancel (pthread_t th);
a6c813d0
AZ
509extern int __pthread_kill_internal (pthread_t threadid, int signo)
510 attribute_hidden;
356fa562 511extern void __pthread_exit (void *value) __attribute__ ((__noreturn__));
c62cef02 512libc_hidden_proto (__pthread_exit)
fa872e1b 513extern int __pthread_join (pthread_t threadid, void **thread_return);
ddd4a2d3 514libc_hidden_proto (__pthread_join)
09efc3ba 515extern int __pthread_setcanceltype (int type, int *oldtype);
75376a3f 516libc_hidden_proto (__pthread_setcanceltype)
47677f2e 517extern void __pthread_testcancel (void);
0197c1bc 518libc_hidden_proto (__pthread_testcancel)
69ca4b54 519extern int __pthread_clockjoin_ex (pthread_t, void **, clockid_t,
4a14cb87 520 const struct __timespec64 *, bool)
69ca4b54 521 attribute_hidden;
2f6fa801
AZ
522extern int __pthread_sigmask (int, const sigset_t *, sigset_t *);
523libc_hidden_proto (__pthread_sigmask);
69ca4b54 524
9ae0909b 525
ce9f10f7 526#if IS_IN (libpthread)
4d17e683 527hidden_proto (__pthread_rwlock_unlock)
4d17e683
AS
528#endif
529
997256dd
UD
530extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond);
531extern int __pthread_cond_destroy_2_0 (pthread_cond_2_0_t *cond);
532extern int __pthread_cond_init_2_0 (pthread_cond_2_0_t *cond,
05df18c3 533 const pthread_condattr_t *cond_attr);
997256dd
UD
534extern int __pthread_cond_signal_2_0 (pthread_cond_2_0_t *cond);
535extern int __pthread_cond_timedwait_2_0 (pthread_cond_2_0_t *cond,
05df18c3
UD
536 pthread_mutex_t *mutex,
537 const struct timespec *abstime);
997256dd 538extern int __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond,
05df18c3
UD
539 pthread_mutex_t *mutex);
540
439ff07b
UD
541extern int __pthread_getaffinity_np (pthread_t th, size_t cpusetsize,
542 cpu_set_t *cpuset);
52302bc2 543libc_hidden_proto (__pthread_getaffinity_np)
73e9ae88 544
ec41af45
FW
545/* Special internal version of pthread_attr_setsigmask_np which does
546 not filter out internal signals from *SIGMASK. This can be used to
547 launch threads with internal signals blocked. */
548 extern int __pthread_attr_setsigmask_internal (pthread_attr_t *attr,
549 const sigset_t *sigmask);
550libc_hidden_proto (__pthread_attr_setsigmask_internal)
551
552extern __typeof (pthread_attr_getsigmask_np) __pthread_attr_getsigmask_np;
553libc_hidden_proto (__pthread_attr_getsigmask_np)
554
09efc3ba 555/* Special versions which use non-exported functions. */
73e9ae88 556extern void __pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
1f2e5bfe
FW
557 void (*routine) (void *), void *arg);
558libc_hidden_proto (__pthread_cleanup_push)
09efc3ba 559
203c1a89
MS
560/* Replace cleanup macros defined in <pthread.h> with internal
561 versions that don't depend on unwind info and better support
562 cancellation. */
563# undef pthread_cleanup_push
564# define pthread_cleanup_push(routine,arg) \
565 { struct _pthread_cleanup_buffer _buffer; \
566 __pthread_cleanup_push (&_buffer, (routine), (arg));
567
73e9ae88 568extern void __pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
1f2e5bfe
FW
569 int execute);
570libc_hidden_proto (__pthread_cleanup_pop)
203c1a89
MS
571# undef pthread_cleanup_pop
572# define pthread_cleanup_pop(execute) \
573 __pthread_cleanup_pop (&_buffer, (execute)); }
f0419e6a 574
1f2e5bfe 575#if defined __EXCEPTIONS && !defined __cplusplus
f0419e6a
JJ
576/* Structure to hold the cleanup handler information. */
577struct __pthread_cleanup_combined_frame
578{
579 void (*__cancel_routine) (void *);
580 void *__cancel_arg;
581 int __do_it;
582 struct _pthread_cleanup_buffer __buffer;
583};
584
585/* Special cleanup macros which register cleanup both using
586 __pthread_cleanup_{push,pop} and using cleanup attribute. This is needed
587 for pthread_once, so that it supports both throwing exceptions from the
588 pthread_once callback (only cleanup attribute works there) and cancellation
589 of the thread running the callback if the callback or some routines it
590 calls don't have unwind information. */
591
592static __always_inline void
593__pthread_cleanup_combined_routine (struct __pthread_cleanup_combined_frame
594 *__frame)
595{
596 if (__frame->__do_it)
597 {
598 __frame->__cancel_routine (__frame->__cancel_arg);
599 __frame->__do_it = 0;
600 __pthread_cleanup_pop (&__frame->__buffer, 0);
601 }
602}
603
604static inline void
605__pthread_cleanup_combined_routine_voidptr (void *__arg)
606{
607 struct __pthread_cleanup_combined_frame *__frame
608 = (struct __pthread_cleanup_combined_frame *) __arg;
609 if (__frame->__do_it)
610 {
611 __frame->__cancel_routine (__frame->__cancel_arg);
612 __frame->__do_it = 0;
613 }
614}
615
1f2e5bfe 616# define pthread_cleanup_combined_push(routine, arg) \
f0419e6a
JJ
617 do { \
618 void (*__cancel_routine) (void *) = (routine); \
619 struct __pthread_cleanup_combined_frame __clframe \
620 __attribute__ ((__cleanup__ (__pthread_cleanup_combined_routine))) \
621 = { .__cancel_routine = __cancel_routine, .__cancel_arg = (arg), \
622 .__do_it = 1 }; \
623 __pthread_cleanup_push (&__clframe.__buffer, \
624 __pthread_cleanup_combined_routine_voidptr, \
625 &__clframe);
626
1f2e5bfe 627# define pthread_cleanup_combined_pop(execute) \
f0419e6a
JJ
628 __pthread_cleanup_pop (&__clframe.__buffer, 0); \
629 __clframe.__do_it = 0; \
630 if (execute) \
631 __cancel_routine (__clframe.__cancel_arg); \
632 } while (0)
633
1f2e5bfe 634#endif /* __EXCEPTIONS && !defined __cplusplus */
76a50749 635
73e9ae88
UD
636extern void __pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
637 void (*routine) (void *), void *arg);
638extern void __pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
639 int execute);
640
6efd4814
UD
641/* Old cleanup interfaces, still used in libc.so. */
642extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
6f8326ca 643 void (*routine) (void *), void *arg);
6efd4814 644extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
6f8326ca 645 int execute);
6efd4814 646extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
6f8326ca 647 void (*routine) (void *), void *arg);
6efd4814 648extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
6f8326ca 649 int execute);
6efd4814 650
2cfef0b0
FW
651extern void __nptl_deallocate_tsd (void);
652libc_hidden_proto (__nptl_deallocate_tsd)
3fa21fd8 653
486010a3
FW
654void __nptl_setxid_sighandler (int sig, siginfo_t *si, void *ctx);
655libc_hidden_proto (__nptl_setxid_sighandler)
ccd8de9a 656extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden;
2edb61e3 657
df94b641
UD
658extern void __wait_lookup_done (void) attribute_hidden;
659
7538d461
FW
660/* Allocates the extension space for ATTR. Returns an error code on
661 memory allocation failure, zero on success. If ATTR already has an
662 extension space, this function does nothing. */
663int __pthread_attr_extension (struct pthread_attr *attr) attribute_hidden
664 __attribute_warn_unused_result__;
665
b639d0c9
UD
666#ifdef SHARED
667# define PTHREAD_STATIC_FN_REQUIRE(name)
668#else
669# define PTHREAD_STATIC_FN_REQUIRE(name) __asm (".globl " #name);
670#endif
671
331c6e8a
FW
672/* Make a deep copy of the attribute *SOURCE in *TARGET. *TARGET is
673 not assumed to have been initialized. Returns 0 on success, or a
674 positive error code otherwise. */
675int __pthread_attr_copy (pthread_attr_t *target, const pthread_attr_t *source);
676libc_hidden_proto (__pthread_attr_copy)
677
da1304bc
SP
678/* Returns 0 if POL is a valid scheduling policy. */
679static inline int
680check_sched_policy_attr (int pol)
681{
682 if (pol == SCHED_OTHER || pol == SCHED_FIFO || pol == SCHED_RR)
683 return 0;
684
685 return EINVAL;
686}
687
688/* Returns 0 if PR is within the accepted range of priority values for
689 the scheduling policy POL or EINVAL otherwise. */
690static inline int
691check_sched_priority_attr (int pr, int pol)
692{
693 int min = __sched_get_priority_min (pol);
694 int max = __sched_get_priority_max (pol);
695
696 if (min >= 0 && max >= 0 && pr >= min && pr <= max)
697 return 0;
698
699 return EINVAL;
700}
701
702/* Returns 0 if ST is a valid stack size for a thread stack and EINVAL
703 otherwise. */
704static inline int
705check_stacksize_attr (size_t st)
706{
707 if (st >= PTHREAD_STACK_MIN)
708 return 0;
709
710 return EINVAL;
711}
712
72b3c6ee
AZ
713#define ASSERT_TYPE_SIZE(type, size) \
714 _Static_assert (sizeof (type) == size, \
715 "sizeof (" #type ") != " #size)
716
717#define ASSERT_PTHREAD_INTERNAL_SIZE(type, internal) \
a3aaa598 718 _Static_assert (sizeof ((type) { { 0 } }).__size >= sizeof (internal),\
72b3c6ee
AZ
719 "sizeof (" #type ".__size) < sizeof (" #internal ")")
720
dff91cd4
AZ
721#define ASSERT_PTHREAD_STRING(x) __STRING (x)
722#define ASSERT_PTHREAD_INTERNAL_OFFSET(type, member, offset) \
723 _Static_assert (offsetof (type, member) == offset, \
724 "offset of " #member " field of " #type " != " \
725 ASSERT_PTHREAD_STRING (offset))
71d260c1
AZ
726#define ASSERT_PTHREAD_INTERNAL_MEMBER_SIZE(type, member, mtype) \
727 _Static_assert (sizeof (((type) { 0 }).member) != 8, \
728 "sizeof (" #type "." #member ") != sizeof (" #mtype "))")
dff91cd4 729
76a50749 730#endif /* pthreadP.h */