pthreadP.h 22 KB

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