libc-lock.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /* libc-internal interface for mutex locks. NPTL version.
  2. Copyright (C) 1996-2003, 2005, 2007 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  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 License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. 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; see the file COPYING.LIB. If
  14. not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef _BITS_LIBC_LOCK_H
  16. #define _BITS_LIBC_LOCK_H 1
  17. #include <bits/initspin.h>
  18. #include <pthread.h>
  19. #define __need_NULL
  20. #include <stddef.h>
  21. /* Fortunately Linux now has a mean to do locking which is realtime
  22. safe without the aid of the thread library. We also need no fancy
  23. options like error checking mutexes etc. We only need simple
  24. locks, maybe recursive. This can be easily and cheaply implemented
  25. using futexes. We will use them everywhere except in ld.so since
  26. ld.so might be used on old kernels with a different libc.so. */
  27. #ifdef _LIBC
  28. # include <lowlevellock.h>
  29. # include <tls.h>
  30. #endif
  31. /* Mutex type. */
  32. #if defined _LIBC || defined _IO_MTSAFE_IO
  33. # if (defined NOT_IN_libc && !defined IS_IN_libpthread) || !defined _LIBC
  34. typedef pthread_mutex_t __libc_lock_t;
  35. typedef struct { pthread_mutex_t mutex; } __libc_lock_recursive_t;
  36. # else
  37. typedef int __libc_lock_t;
  38. typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t;
  39. # endif
  40. typedef struct { pthread_mutex_t mutex; } __rtld_lock_recursive_t;
  41. # ifdef __USE_UNIX98
  42. typedef pthread_rwlock_t __libc_rwlock_t;
  43. # else
  44. typedef struct __libc_rwlock_opaque__ __libc_rwlock_t;
  45. # endif
  46. #else
  47. typedef struct __libc_lock_opaque__ __libc_lock_t;
  48. typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t;
  49. typedef struct __libc_rwlock_opaque__ __libc_rwlock_t;
  50. #endif
  51. /* Type for key to thread-specific data. */
  52. typedef pthread_key_t __libc_key_t;
  53. # define __libc_freeres_fn_section \
  54. __attribute__ ((section ("__libc_freeres_fn")))
  55. /* Define a lock variable NAME with storage class CLASS. The lock must be
  56. initialized with __libc_lock_init before it can be used (or define it
  57. with __libc_lock_define_initialized, below). Use `extern' for CLASS to
  58. declare a lock defined in another module. In public structure
  59. definitions you must use a pointer to the lock structure (i.e., NAME
  60. begins with a `*'), because its storage size will not be known outside
  61. of libc. */
  62. #define __libc_lock_define(CLASS,NAME) \
  63. CLASS __libc_lock_t NAME;
  64. #define __libc_rwlock_define(CLASS,NAME) \
  65. CLASS __libc_rwlock_t NAME;
  66. #define __libc_lock_define_recursive(CLASS,NAME) \
  67. CLASS __libc_lock_recursive_t NAME;
  68. #define __rtld_lock_define_recursive(CLASS,NAME) \
  69. CLASS __rtld_lock_recursive_t NAME;
  70. /* Define an initialized lock variable NAME with storage class CLASS.
  71. For the C library we take a deeper look at the initializer. For
  72. this implementation all fields are initialized to zero. Therefore
  73. we don't initialize the variable which allows putting it into the
  74. BSS section. (Except on PA-RISC and other odd architectures, where
  75. initialized locks must be set to one due to the lack of normal
  76. atomic operations.) */
  77. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  78. # if LLL_LOCK_INITIALIZER == 0
  79. # define __libc_lock_define_initialized(CLASS,NAME) \
  80. CLASS __libc_lock_t NAME;
  81. # else
  82. # define __libc_lock_define_initialized(CLASS,NAME) \
  83. CLASS __libc_lock_t NAME = LLL_LOCK_INITIALIZER;
  84. # endif
  85. #else
  86. # if __LT_SPINLOCK_INIT == 0
  87. # define __libc_lock_define_initialized(CLASS,NAME) \
  88. CLASS __libc_lock_t NAME;
  89. # else
  90. # define __libc_lock_define_initialized(CLASS,NAME) \
  91. CLASS __libc_lock_t NAME = PTHREAD_MUTEX_INITIALIZER;
  92. # endif
  93. #endif
  94. #define __libc_rwlock_define_initialized(CLASS,NAME) \
  95. CLASS __libc_rwlock_t NAME = PTHREAD_RWLOCK_INITIALIZER;
  96. /* Define an initialized recursive lock variable NAME with storage
  97. class CLASS. */
  98. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  99. # if LLL_LOCK_INITIALIZER == 0
  100. # define __libc_lock_define_initialized_recursive(CLASS,NAME) \
  101. CLASS __libc_lock_recursive_t NAME;
  102. # else
  103. # define __libc_lock_define_initialized_recursive(CLASS,NAME) \
  104. CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
  105. # endif
  106. # define _LIBC_LOCK_RECURSIVE_INITIALIZER \
  107. { LLL_LOCK_INITIALIZER, 0, NULL }
  108. #else
  109. # define __libc_lock_define_initialized_recursive(CLASS,NAME) \
  110. CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
  111. # define _LIBC_LOCK_RECURSIVE_INITIALIZER \
  112. {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}
  113. #endif
  114. #define __rtld_lock_define_initialized_recursive(CLASS,NAME) \
  115. CLASS __rtld_lock_recursive_t NAME = _RTLD_LOCK_RECURSIVE_INITIALIZER;
  116. #define _RTLD_LOCK_RECURSIVE_INITIALIZER \
  117. {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}
  118. #define __rtld_lock_initialize(NAME) \
  119. (void) ((NAME) = (__rtld_lock_recursive_t) _RTLD_LOCK_RECURSIVE_INITIALIZER)
  120. /* If we check for a weakly referenced symbol and then perform a
  121. normal jump to it te code generated for some platforms in case of
  122. PIC is unnecessarily slow. What would happen is that the function
  123. is first referenced as data and then it is called indirectly
  124. through the PLT. We can make this a direct jump. */
  125. #ifdef __PIC__
  126. # define __libc_maybe_call(FUNC, ARGS, ELSE) \
  127. (__extension__ ({ __typeof (FUNC) *_fn = (FUNC); \
  128. _fn != NULL ? (*_fn) ARGS : ELSE; }))
  129. #else
  130. # define __libc_maybe_call(FUNC, ARGS, ELSE) \
  131. (FUNC != NULL ? FUNC ARGS : ELSE)
  132. #endif
  133. # define PTFAVAIL(NAME) (NAME != NULL)
  134. # define __libc_ptf_call(FUNC, ARGS, ELSE) \
  135. __libc_maybe_call (FUNC, ARGS, ELSE)
  136. # define __libc_ptf_call_always(FUNC, ARGS) \
  137. FUNC ARGS
  138. /* Initialize the named lock variable, leaving it in a consistent, unlocked
  139. state. */
  140. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  141. # define __libc_lock_init(NAME) ((void)((NAME) = LLL_LOCK_INITIALIZER))
  142. #else
  143. # define __libc_lock_init(NAME) \
  144. __libc_maybe_call (__pthread_mutex_init, (&(NAME), NULL), 0)
  145. #endif
  146. #if defined SHARED && !defined NOT_IN_libc
  147. /* ((NAME) = (__libc_rwlock_t) PTHREAD_RWLOCK_INITIALIZER, 0) is
  148. inefficient. */
  149. # define __libc_rwlock_init(NAME) \
  150. (__builtin_memset (&(NAME), '\0', sizeof (NAME)), 0)
  151. #else
  152. # define __libc_rwlock_init(NAME) \
  153. __libc_maybe_call (__pthread_rwlock_init, (&(NAME), NULL), 0)
  154. #endif
  155. /* Same as last but this time we initialize a recursive mutex. */
  156. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  157. # define __libc_lock_init_recursive(NAME) \
  158. ((NAME) = (__libc_lock_recursive_t) _LIBC_LOCK_RECURSIVE_INITIALIZER, 0)
  159. #else
  160. # define __libc_lock_init_recursive(NAME) \
  161. do { \
  162. if (__pthread_mutex_init != NULL) \
  163. { \
  164. pthread_mutexattr_t __attr; \
  165. __pthread_mutexattr_init (&__attr); \
  166. __pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \
  167. __pthread_mutex_init (&(NAME).mutex, &__attr); \
  168. __pthread_mutexattr_destroy (&__attr); \
  169. } \
  170. } while (0)
  171. #endif
  172. #define __rtld_lock_init_recursive(NAME) \
  173. do { \
  174. if (__pthread_mutex_init != NULL) \
  175. { \
  176. pthread_mutexattr_t __attr; \
  177. __pthread_mutexattr_init (&__attr); \
  178. __pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \
  179. __pthread_mutex_init (&(NAME).mutex, &__attr); \
  180. __pthread_mutexattr_destroy (&__attr); \
  181. } \
  182. } while (0)
  183. /* Finalize the named lock variable, which must be locked. It cannot be
  184. used again until __libc_lock_init is called again on it. This must be
  185. called on a lock variable before the containing storage is reused. */
  186. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  187. # define __libc_lock_fini(NAME) ((void) 0)
  188. #else
  189. # define __libc_lock_fini(NAME) \
  190. __libc_maybe_call (__pthread_mutex_destroy, (&(NAME)), 0)
  191. #endif
  192. #if defined SHARED && !defined NOT_IN_libc
  193. # define __libc_rwlock_fini(NAME) ((void) 0)
  194. #else
  195. # define __libc_rwlock_fini(NAME) \
  196. __libc_maybe_call (__pthread_rwlock_destroy, (&(NAME)), 0)
  197. #endif
  198. /* Finalize recursive named lock. */
  199. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  200. # define __libc_lock_fini_recursive(NAME) ((void) 0)
  201. #else
  202. # define __libc_lock_fini_recursive(NAME) \
  203. __libc_maybe_call (__pthread_mutex_destroy, (&(NAME)), 0)
  204. #endif
  205. /* Lock the named lock variable. */
  206. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  207. # define __libc_lock_lock(NAME) \
  208. ({ lll_lock (NAME, LLL_PRIVATE); 0; })
  209. #else
  210. # define __libc_lock_lock(NAME) \
  211. __libc_maybe_call (__pthread_mutex_lock, (&(NAME)), 0)
  212. #endif
  213. #define __libc_rwlock_rdlock(NAME) \
  214. __libc_ptf_call (__pthread_rwlock_rdlock, (&(NAME)), 0)
  215. #define __libc_rwlock_wrlock(NAME) \
  216. __libc_ptf_call (__pthread_rwlock_wrlock, (&(NAME)), 0)
  217. /* Lock the recursive named lock variable. */
  218. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  219. # define __libc_lock_lock_recursive(NAME) \
  220. do { \
  221. void *self = THREAD_SELF; \
  222. if ((NAME).owner != self) \
  223. { \
  224. lll_lock ((NAME).lock, LLL_PRIVATE); \
  225. (NAME).owner = self; \
  226. } \
  227. ++(NAME).cnt; \
  228. } while (0)
  229. #else
  230. # define __libc_lock_lock_recursive(NAME) \
  231. __libc_maybe_call (__pthread_mutex_lock, (&(NAME).mutex), 0)
  232. #endif
  233. /* Try to lock the named lock variable. */
  234. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  235. # define __libc_lock_trylock(NAME) \
  236. lll_trylock (NAME)
  237. #else
  238. # define __libc_lock_trylock(NAME) \
  239. __libc_maybe_call (__pthread_mutex_trylock, (&(NAME)), 0)
  240. #endif
  241. #define __libc_rwlock_tryrdlock(NAME) \
  242. __libc_maybe_call (__pthread_rwlock_tryrdlock, (&(NAME)), 0)
  243. #define __libc_rwlock_trywrlock(NAME) \
  244. __libc_maybe_call (__pthread_rwlock_trywrlock, (&(NAME)), 0)
  245. /* Try to lock the recursive named lock variable. */
  246. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  247. # define __libc_lock_trylock_recursive(NAME) \
  248. ({ \
  249. int result = 0; \
  250. void *self = THREAD_SELF; \
  251. if ((NAME).owner != self) \
  252. { \
  253. if (lll_trylock ((NAME).lock) == 0) \
  254. { \
  255. (NAME).owner = self; \
  256. (NAME).cnt = 1; \
  257. } \
  258. else \
  259. result = EBUSY; \
  260. } \
  261. else \
  262. ++(NAME).cnt; \
  263. result; \
  264. })
  265. #else
  266. # define __libc_lock_trylock_recursive(NAME) \
  267. __libc_maybe_call (__pthread_mutex_trylock, (&(NAME)), 0)
  268. #endif
  269. #define __rtld_lock_trylock_recursive(NAME) \
  270. __libc_maybe_call (__pthread_mutex_trylock, (&(NAME).mutex), 0)
  271. /* Unlock the named lock variable. */
  272. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  273. # define __libc_lock_unlock(NAME) \
  274. lll_unlock (NAME, LLL_PRIVATE)
  275. #else
  276. # define __libc_lock_unlock(NAME) \
  277. __libc_maybe_call (__pthread_mutex_unlock, (&(NAME)), 0)
  278. #endif
  279. #define __libc_rwlock_unlock(NAME) \
  280. __libc_ptf_call (__pthread_rwlock_unlock, (&(NAME)), 0)
  281. /* Unlock the recursive named lock variable. */
  282. #if defined _LIBC && (!defined NOT_IN_libc || defined IS_IN_libpthread)
  283. /* We do no error checking here. */
  284. # define __libc_lock_unlock_recursive(NAME) \
  285. do { \
  286. if (--(NAME).cnt == 0) \
  287. { \
  288. (NAME).owner = NULL; \
  289. lll_unlock ((NAME).lock, LLL_PRIVATE); \
  290. } \
  291. } while (0)
  292. #else
  293. # define __libc_lock_unlock_recursive(NAME) \
  294. __libc_maybe_call (__pthread_mutex_unlock, (&(NAME)), 0)
  295. #endif
  296. #if defined _LIBC && defined SHARED
  297. # define __rtld_lock_default_lock_recursive(lock) \
  298. ++((pthread_mutex_t *)(lock))->__data.__count;
  299. # define __rtld_lock_default_unlock_recursive(lock) \
  300. --((pthread_mutex_t *)(lock))->__data.__count;
  301. # define __rtld_lock_lock_recursive(NAME) \
  302. GL(dl_rtld_lock_recursive) (&(NAME).mutex)
  303. # define __rtld_lock_unlock_recursive(NAME) \
  304. GL(dl_rtld_unlock_recursive) (&(NAME).mutex)
  305. #else
  306. # define __rtld_lock_lock_recursive(NAME) \
  307. __libc_maybe_call (__pthread_mutex_lock, (&(NAME).mutex), 0)
  308. # define __rtld_lock_unlock_recursive(NAME) \
  309. __libc_maybe_call (__pthread_mutex_unlock, (&(NAME).mutex), 0)
  310. #endif
  311. /* Define once control variable. */
  312. #if PTHREAD_ONCE_INIT == 0
  313. /* Special case for static variables where we can avoid the initialization
  314. if it is zero. */
  315. # define __libc_once_define(CLASS, NAME) \
  316. CLASS pthread_once_t NAME
  317. #else
  318. # define __libc_once_define(CLASS, NAME) \
  319. CLASS pthread_once_t NAME = PTHREAD_ONCE_INIT
  320. #endif
  321. /* Call handler iff the first call. */
  322. #define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
  323. do { \
  324. if (PTFAVAIL (__pthread_once)) \
  325. __libc_ptf_call_always (__pthread_once, (&(ONCE_CONTROL), \
  326. INIT_FUNCTION)); \
  327. else if ((ONCE_CONTROL) == PTHREAD_ONCE_INIT) { \
  328. INIT_FUNCTION (); \
  329. (ONCE_CONTROL) |= 2; \
  330. } \
  331. } while (0)
  332. /* Note that for I/O cleanup handling we are using the old-style
  333. cancel handling. It does not have to be integrated with C++ snce
  334. no C++ code is called in the middle. The old-style handling is
  335. faster and the support is not going away. */
  336. extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
  337. void (*routine) (void *), void *arg);
  338. extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
  339. int execute);
  340. extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
  341. void (*routine) (void *), void *arg);
  342. extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
  343. int execute);
  344. /* Start critical region with cleanup. */
  345. #define __libc_cleanup_region_start(DOIT, FCT, ARG) \
  346. { struct _pthread_cleanup_buffer _buffer; \
  347. int _avail; \
  348. if (DOIT) { \
  349. _avail = PTFAVAIL (_pthread_cleanup_push_defer); \
  350. if (_avail) { \
  351. __libc_ptf_call_always (_pthread_cleanup_push_defer, (&_buffer, FCT, \
  352. ARG)); \
  353. } else { \
  354. _buffer.__routine = (FCT); \
  355. _buffer.__arg = (ARG); \
  356. } \
  357. } else { \
  358. _avail = 0; \
  359. }
  360. /* End critical region with cleanup. */
  361. #define __libc_cleanup_region_end(DOIT) \
  362. if (_avail) { \
  363. __libc_ptf_call_always (_pthread_cleanup_pop_restore, (&_buffer, DOIT));\
  364. } else if (DOIT) \
  365. _buffer.__routine (_buffer.__arg); \
  366. }
  367. /* Sometimes we have to exit the block in the middle. */
  368. #define __libc_cleanup_end(DOIT) \
  369. if (_avail) { \
  370. __libc_ptf_call_always (_pthread_cleanup_pop_restore, (&_buffer, DOIT));\
  371. } else if (DOIT) \
  372. _buffer.__routine (_buffer.__arg)
  373. /* Normal cleanup handling, based on C cleanup attribute. */
  374. static inline void
  375. __libc_cleanup_routine (struct __pthread_cleanup_frame *f)
  376. {
  377. if (f->__do_it)
  378. f->__cancel_routine (f->__cancel_arg);
  379. }
  380. #define __libc_cleanup_push(fct, arg) \
  381. do { \
  382. struct __pthread_cleanup_frame __clframe \
  383. __attribute__ ((__cleanup__ (__libc_cleanup_routine))) \
  384. = { .__cancel_routine = (fct), .__cancel_arg = (arg), \
  385. .__do_it = 1 };
  386. #define __libc_cleanup_pop(execute) \
  387. __clframe.__do_it = (execute); \
  388. } while (0)
  389. /* Create thread-specific key. */
  390. #define __libc_key_create(KEY, DESTRUCTOR) \
  391. __libc_ptf_call (__pthread_key_create, (KEY, DESTRUCTOR), 1)
  392. /* Get thread-specific data. */
  393. #define __libc_getspecific(KEY) \
  394. __libc_ptf_call (__pthread_getspecific, (KEY), NULL)
  395. /* Set thread-specific data. */
  396. #define __libc_setspecific(KEY, VALUE) \
  397. __libc_ptf_call (__pthread_setspecific, (KEY, VALUE), 0)
  398. /* Register handlers to execute before and after `fork'. Note that the
  399. last parameter is NULL. The handlers registered by the libc are
  400. never removed so this is OK. */
  401. #define __libc_atfork(PREPARE, PARENT, CHILD) \
  402. __register_atfork (PREPARE, PARENT, CHILD, NULL)
  403. extern int __register_atfork (void (*__prepare) (void),
  404. void (*__parent) (void),
  405. void (*__child) (void),
  406. void *__dso_handle);
  407. /* Functions that are used by this file and are internal to the GNU C
  408. library. */
  409. extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
  410. const pthread_mutexattr_t *__mutex_attr);
  411. extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
  412. extern int __pthread_mutex_trylock (pthread_mutex_t *__mutex);
  413. extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
  414. extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
  415. extern int __pthread_mutexattr_init (pthread_mutexattr_t *__attr);
  416. extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *__attr);
  417. extern int __pthread_mutexattr_settype (pthread_mutexattr_t *__attr,
  418. int __kind);
  419. #ifdef __USE_UNIX98
  420. extern int __pthread_rwlock_init (pthread_rwlock_t *__rwlock,
  421. const pthread_rwlockattr_t *__attr);
  422. extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock);
  423. extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock);
  424. extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock);
  425. extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock);
  426. extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock);
  427. extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock);
  428. #endif
  429. extern int __pthread_key_create (pthread_key_t *__key,
  430. void (*__destr_function) (void *));
  431. extern int __pthread_setspecific (pthread_key_t __key,
  432. const void *__pointer);
  433. extern void *__pthread_getspecific (pthread_key_t __key);
  434. extern int __pthread_once (pthread_once_t *__once_control,
  435. void (*__init_routine) (void));
  436. extern int __pthread_atfork (void (*__prepare) (void),
  437. void (*__parent) (void),
  438. void (*__child) (void));
  439. /* Make the pthread functions weak so that we can elide them from
  440. single-threaded processes. */
  441. #ifndef __NO_WEAK_PTHREAD_ALIASES
  442. # ifdef weak_extern
  443. weak_extern (__pthread_mutex_init)
  444. weak_extern (__pthread_mutex_destroy)
  445. weak_extern (__pthread_mutex_lock)
  446. weak_extern (__pthread_mutex_trylock)
  447. weak_extern (__pthread_mutex_unlock)
  448. weak_extern (__pthread_mutexattr_init)
  449. weak_extern (__pthread_mutexattr_destroy)
  450. weak_extern (__pthread_mutexattr_settype)
  451. weak_extern (__pthread_rwlock_init)
  452. weak_extern (__pthread_rwlock_destroy)
  453. weak_extern (__pthread_rwlock_rdlock)
  454. weak_extern (__pthread_rwlock_tryrdlock)
  455. weak_extern (__pthread_rwlock_wrlock)
  456. weak_extern (__pthread_rwlock_trywrlock)
  457. weak_extern (__pthread_rwlock_unlock)
  458. weak_extern (__pthread_key_create)
  459. weak_extern (__pthread_setspecific)
  460. weak_extern (__pthread_getspecific)
  461. weak_extern (__pthread_once)
  462. //weak_extern (__pthread_initialize)
  463. weak_extern (__pthread_atfork)
  464. weak_extern (_pthread_cleanup_push_defer)
  465. weak_extern (_pthread_cleanup_pop_restore)
  466. weak_extern (pthread_setcancelstate)
  467. # else
  468. # pragma weak __pthread_mutex_init
  469. # pragma weak __pthread_mutex_destroy
  470. # pragma weak __pthread_mutex_lock
  471. # pragma weak __pthread_mutex_trylock
  472. # pragma weak __pthread_mutex_unlock
  473. # pragma weak __pthread_mutexattr_init
  474. # pragma weak __pthread_mutexattr_destroy
  475. # pragma weak __pthread_mutexattr_settype
  476. # pragma weak __pthread_rwlock_destroy
  477. # pragma weak __pthread_rwlock_rdlock
  478. # pragma weak __pthread_rwlock_tryrdlock
  479. # pragma weak __pthread_rwlock_wrlock
  480. # pragma weak __pthread_rwlock_trywrlock
  481. # pragma weak __pthread_rwlock_unlock
  482. # pragma weak __pthread_key_create
  483. # pragma weak __pthread_setspecific
  484. # pragma weak __pthread_getspecific
  485. # pragma weak __pthread_once
  486. //# pragma weak __pthread_initialize
  487. # pragma weak __pthread_atfork
  488. # pragma weak _pthread_cleanup_push_defer
  489. # pragma weak _pthread_cleanup_pop_restore
  490. # pragma weak pthread_setcancelstate
  491. # endif
  492. #endif
  493. #endif /* bits/libc-lock.h */