pthreadP.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /* Copyright (C) 2002-2007, 2009 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  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. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _PTHREADP_H
  16. #define _PTHREADP_H 1
  17. #include <pthread.h>
  18. #include <setjmp.h>
  19. #include <stdbool.h>
  20. #include <sys/syscall.h>
  21. #include "descr.h"
  22. #include <tls.h>
  23. #include <lowlevellock.h>
  24. #include <bits/stackinfo.h>
  25. #include <internaltypes.h>
  26. #include <atomic.h>
  27. #include <bits/kernel-features.h>
  28. #include <errno.h>
  29. #include <nptl-signals.h>
  30. /* Atomic operations on TLS memory. */
  31. #ifndef THREAD_ATOMIC_CMPXCHG_VAL
  32. # define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, new, old) \
  33. atomic_compare_and_exchange_val_acq (&(descr)->member, new, old)
  34. #endif
  35. #ifndef THREAD_ATOMIC_BIT_SET
  36. # define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
  37. atomic_bit_set (&(descr)->member, bit)
  38. #endif
  39. /* Adaptive mutex definitions. */
  40. #ifndef MAX_ADAPTIVE_COUNT
  41. # define MAX_ADAPTIVE_COUNT 100
  42. #endif
  43. /* Magic cookie representing robust mutex with dead owner. */
  44. #define PTHREAD_MUTEX_INCONSISTENT INT_MAX
  45. /* Magic cookie representing not recoverable robust mutex. */
  46. #define PTHREAD_MUTEX_NOTRECOVERABLE (INT_MAX - 1)
  47. /* Internal mutex type value. */
  48. enum
  49. {
  50. PTHREAD_MUTEX_KIND_MASK_NP = 3,
  51. PTHREAD_MUTEX_ROBUST_NORMAL_NP = 16,
  52. PTHREAD_MUTEX_ROBUST_RECURSIVE_NP
  53. = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_RECURSIVE_NP,
  54. PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP
  55. = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
  56. PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP
  57. = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
  58. PTHREAD_MUTEX_PRIO_INHERIT_NP = 32,
  59. PTHREAD_MUTEX_PI_NORMAL_NP
  60. = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_NORMAL,
  61. PTHREAD_MUTEX_PI_RECURSIVE_NP
  62. = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_RECURSIVE_NP,
  63. PTHREAD_MUTEX_PI_ERRORCHECK_NP
  64. = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
  65. PTHREAD_MUTEX_PI_ADAPTIVE_NP
  66. = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ADAPTIVE_NP,
  67. PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP
  68. = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_NORMAL_NP,
  69. PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP
  70. = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_RECURSIVE_NP,
  71. PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP
  72. = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP,
  73. PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP
  74. = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP,
  75. PTHREAD_MUTEX_PRIO_PROTECT_NP = 64,
  76. PTHREAD_MUTEX_PP_NORMAL_NP
  77. = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_NORMAL,
  78. PTHREAD_MUTEX_PP_RECURSIVE_NP
  79. = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_RECURSIVE_NP,
  80. PTHREAD_MUTEX_PP_ERRORCHECK_NP
  81. = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ERRORCHECK_NP,
  82. PTHREAD_MUTEX_PP_ADAPTIVE_NP
  83. = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ADAPTIVE_NP
  84. };
  85. #define PTHREAD_MUTEX_PSHARED_BIT 128
  86. #define PTHREAD_MUTEX_TYPE(m) \
  87. ((m)->__data.__kind & 127)
  88. #if LLL_PRIVATE == 0 && LLL_SHARED == 128
  89. # define PTHREAD_MUTEX_PSHARED(m) \
  90. ((m)->__data.__kind & 128)
  91. #else
  92. # define PTHREAD_MUTEX_PSHARED(m) \
  93. (((m)->__data.__kind & 128) ? LLL_SHARED : LLL_PRIVATE)
  94. #endif
  95. /* The kernel when waking robust mutexes on exit never uses
  96. FUTEX_PRIVATE_FLAG FUTEX_WAKE. */
  97. #define PTHREAD_ROBUST_MUTEX_PSHARED(m) LLL_SHARED
  98. /* Ceiling in __data.__lock. __data.__lock is signed, so don't
  99. use the MSB bit in there, but in the mask also include that bit,
  100. so that the compiler can optimize & PTHREAD_MUTEX_PRIO_CEILING_MASK
  101. masking if the value is then shifted down by
  102. PTHREAD_MUTEX_PRIO_CEILING_SHIFT. */
  103. #define PTHREAD_MUTEX_PRIO_CEILING_SHIFT 19
  104. #define PTHREAD_MUTEX_PRIO_CEILING_MASK 0xfff80000
  105. /* Flags in mutex attr. */
  106. #define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT 28
  107. #define PTHREAD_MUTEXATTR_PROTOCOL_MASK 0x30000000
  108. #define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT 12
  109. #define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK 0x00fff000
  110. #define PTHREAD_MUTEXATTR_FLAG_ROBUST 0x40000000
  111. #define PTHREAD_MUTEXATTR_FLAG_PSHARED 0x80000000
  112. #define PTHREAD_MUTEXATTR_FLAG_BITS \
  113. (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \
  114. | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
  115. /* Check whether rwlock prefers readers. */
  116. #define PTHREAD_RWLOCK_PREFER_READER_P(rwlock) \
  117. ((rwlock)->__data.__flags == 0)
  118. /* Bits used in robust mutex implementation. */
  119. #define FUTEX_WAITERS 0x80000000
  120. #define FUTEX_OWNER_DIED 0x40000000
  121. #define FUTEX_TID_MASK 0x3fffffff
  122. /* Internal variables. */
  123. /* Default stack size. */
  124. extern size_t __default_stacksize attribute_hidden;
  125. /* Size and alignment of static TLS block. */
  126. extern size_t __static_tls_size attribute_hidden;
  127. extern size_t __static_tls_align_m1 attribute_hidden;
  128. /* Flag whether the machine is SMP or not. */
  129. extern int __is_smp attribute_hidden;
  130. /* Thread descriptor handling. */
  131. extern list_t __stack_user;
  132. hidden_proto (__stack_user)
  133. /* Attribute handling. */
  134. extern struct pthread_attr *__attr_list attribute_hidden;
  135. extern int __attr_list_lock attribute_hidden;
  136. /* First available RT signal. */
  137. extern int __current_sigrtmin attribute_hidden;
  138. /* Last available RT signal. */
  139. extern int __current_sigrtmax attribute_hidden;
  140. /* Concurrency handling. */
  141. extern int __concurrency_level attribute_hidden;
  142. /* Thread-local data key handling. */
  143. extern struct pthread_key_struct __pthread_keys[PTHREAD_KEYS_MAX];
  144. hidden_proto (__pthread_keys)
  145. /* Number of threads running. */
  146. extern unsigned int __nptl_nthreads
  147. #ifdef SHARED
  148. attribute_hidden
  149. #else
  150. __attribute ((weak))
  151. #endif
  152. ;
  153. #ifndef __ASSUME_SET_ROBUST_LIST
  154. /* Negative if we do not have the system call and we can use it. */
  155. extern int __set_robust_list_avail attribute_hidden;
  156. #endif
  157. /* Thread Priority Protection. */
  158. extern int __sched_fifo_min_prio attribute_hidden;
  159. extern int __sched_fifo_max_prio attribute_hidden;
  160. extern void __init_sched_fifo_prio (void) attribute_hidden;
  161. extern int __pthread_tpp_change_priority (int prev_prio, int new_prio)
  162. attribute_hidden;
  163. extern int __pthread_current_priority (void) attribute_hidden;
  164. /* The library can run in debugging mode where it performs a lot more
  165. tests. */
  166. extern int __pthread_debug attribute_hidden;
  167. /** For now disable debugging support. */
  168. #if 0
  169. # define DEBUGGING_P __builtin_expect (__pthread_debug, 0)
  170. # define INVALID_TD_P(pd) (DEBUGGING_P && __find_in_stack_list (pd) == NULL)
  171. # define INVALID_NOT_TERMINATED_TD_P(pd) INVALID_TD_P (pd)
  172. #else
  173. # define DEBUGGING_P 0
  174. /* Simplified test. This will not catch all invalid descriptors but
  175. is better than nothing. And if the test triggers the thread
  176. descriptor is guaranteed to be invalid. */
  177. # define INVALID_TD_P(pd) __builtin_expect ((pd)->tid <= 0, 0)
  178. # define INVALID_NOT_TERMINATED_TD_P(pd) __builtin_expect ((pd)->tid < 0, 0)
  179. #endif
  180. /* Cancellation test. */
  181. #define CANCELLATION_P(self) \
  182. do { \
  183. cancelhandling = THREAD_GETMEM (self, cancelhandling); \
  184. if (CANCEL_ENABLED_AND_CANCELED (cancelhandling)) \
  185. { \
  186. THREAD_SETMEM (self, result, PTHREAD_CANCELED); \
  187. __do_cancel (); \
  188. } \
  189. } while (0)
  190. extern void __pthread_unwind (__pthread_unwind_buf_t *__buf)
  191. __cleanup_fct_attribute __attribute ((__noreturn__))
  192. #if !defined SHARED && !defined IS_IN_libpthread
  193. weak_function
  194. #endif
  195. ;
  196. extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
  197. __cleanup_fct_attribute __attribute ((__noreturn__))
  198. #ifndef SHARED
  199. weak_function
  200. #endif
  201. ;
  202. extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
  203. __cleanup_fct_attribute;
  204. extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
  205. __cleanup_fct_attribute;
  206. #if defined NOT_IN_libc && defined IS_IN_libpthread
  207. hidden_proto (__pthread_unwind)
  208. hidden_proto (__pthread_unwind_next)
  209. hidden_proto (__pthread_register_cancel)
  210. hidden_proto (__pthread_unregister_cancel)
  211. # ifdef SHARED
  212. extern void attribute_hidden pthread_cancel_init (void);
  213. extern void __unwind_freeres (void);
  214. # endif
  215. #endif
  216. /* Called when a thread reacts on a cancellation request. */
  217. static inline void
  218. __attribute ((noreturn, always_inline))
  219. __do_cancel (void)
  220. {
  221. struct pthread *self = THREAD_SELF;
  222. /* Make sure we get no more cancellations. */
  223. THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
  224. __pthread_unwind ((__pthread_unwind_buf_t *)
  225. THREAD_GETMEM (self, cleanup_jmp_buf));
  226. }
  227. /* Set cancellation mode to asynchronous. */
  228. #define CANCEL_ASYNC() \
  229. __pthread_enable_asynccancel ()
  230. /* Reset to previous cancellation mode. */
  231. #define CANCEL_RESET(oldtype) \
  232. __pthread_disable_asynccancel (oldtype)
  233. #define __LABEL_PREFIX__ __stringify(__USER_LABEL_PREFIX__)
  234. #if !defined NOT_IN_libc
  235. /* Same as CANCEL_ASYNC, but for use in libc.so. */
  236. # define LIBC_CANCEL_ASYNC() \
  237. __libc_enable_asynccancel ()
  238. /* Same as CANCEL_RESET, but for use in libc.so. */
  239. # define LIBC_CANCEL_RESET(oldtype) \
  240. __libc_disable_asynccancel (oldtype)
  241. # define LIBC_CANCEL_HANDLED() \
  242. __asm__ (".globl " __LABEL_PREFIX__ "__libc_enable_asynccancel"); \
  243. __asm__ (".globl " __LABEL_PREFIX__ "__libc_disable_asynccancel")
  244. #elif defined NOT_IN_libc && defined IS_IN_libpthread
  245. # define LIBC_CANCEL_ASYNC() CANCEL_ASYNC ()
  246. # define LIBC_CANCEL_RESET(val) CANCEL_RESET (val)
  247. # define LIBC_CANCEL_HANDLED() \
  248. __asm__ (".globl " __LABEL_PREFIX__ "__pthread_enable_asynccancel"); \
  249. __asm__ (".globl " __LABEL_PREFIX__ "__pthread_disable_asynccancel")
  250. #elif defined NOT_IN_libc && defined IS_IN_librt
  251. # define LIBC_CANCEL_ASYNC() \
  252. __librt_enable_asynccancel ()
  253. # define LIBC_CANCEL_RESET(val) \
  254. __librt_disable_asynccancel (val)
  255. # define LIBC_CANCEL_HANDLED() \
  256. __asm__ (".globl " __LABEL_PREFIX__ "__librt_enable_asynccancel"); \
  257. __asm__ (".globl " __LABEL_PREFIX__ "__librt_disable_asynccancel")
  258. #else
  259. # define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */
  260. # define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */
  261. # define LIBC_CANCEL_HANDLED() /* Nothing. */
  262. #endif
  263. /* Internal prototypes. */
  264. /* Thread list handling. */
  265. extern struct pthread *__find_in_stack_list (struct pthread *pd)
  266. attribute_hidden internal_function;
  267. /* Deallocate a thread's stack after optionally making sure the thread
  268. descriptor is still valid. */
  269. extern void __free_tcb (struct pthread *pd) attribute_hidden internal_function;
  270. /* Free allocated stack. */
  271. extern void __deallocate_stack (struct pthread *pd)
  272. attribute_hidden internal_function;
  273. /* Mark all the stacks except for the current one as available. This
  274. function also re-initializes the lock for the stack cache. */
  275. extern void __reclaim_stacks (void) attribute_hidden;
  276. /* Make all threads's stacks executable. */
  277. extern int __make_stacks_executable (void **stack_endp)
  278. internal_function attribute_hidden;
  279. /* longjmp handling. */
  280. extern void __pthread_cleanup_upto (__jmp_buf target, char *targetframe);
  281. #if defined NOT_IN_libc && defined IS_IN_libpthread
  282. hidden_proto (__pthread_cleanup_upto)
  283. #endif
  284. extern int pthread_create (pthread_t *newthread,
  285. const pthread_attr_t *attr,
  286. void *(*start_routine) (void *), void *arg);
  287. extern int pthread_attr_init (pthread_attr_t *attr);
  288. /* Event handlers for libthread_db interface. */
  289. extern void __nptl_create_event (void);
  290. extern void __nptl_death_event (void);
  291. hidden_proto (__nptl_create_event)
  292. hidden_proto (__nptl_death_event)
  293. /* Register the generation counter in the libpthread with the libc. */
  294. #ifdef TLS_MULTIPLE_THREADS_IN_TCB
  295. extern void __libc_pthread_init (unsigned long int *ptr,
  296. void (*reclaim) (void));
  297. #else
  298. extern int *__libc_pthread_init (unsigned long int *ptr,
  299. void (*reclaim) (void));
  300. /* Variable set to a nonzero value if more than one thread runs or ran. */
  301. extern int __pthread_multiple_threads attribute_hidden;
  302. /* Pointer to the corresponding variable in libc. */
  303. extern int *__libc_multiple_threads_ptr attribute_hidden;
  304. #endif
  305. /* Find a thread given its TID. */
  306. extern struct pthread *__find_thread_by_id (pid_t tid) attribute_hidden
  307. #ifdef SHARED
  308. ;
  309. #else
  310. weak_function;
  311. #define __find_thread_by_id(tid) \
  312. (__find_thread_by_id ? (__find_thread_by_id) (tid) : (struct pthread *) NULL)
  313. #endif
  314. extern void __pthread_init_static_tls (struct link_map *) attribute_hidden;
  315. /* Namespace save aliases. */
  316. extern int __pthread_getschedparam (pthread_t thread_id, int *policy,
  317. struct sched_param *param);
  318. extern int __pthread_setschedparam (pthread_t thread_id, int policy,
  319. const struct sched_param *param);
  320. extern int __pthread_setcancelstate (int state, int *oldstate);
  321. extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
  322. const pthread_mutexattr_t *__mutexattr);
  323. extern int __pthread_mutex_init_internal (pthread_mutex_t *__mutex,
  324. const pthread_mutexattr_t *__mutexattr)
  325. attribute_hidden;
  326. extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
  327. extern int __pthread_mutex_destroy_internal (pthread_mutex_t *__mutex)
  328. attribute_hidden;
  329. extern int __pthread_mutex_trylock (pthread_mutex_t *_mutex);
  330. extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
  331. extern int __pthread_mutex_lock_internal (pthread_mutex_t *__mutex)
  332. attribute_hidden;
  333. extern int __pthread_mutex_cond_lock (pthread_mutex_t *__mutex)
  334. attribute_hidden internal_function;
  335. extern void __pthread_mutex_cond_lock_adjust (pthread_mutex_t *__mutex)
  336. attribute_hidden internal_function;
  337. extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
  338. extern int __pthread_mutex_unlock_internal (pthread_mutex_t *__mutex)
  339. attribute_hidden;
  340. extern int __pthread_mutex_unlock_usercnt (pthread_mutex_t *__mutex,
  341. int __decr)
  342. attribute_hidden internal_function;
  343. extern int __pthread_mutexattr_init (pthread_mutexattr_t *attr);
  344. extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *attr);
  345. extern int __pthread_mutexattr_settype (pthread_mutexattr_t *attr, int kind);
  346. extern int __pthread_attr_destroy (pthread_attr_t *attr);
  347. extern int __pthread_attr_getdetachstate (const pthread_attr_t *attr,
  348. int *detachstate);
  349. extern int __pthread_attr_setdetachstate (pthread_attr_t *attr,
  350. int detachstate);
  351. extern int __pthread_attr_getinheritsched (const pthread_attr_t *attr,
  352. int *inherit);
  353. extern int __pthread_attr_setinheritsched (pthread_attr_t *attr, int inherit);
  354. extern int __pthread_attr_getschedparam (const pthread_attr_t *attr,
  355. struct sched_param *param);
  356. extern int __pthread_attr_setschedparam (pthread_attr_t *attr,
  357. const struct sched_param *param);
  358. extern int __pthread_attr_getschedpolicy (const pthread_attr_t *attr,
  359. int *policy);
  360. extern int __pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy);
  361. extern int __pthread_attr_getscope (const pthread_attr_t *attr, int *scope);
  362. extern int __pthread_attr_setscope (pthread_attr_t *attr, int scope);
  363. extern int __pthread_attr_getstackaddr (const pthread_attr_t *__restrict
  364. __attr, void **__restrict __stackaddr);
  365. extern int __pthread_attr_setstackaddr (pthread_attr_t *__attr,
  366. void *__stackaddr);
  367. extern int __pthread_attr_getstacksize (const pthread_attr_t *__restrict
  368. __attr,
  369. size_t *__restrict __stacksize);
  370. extern int __pthread_attr_setstacksize (pthread_attr_t *__attr,
  371. size_t __stacksize);
  372. extern int __pthread_attr_getstack (const pthread_attr_t *__restrict __attr,
  373. void **__restrict __stackaddr,
  374. size_t *__restrict __stacksize);
  375. extern int __pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
  376. size_t __stacksize);
  377. extern int __pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
  378. const pthread_rwlockattr_t *__restrict
  379. __attr);
  380. extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock);
  381. extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock);
  382. extern int __pthread_rwlock_rdlock_internal (pthread_rwlock_t *__rwlock);
  383. extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock);
  384. extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock);
  385. extern int __pthread_rwlock_wrlock_internal (pthread_rwlock_t *__rwlock);
  386. extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
  387. extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock);
  388. extern int __pthread_rwlock_unlock_internal (pthread_rwlock_t *__rwlock);
  389. extern int __pthread_cond_broadcast (pthread_cond_t *cond);
  390. extern int __pthread_cond_destroy (pthread_cond_t *cond);
  391. extern int __pthread_cond_init (pthread_cond_t *cond,
  392. const pthread_condattr_t *cond_attr);
  393. extern int __pthread_cond_signal (pthread_cond_t *cond);
  394. extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
  395. extern int __pthread_cond_timedwait (pthread_cond_t *cond,
  396. pthread_mutex_t *mutex,
  397. const struct timespec *abstime);
  398. extern int __pthread_condattr_destroy (pthread_condattr_t *attr);
  399. extern int __pthread_condattr_init (pthread_condattr_t *attr);
  400. extern int __pthread_key_create (pthread_key_t *key, void (*destr) (void *));
  401. extern int __pthread_key_create_internal (pthread_key_t *key,
  402. void (*destr) (void *));
  403. extern void *__pthread_getspecific (pthread_key_t key);
  404. extern void *__pthread_getspecific_internal (pthread_key_t key);
  405. extern int __pthread_setspecific (pthread_key_t key, const void *value);
  406. extern int __pthread_setspecific_internal (pthread_key_t key,
  407. const void *value);
  408. extern int __pthread_once (pthread_once_t *once_control,
  409. void (*init_routine) (void));
  410. extern int __pthread_once_internal (pthread_once_t *once_control,
  411. void (*init_routine) (void));
  412. extern int __pthread_atfork (void (*prepare) (void), void (*parent) (void),
  413. void (*child) (void));
  414. extern pthread_t __pthread_self (void);
  415. extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
  416. extern int __pthread_kill (pthread_t threadid, int signo);
  417. extern void __pthread_exit (void *value);
  418. extern int __pthread_setcanceltype (int type, int *oldtype);
  419. extern int __pthread_enable_asynccancel (void) attribute_hidden;
  420. extern void __pthread_disable_asynccancel (int oldtype)
  421. internal_function attribute_hidden;
  422. extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond);
  423. extern int __pthread_cond_destroy_2_0 (pthread_cond_2_0_t *cond);
  424. extern int __pthread_cond_init_2_0 (pthread_cond_2_0_t *cond,
  425. const pthread_condattr_t *cond_attr);
  426. extern int __pthread_cond_signal_2_0 (pthread_cond_2_0_t *cond);
  427. extern int __pthread_cond_timedwait_2_0 (pthread_cond_2_0_t *cond,
  428. pthread_mutex_t *mutex,
  429. const struct timespec *abstime);
  430. extern int __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond,
  431. pthread_mutex_t *mutex);
  432. extern int __pthread_getaffinity_np (pthread_t th, size_t cpusetsize,
  433. cpu_set_t *cpuset);
  434. /* The two functions are in libc.so and not exported. */
  435. extern int __libc_enable_asynccancel (void) attribute_hidden;
  436. extern void __libc_disable_asynccancel (int oldtype)
  437. internal_function attribute_hidden;
  438. /* The two functions are in librt.so and not exported. */
  439. extern int __librt_enable_asynccancel (void) attribute_hidden;
  440. extern void __librt_disable_asynccancel (int oldtype)
  441. internal_function attribute_hidden;
  442. #ifdef IS_IN_libpthread
  443. /* Special versions which use non-exported functions. */
  444. extern void __pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
  445. void (*routine) (void *), void *arg)
  446. attribute_hidden;
  447. # undef pthread_cleanup_push
  448. # define pthread_cleanup_push(routine,arg) \
  449. { struct _pthread_cleanup_buffer _buffer; \
  450. __pthread_cleanup_push (&_buffer, (routine), (arg));
  451. extern void __pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
  452. int execute) attribute_hidden;
  453. # undef pthread_cleanup_pop
  454. # define pthread_cleanup_pop(execute) \
  455. __pthread_cleanup_pop (&_buffer, (execute)); }
  456. #endif
  457. extern void __pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
  458. void (*routine) (void *), void *arg);
  459. extern void __pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
  460. int execute);
  461. /* Old cleanup interfaces, still used in libc.so. */
  462. extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
  463. void (*routine) (void *), void *arg);
  464. extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
  465. int execute);
  466. extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
  467. void (*routine) (void *), void *arg);
  468. extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
  469. int execute);
  470. extern void __nptl_deallocate_tsd (void)
  471. #ifdef SHARED
  472. attribute_hidden
  473. #else
  474. __attribute ((weak))
  475. #endif
  476. ;
  477. extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden;
  478. extern void __free_stacks (size_t limit) attribute_hidden;
  479. extern void __wait_lookup_done (void) attribute_hidden;
  480. #ifdef SHARED
  481. # define PTHREAD_STATIC_FN_REQUIRE(name)
  482. #else
  483. # define PTHREAD_STATIC_FN_REQUIRE(name) __asm__ (".globl " #name);
  484. #endif
  485. #ifndef __NR_set_robust_list
  486. /* XXX For the time being... Once we can rely on the kernel headers
  487. having the definition remove these lines. */
  488. # if defined __i386__
  489. # define __NR_set_robust_list 311
  490. # elif defined __x86_64__
  491. # define __NR_set_robust_list 273
  492. # endif
  493. #endif
  494. #endif /* pthreadP.h */