libc-lock.h 21 KB

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