libc-lock.h 21 KB

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