libc-lock.h 21 KB

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