Remove declarations of two nonexistent variables from nptl/pthreadP.h.
[glibc.git] / nptl / pthreadP.h
blob6069be93c33f6ab7684f1baca3046d36353f2340
1 /* Copyright (C) 2002-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _PTHREADP_H
20 #define _PTHREADP_H 1
22 #include <pthread.h>
23 #include <setjmp.h>
24 #include <stdbool.h>
25 #include <sys/syscall.h>
26 #include "descr.h"
27 #include <tls.h>
28 #include <lowlevellock.h>
29 #include <stackinfo.h>
30 #include <internaltypes.h>
31 #include <pthread-functions.h>
32 #include <atomic.h>
33 #include <kernel-features.h>
34 #include <errno.h>
36 /* Atomic operations on TLS memory. */
37 #ifndef THREAD_ATOMIC_CMPXCHG_VAL
38 # define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, new, old) \
39 atomic_compare_and_exchange_val_acq (&(descr)->member, new, old)
40 #endif
42 #ifndef THREAD_ATOMIC_BIT_SET
43 # define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
44 atomic_bit_set (&(descr)->member, bit)
45 #endif
48 /* Adaptive mutex definitions. */
49 #ifndef MAX_ADAPTIVE_COUNT
50 # define MAX_ADAPTIVE_COUNT 100
51 #endif
54 /* Magic cookie representing robust mutex with dead owner. */
55 #define PTHREAD_MUTEX_INCONSISTENT INT_MAX
56 /* Magic cookie representing not recoverable robust mutex. */
57 #define PTHREAD_MUTEX_NOTRECOVERABLE (INT_MAX - 1)
60 /* Internal mutex type value. */
61 enum
63 PTHREAD_MUTEX_KIND_MASK_NP = 3,
65 PTHREAD_MUTEX_ELISION_NP = 256,
66 PTHREAD_MUTEX_NO_ELISION_NP = 512,
68 PTHREAD_MUTEX_ROBUST_NORMAL_NP = 16,
69 PTHREAD_MUTEX_ROBUST_RECURSIVE_NP
70 = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_RECURSIVE_NP,
71 PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP
72 = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
73 PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP
74 = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
75 PTHREAD_MUTEX_PRIO_INHERIT_NP = 32,
76 PTHREAD_MUTEX_PI_NORMAL_NP
77 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_NORMAL,
78 PTHREAD_MUTEX_PI_RECURSIVE_NP
79 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_RECURSIVE_NP,
80 PTHREAD_MUTEX_PI_ERRORCHECK_NP
81 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
82 PTHREAD_MUTEX_PI_ADAPTIVE_NP
83 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
84 PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP
85 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_NORMAL_NP,
86 PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP
87 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_RECURSIVE_NP,
88 PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP
89 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP,
90 PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP
91 = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP,
92 PTHREAD_MUTEX_PRIO_PROTECT_NP = 64,
93 PTHREAD_MUTEX_PP_NORMAL_NP
94 = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_NORMAL,
95 PTHREAD_MUTEX_PP_RECURSIVE_NP
96 = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_RECURSIVE_NP,
97 PTHREAD_MUTEX_PP_ERRORCHECK_NP
98 = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
99 PTHREAD_MUTEX_PP_ADAPTIVE_NP
100 = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
101 PTHREAD_MUTEX_ELISION_FLAGS_NP
102 = PTHREAD_MUTEX_ELISION_NP | PTHREAD_MUTEX_NO_ELISION_NP,
104 PTHREAD_MUTEX_TIMED_ELISION_NP =
105 PTHREAD_MUTEX_TIMED_NP | PTHREAD_MUTEX_ELISION_NP,
106 PTHREAD_MUTEX_TIMED_NO_ELISION_NP =
107 PTHREAD_MUTEX_TIMED_NP | PTHREAD_MUTEX_NO_ELISION_NP,
109 #define PTHREAD_MUTEX_PSHARED_BIT 128
111 #define PTHREAD_MUTEX_TYPE(m) \
112 ((m)->__data.__kind & 127)
113 /* Don't include NO_ELISION, as that type is always the same
114 as the underlying lock type. */
115 #define PTHREAD_MUTEX_TYPE_ELISION(m) \
116 ((m)->__data.__kind & (127|PTHREAD_MUTEX_ELISION_NP))
118 #if LLL_PRIVATE == 0 && LLL_SHARED == 128
119 # define PTHREAD_MUTEX_PSHARED(m) \
120 ((m)->__data.__kind & 128)
121 #else
122 # define PTHREAD_MUTEX_PSHARED(m) \
123 (((m)->__data.__kind & 128) ? LLL_SHARED : LLL_PRIVATE)
124 #endif
126 /* The kernel when waking robust mutexes on exit never uses
127 FUTEX_PRIVATE_FLAG FUTEX_WAKE. */
128 #define PTHREAD_ROBUST_MUTEX_PSHARED(m) LLL_SHARED
130 /* Ceiling in __data.__lock. __data.__lock is signed, so don't
131 use the MSB bit in there, but in the mask also include that bit,
132 so that the compiler can optimize & PTHREAD_MUTEX_PRIO_CEILING_MASK
133 masking if the value is then shifted down by
134 PTHREAD_MUTEX_PRIO_CEILING_SHIFT. */
135 #define PTHREAD_MUTEX_PRIO_CEILING_SHIFT 19
136 #define PTHREAD_MUTEX_PRIO_CEILING_MASK 0xfff80000
139 /* Flags in mutex attr. */
140 #define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT 28
141 #define PTHREAD_MUTEXATTR_PROTOCOL_MASK 0x30000000
142 #define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT 12
143 #define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK 0x00fff000
144 #define PTHREAD_MUTEXATTR_FLAG_ROBUST 0x40000000
145 #define PTHREAD_MUTEXATTR_FLAG_PSHARED 0x80000000
146 #define PTHREAD_MUTEXATTR_FLAG_BITS \
147 (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \
148 | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
151 /* Check whether rwlock prefers readers. */
152 #define PTHREAD_RWLOCK_PREFER_READER_P(rwlock) \
153 ((rwlock)->__data.__flags == 0)
156 /* Bits used in robust mutex implementation. */
157 #define FUTEX_WAITERS 0x80000000
158 #define FUTEX_OWNER_DIED 0x40000000
159 #define FUTEX_TID_MASK 0x3fffffff
162 /* Internal variables. */
165 /* Default pthread attributes. */
166 extern struct pthread_attr __default_pthread_attr attribute_hidden;
167 extern int __default_pthread_attr_lock attribute_hidden;
169 /* Size and alignment of static TLS block. */
170 extern size_t __static_tls_size attribute_hidden;
171 extern size_t __static_tls_align_m1 attribute_hidden;
173 /* Flag whether the machine is SMP or not. */
174 extern int __is_smp attribute_hidden;
176 /* Thread descriptor handling. */
177 extern list_t __stack_user;
178 hidden_proto (__stack_user)
180 /* Attribute handling. */
181 extern struct pthread_attr *__attr_list attribute_hidden;
182 extern int __attr_list_lock attribute_hidden;
184 /* Concurrency handling. */
185 extern int __concurrency_level attribute_hidden;
187 /* Thread-local data key handling. */
188 extern struct pthread_key_struct __pthread_keys[PTHREAD_KEYS_MAX];
189 hidden_proto (__pthread_keys)
191 /* Number of threads running. */
192 extern unsigned int __nptl_nthreads attribute_hidden;
194 #ifndef __ASSUME_SET_ROBUST_LIST
195 /* Negative if we do not have the system call and we can use it. */
196 extern int __set_robust_list_avail attribute_hidden;
197 #endif
199 /* Thread Priority Protection. */
200 extern int __sched_fifo_min_prio attribute_hidden;
201 extern int __sched_fifo_max_prio attribute_hidden;
202 extern void __init_sched_fifo_prio (void) attribute_hidden;
203 extern int __pthread_tpp_change_priority (int prev_prio, int new_prio)
204 attribute_hidden;
205 extern int __pthread_current_priority (void) attribute_hidden;
207 /* The library can run in debugging mode where it performs a lot more
208 tests. */
209 extern int __pthread_debug attribute_hidden;
210 /** For now disable debugging support. */
211 #if 0
212 # define DEBUGGING_P __builtin_expect (__pthread_debug, 0)
213 # define INVALID_TD_P(pd) (DEBUGGING_P && __find_in_stack_list (pd) == NULL)
214 # define INVALID_NOT_TERMINATED_TD_P(pd) INVALID_TD_P (pd)
215 #else
216 # define DEBUGGING_P 0
217 /* Simplified test. This will not catch all invalid descriptors but
218 is better than nothing. And if the test triggers the thread
219 descriptor is guaranteed to be invalid. */
220 # define INVALID_TD_P(pd) __builtin_expect ((pd)->tid <= 0, 0)
221 # define INVALID_NOT_TERMINATED_TD_P(pd) __builtin_expect ((pd)->tid < 0, 0)
222 #endif
225 /* Cancellation test. */
226 #define CANCELLATION_P(self) \
227 do { \
228 int cancelhandling = THREAD_GETMEM (self, cancelhandling); \
229 if (CANCEL_ENABLED_AND_CANCELED (cancelhandling)) \
231 THREAD_SETMEM (self, result, PTHREAD_CANCELED); \
232 __do_cancel (); \
234 } while (0)
237 extern void __pthread_unwind (__pthread_unwind_buf_t *__buf)
238 __cleanup_fct_attribute __attribute ((__noreturn__))
239 #if !defined SHARED && !defined IS_IN_libpthread
240 weak_function
241 #endif
243 extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
244 __cleanup_fct_attribute __attribute ((__noreturn__))
245 #ifndef SHARED
246 weak_function
247 #endif
249 extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
250 __cleanup_fct_attribute;
251 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
252 __cleanup_fct_attribute;
253 #if defined NOT_IN_libc && defined IS_IN_libpthread
254 hidden_proto (__pthread_unwind)
255 hidden_proto (__pthread_unwind_next)
256 hidden_proto (__pthread_register_cancel)
257 hidden_proto (__pthread_unregister_cancel)
258 # ifdef SHARED
259 extern void attribute_hidden pthread_cancel_init (void);
260 extern void __unwind_freeres (void);
261 # endif
262 #endif
265 /* Called when a thread reacts on a cancellation request. */
266 static inline void
267 __attribute ((noreturn, always_inline))
268 __do_cancel (void)
270 struct pthread *self = THREAD_SELF;
272 /* Make sure we get no more cancellations. */
273 THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
275 __pthread_unwind ((__pthread_unwind_buf_t *)
276 THREAD_GETMEM (self, cleanup_jmp_buf));
280 /* Set cancellation mode to asynchronous. */
281 #define CANCEL_ASYNC() \
282 __pthread_enable_asynccancel ()
283 /* Reset to previous cancellation mode. */
284 #define CANCEL_RESET(oldtype) \
285 __pthread_disable_asynccancel (oldtype)
287 #if !defined NOT_IN_libc
288 /* Same as CANCEL_ASYNC, but for use in libc.so. */
289 # define LIBC_CANCEL_ASYNC() \
290 __libc_enable_asynccancel ()
291 /* Same as CANCEL_RESET, but for use in libc.so. */
292 # define LIBC_CANCEL_RESET(oldtype) \
293 __libc_disable_asynccancel (oldtype)
294 # define LIBC_CANCEL_HANDLED() \
295 __asm (".globl " __SYMBOL_PREFIX "__libc_enable_asynccancel"); \
296 __asm (".globl " __SYMBOL_PREFIX "__libc_disable_asynccancel")
297 #elif defined NOT_IN_libc && defined IS_IN_libpthread
298 # define LIBC_CANCEL_ASYNC() CANCEL_ASYNC ()
299 # define LIBC_CANCEL_RESET(val) CANCEL_RESET (val)
300 # define LIBC_CANCEL_HANDLED() \
301 __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \
302 __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel")
303 #elif defined NOT_IN_libc && defined IS_IN_librt
304 # define LIBC_CANCEL_ASYNC() \
305 __librt_enable_asynccancel ()
306 # define LIBC_CANCEL_RESET(val) \
307 __librt_disable_asynccancel (val)
308 # define LIBC_CANCEL_HANDLED() \
309 __asm (".globl " __SYMBOL_PREFIX "__librt_enable_asynccancel"); \
310 __asm (".globl " __SYMBOL_PREFIX "__librt_disable_asynccancel")
311 #else
312 # define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */
313 # define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */
314 # define LIBC_CANCEL_HANDLED() /* Nothing. */
315 #endif
317 /* The signal used for asynchronous cancelation. */
318 #define SIGCANCEL __SIGRTMIN
321 /* Signal needed for the kernel-supported POSIX timer implementation.
322 We can reuse the cancellation signal since we can distinguish
323 cancellation from timer expirations. */
324 #define SIGTIMER SIGCANCEL
327 /* Signal used to implement the setuid et.al. functions. */
328 #define SIGSETXID (__SIGRTMIN + 1)
330 /* Used to communicate with signal handler. */
331 extern struct xid_command *__xidcmd attribute_hidden;
334 /* Internal prototypes. */
336 /* Thread list handling. */
337 extern struct pthread *__find_in_stack_list (struct pthread *pd)
338 attribute_hidden internal_function;
340 /* Deallocate a thread's stack after optionally making sure the thread
341 descriptor is still valid. */
342 extern void __free_tcb (struct pthread *pd) attribute_hidden internal_function;
344 /* Free allocated stack. */
345 extern void __deallocate_stack (struct pthread *pd)
346 attribute_hidden internal_function;
348 /* Mark all the stacks except for the current one as available. This
349 function also re-initializes the lock for the stack cache. */
350 extern void __reclaim_stacks (void) attribute_hidden;
352 /* Make all threads's stacks executable. */
353 extern int __make_stacks_executable (void **stack_endp)
354 internal_function attribute_hidden;
356 /* longjmp handling. */
357 extern void __pthread_cleanup_upto (__jmp_buf target, char *targetframe);
358 #if defined NOT_IN_libc && defined IS_IN_libpthread
359 hidden_proto (__pthread_cleanup_upto)
360 #endif
363 /* Functions with versioned interfaces. */
364 extern int __pthread_create_2_1 (pthread_t *newthread,
365 const pthread_attr_t *attr,
366 void *(*start_routine) (void *), void *arg);
367 extern int __pthread_create_2_0 (pthread_t *newthread,
368 const pthread_attr_t *attr,
369 void *(*start_routine) (void *), void *arg);
370 extern int __pthread_attr_init_2_1 (pthread_attr_t *attr);
371 extern int __pthread_attr_init_2_0 (pthread_attr_t *attr);
374 /* Event handlers for libthread_db interface. */
375 extern void __nptl_create_event (void);
376 extern void __nptl_death_event (void);
377 hidden_proto (__nptl_create_event)
378 hidden_proto (__nptl_death_event)
380 /* Register the generation counter in the libpthread with the libc. */
381 #ifdef TLS_MULTIPLE_THREADS_IN_TCB
382 extern void __libc_pthread_init (unsigned long int *ptr,
383 void (*reclaim) (void),
384 const struct pthread_functions *functions)
385 internal_function;
386 #else
387 extern int *__libc_pthread_init (unsigned long int *ptr,
388 void (*reclaim) (void),
389 const struct pthread_functions *functions)
390 internal_function;
392 /* Variable set to a nonzero value either if more than one thread runs or ran,
393 or if a single-threaded process is trying to cancel itself. See
394 nptl/descr.h for more context on the single-threaded process case. */
395 extern int __pthread_multiple_threads attribute_hidden;
396 /* Pointer to the corresponding variable in libc. */
397 extern int *__libc_multiple_threads_ptr attribute_hidden;
398 #endif
400 /* Find a thread given its TID. */
401 extern struct pthread *__find_thread_by_id (pid_t tid) attribute_hidden
402 #ifdef SHARED
404 #else
405 weak_function;
406 #define __find_thread_by_id(tid) \
407 (__find_thread_by_id ? (__find_thread_by_id) (tid) : (struct pthread *) NULL)
408 #endif
410 extern void __pthread_init_static_tls (struct link_map *) attribute_hidden;
412 extern size_t __pthread_get_minstack (const pthread_attr_t *attr);
414 /* Namespace save aliases. */
415 extern int __pthread_getschedparam (pthread_t thread_id, int *policy,
416 struct sched_param *param);
417 extern int __pthread_setschedparam (pthread_t thread_id, int policy,
418 const struct sched_param *param);
419 extern int __pthread_setcancelstate (int state, int *oldstate);
420 extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
421 const pthread_mutexattr_t *__mutexattr);
422 extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
423 extern int __pthread_mutex_trylock (pthread_mutex_t *_mutex);
424 extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
425 extern int __pthread_mutex_cond_lock (pthread_mutex_t *__mutex)
426 attribute_hidden internal_function;
427 extern void __pthread_mutex_cond_lock_adjust (pthread_mutex_t *__mutex)
428 attribute_hidden internal_function;
429 extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
430 extern int __pthread_mutex_unlock_usercnt (pthread_mutex_t *__mutex,
431 int __decr)
432 attribute_hidden internal_function;
433 extern int __pthread_mutexattr_init (pthread_mutexattr_t *attr);
434 extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *attr);
435 extern int __pthread_mutexattr_settype (pthread_mutexattr_t *attr, int kind);
436 extern int __pthread_attr_destroy (pthread_attr_t *attr);
437 extern int __pthread_attr_getdetachstate (const pthread_attr_t *attr,
438 int *detachstate);
439 extern int __pthread_attr_setdetachstate (pthread_attr_t *attr,
440 int detachstate);
441 extern int __pthread_attr_getinheritsched (const pthread_attr_t *attr,
442 int *inherit);
443 extern int __pthread_attr_setinheritsched (pthread_attr_t *attr, int inherit);
444 extern int __pthread_attr_getschedparam (const pthread_attr_t *attr,
445 struct sched_param *param);
446 extern int __pthread_attr_setschedparam (pthread_attr_t *attr,
447 const struct sched_param *param);
448 extern int __pthread_attr_getschedpolicy (const pthread_attr_t *attr,
449 int *policy);
450 extern int __pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy);
451 extern int __pthread_attr_getscope (const pthread_attr_t *attr, int *scope);
452 extern int __pthread_attr_setscope (pthread_attr_t *attr, int scope);
453 extern int __pthread_attr_getstackaddr (const pthread_attr_t *__restrict
454 __attr, void **__restrict __stackaddr);
455 extern int __pthread_attr_setstackaddr (pthread_attr_t *__attr,
456 void *__stackaddr);
457 extern int __pthread_attr_getstacksize (const pthread_attr_t *__restrict
458 __attr,
459 size_t *__restrict __stacksize);
460 extern int __pthread_attr_setstacksize (pthread_attr_t *__attr,
461 size_t __stacksize);
462 extern int __pthread_attr_getstack (const pthread_attr_t *__restrict __attr,
463 void **__restrict __stackaddr,
464 size_t *__restrict __stacksize);
465 extern int __pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
466 size_t __stacksize);
467 extern int __pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
468 const pthread_rwlockattr_t *__restrict
469 __attr);
470 extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock);
471 extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock);
472 extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock);
473 extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock);
474 extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
475 extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock);
476 extern int __pthread_cond_broadcast (pthread_cond_t *cond);
477 extern int __pthread_cond_destroy (pthread_cond_t *cond);
478 extern int __pthread_cond_init (pthread_cond_t *cond,
479 const pthread_condattr_t *cond_attr);
480 extern int __pthread_cond_signal (pthread_cond_t *cond);
481 extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
482 extern int __pthread_cond_timedwait (pthread_cond_t *cond,
483 pthread_mutex_t *mutex,
484 const struct timespec *abstime);
485 extern int __pthread_condattr_destroy (pthread_condattr_t *attr);
486 extern int __pthread_condattr_init (pthread_condattr_t *attr);
487 extern int __pthread_key_create (pthread_key_t *key, void (*destr) (void *));
488 extern void *__pthread_getspecific (pthread_key_t key);
489 extern int __pthread_setspecific (pthread_key_t key, const void *value);
490 extern int __pthread_once (pthread_once_t *once_control,
491 void (*init_routine) (void));
492 extern int __pthread_atfork (void (*prepare) (void), void (*parent) (void),
493 void (*child) (void));
494 extern pthread_t __pthread_self (void);
495 extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
496 extern int __pthread_kill (pthread_t threadid, int signo);
497 extern void __pthread_exit (void *value) __attribute__ ((__noreturn__));
498 extern int __pthread_setcanceltype (int type, int *oldtype);
499 extern int __pthread_enable_asynccancel (void) attribute_hidden;
500 extern void __pthread_disable_asynccancel (int oldtype)
501 internal_function attribute_hidden;
503 #if defined NOT_IN_libc && defined IS_IN_libpthread
504 hidden_proto (__pthread_mutex_init)
505 hidden_proto (__pthread_mutex_destroy)
506 hidden_proto (__pthread_mutex_lock)
507 hidden_proto (__pthread_mutex_unlock)
508 hidden_proto (__pthread_rwlock_rdlock)
509 hidden_proto (__pthread_rwlock_wrlock)
510 hidden_proto (__pthread_rwlock_unlock)
511 hidden_proto (__pthread_key_create)
512 hidden_proto (__pthread_getspecific)
513 hidden_proto (__pthread_setspecific)
514 hidden_proto (__pthread_once)
515 #endif
517 extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond);
518 extern int __pthread_cond_destroy_2_0 (pthread_cond_2_0_t *cond);
519 extern int __pthread_cond_init_2_0 (pthread_cond_2_0_t *cond,
520 const pthread_condattr_t *cond_attr);
521 extern int __pthread_cond_signal_2_0 (pthread_cond_2_0_t *cond);
522 extern int __pthread_cond_timedwait_2_0 (pthread_cond_2_0_t *cond,
523 pthread_mutex_t *mutex,
524 const struct timespec *abstime);
525 extern int __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond,
526 pthread_mutex_t *mutex);
528 extern int __pthread_getaffinity_np (pthread_t th, size_t cpusetsize,
529 cpu_set_t *cpuset);
531 /* The two functions are in libc.so and not exported. */
532 extern int __libc_enable_asynccancel (void) attribute_hidden;
533 extern void __libc_disable_asynccancel (int oldtype)
534 internal_function attribute_hidden;
537 /* The two functions are in librt.so and not exported. */
538 extern int __librt_enable_asynccancel (void) attribute_hidden;
539 extern void __librt_disable_asynccancel (int oldtype)
540 internal_function attribute_hidden;
542 #ifdef IS_IN_libpthread
543 /* Special versions which use non-exported functions. */
544 extern void __pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
545 void (*routine) (void *), void *arg)
546 attribute_hidden;
547 # undef pthread_cleanup_push
548 # define pthread_cleanup_push(routine,arg) \
549 { struct _pthread_cleanup_buffer _buffer; \
550 __pthread_cleanup_push (&_buffer, (routine), (arg));
552 extern void __pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
553 int execute) attribute_hidden;
554 # undef pthread_cleanup_pop
555 # define pthread_cleanup_pop(execute) \
556 __pthread_cleanup_pop (&_buffer, (execute)); }
557 #endif
559 extern void __pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
560 void (*routine) (void *), void *arg);
561 extern void __pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
562 int execute);
564 /* Old cleanup interfaces, still used in libc.so. */
565 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
566 void (*routine) (void *), void *arg);
567 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
568 int execute);
569 extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
570 void (*routine) (void *), void *arg);
571 extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
572 int execute);
574 extern void __nptl_deallocate_tsd (void) attribute_hidden;
576 extern void __nptl_setxid_error (struct xid_command *cmdp, int error)
577 attribute_hidden;
578 extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden;
579 #ifndef SHARED
580 extern void __nptl_set_robust (struct pthread *self);
581 #endif
583 extern void __free_stacks (size_t limit) attribute_hidden;
585 extern void __wait_lookup_done (void) attribute_hidden;
587 #ifdef SHARED
588 # define PTHREAD_STATIC_FN_REQUIRE(name)
589 #else
590 # define PTHREAD_STATIC_FN_REQUIRE(name) __asm (".globl " #name);
591 #endif
593 /* Test if the mutex is suitable for the FUTEX_WAIT_REQUEUE_PI operation. */
594 #if (defined lll_futex_wait_requeue_pi \
595 && defined __ASSUME_REQUEUE_PI)
596 # define USE_REQUEUE_PI(mut) \
597 ((mut) && (mut) != (void *) ~0l \
598 && (((mut)->__data.__kind \
599 & (PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_NORMAL_NP)) \
600 == PTHREAD_MUTEX_PRIO_INHERIT_NP))
601 #else
602 # define USE_REQUEUE_PI(mut) 0
603 #endif
605 /* Returns 0 if POL is a valid scheduling policy. */
606 static inline int
607 check_sched_policy_attr (int pol)
609 if (pol == SCHED_OTHER || pol == SCHED_FIFO || pol == SCHED_RR)
610 return 0;
612 return EINVAL;
615 /* Returns 0 if PR is within the accepted range of priority values for
616 the scheduling policy POL or EINVAL otherwise. */
617 static inline int
618 check_sched_priority_attr (int pr, int pol)
620 int min = __sched_get_priority_min (pol);
621 int max = __sched_get_priority_max (pol);
623 if (min >= 0 && max >= 0 && pr >= min && pr <= max)
624 return 0;
626 return EINVAL;
629 /* Returns 0 if ST is a valid stack size for a thread stack and EINVAL
630 otherwise. */
631 static inline int
632 check_stacksize_attr (size_t st)
634 if (st >= PTHREAD_STACK_MIN)
635 return 0;
637 return EINVAL;
640 /* Defined in pthread_setaffinity.c. */
641 extern size_t __kernel_cpumask_size attribute_hidden;
642 extern int __determine_cpumask_size (pid_t tid);
644 /* Returns 0 if CS and SZ are valid values for the cpuset and cpuset size
645 respectively. Otherwise it returns an error number. */
646 static inline int
647 check_cpuset_attr (const cpu_set_t *cs, const size_t sz)
649 if (__kernel_cpumask_size == 0)
651 int res = __determine_cpumask_size (THREAD_SELF->tid);
652 if (res)
653 return res;
656 /* Check whether the new bitmask has any bit set beyond the
657 last one the kernel accepts. */
658 for (size_t cnt = __kernel_cpumask_size; cnt < sz; ++cnt)
659 if (((char *) cs)[cnt] != '\0')
660 /* Found a nonzero byte. This means the user request cannot be
661 fulfilled. */
662 return EINVAL;
664 return 0;
667 #endif /* pthreadP.h */