pthread.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /* Linuxthreads - a simple clone()-based implementation of Posix */
  2. /* threads for Linux. */
  3. /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
  4. /* */
  5. /* This program is free software; you can redistribute it and/or */
  6. /* modify it under the terms of the GNU Library General Public License */
  7. /* as published by the Free Software Foundation; either version 2 */
  8. /* of the License, or (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU Library General Public License for more details. */
  14. #ifndef _PTHREAD_H
  15. #define _PTHREAD_H 1
  16. #include <features.h>
  17. #include <sched.h>
  18. #include <time.h>
  19. #include <signal.h>
  20. #include <bits/pthreadtypes.h>
  21. #include <bits/initspin.h>
  22. __BEGIN_DECLS
  23. /* Initializers. */
  24. #define PTHREAD_MUTEX_INITIALIZER \
  25. {0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __LOCK_INITIALIZER}
  26. #ifdef __USE_GNU
  27. # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
  28. {0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, __LOCK_INITIALIZER}
  29. # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
  30. {0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, __LOCK_INITIALIZER}
  31. # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
  32. {0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __LOCK_INITIALIZER}
  33. #endif
  34. #define PTHREAD_COND_INITIALIZER {__LOCK_INITIALIZER, 0}
  35. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  36. # define PTHREAD_RWLOCK_INITIALIZER \
  37. { __LOCK_INITIALIZER, 0, NULL, NULL, NULL, \
  38. PTHREAD_RWLOCK_DEFAULT_NP, PTHREAD_PROCESS_PRIVATE }
  39. #endif
  40. #ifdef __USE_GNU
  41. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  42. { __LOCK_INITIALIZER, 0, NULL, NULL, NULL, \
  43. PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, PTHREAD_PROCESS_PRIVATE }
  44. #endif
  45. /* Values for attributes. */
  46. enum
  47. {
  48. PTHREAD_CREATE_JOINABLE,
  49. #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
  50. PTHREAD_CREATE_DETACHED
  51. #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
  52. };
  53. enum
  54. {
  55. PTHREAD_INHERIT_SCHED,
  56. #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
  57. PTHREAD_EXPLICIT_SCHED
  58. #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
  59. };
  60. enum
  61. {
  62. PTHREAD_SCOPE_SYSTEM,
  63. #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
  64. PTHREAD_SCOPE_PROCESS
  65. #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
  66. };
  67. enum
  68. {
  69. PTHREAD_MUTEX_ADAPTIVE_NP,
  70. PTHREAD_MUTEX_RECURSIVE_NP,
  71. PTHREAD_MUTEX_ERRORCHECK_NP,
  72. PTHREAD_MUTEX_TIMED_NP
  73. #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
  74. ,
  75. PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_ADAPTIVE_NP,
  76. PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
  77. PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
  78. PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
  79. #endif
  80. #ifdef __USE_GNU
  81. /* For compatibility. */
  82. , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_ADAPTIVE_NP
  83. #endif
  84. };
  85. enum
  86. {
  87. PTHREAD_PROCESS_PRIVATE,
  88. #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
  89. PTHREAD_PROCESS_SHARED
  90. #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
  91. };
  92. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  93. enum
  94. {
  95. PTHREAD_RWLOCK_PREFER_READER_NP,
  96. PTHREAD_RWLOCK_PREFER_WRITER_NP,
  97. PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
  98. PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_WRITER_NP
  99. };
  100. #endif /* Unix98 */
  101. #define PTHREAD_ONCE_INIT 0
  102. /* Special constants */
  103. #ifdef __USE_XOPEN2K
  104. /* -1 is distinct from 0 and all errno constants */
  105. # define PTHREAD_BARRIER_SERIAL_THREAD -1
  106. #endif
  107. /* Cleanup buffers */
  108. struct _pthread_cleanup_buffer
  109. {
  110. void (*__routine) (void *); /* Function to call. */
  111. void *__arg; /* Its argument. */
  112. int __canceltype; /* Saved cancellation type. */
  113. struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */
  114. };
  115. /* Cancellation */
  116. enum
  117. {
  118. PTHREAD_CANCEL_ENABLE,
  119. #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
  120. PTHREAD_CANCEL_DISABLE
  121. #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
  122. };
  123. enum
  124. {
  125. PTHREAD_CANCEL_DEFERRED,
  126. #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
  127. PTHREAD_CANCEL_ASYNCHRONOUS
  128. #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
  129. };
  130. #define PTHREAD_CANCELED ((void *) -1)
  131. /* Function for handling threads. */
  132. /* Create a thread with given attributes ATTR (or default attributes
  133. if ATTR is NULL), and call function START_ROUTINE with given
  134. arguments ARG. */
  135. extern int pthread_create (pthread_t *__restrict __threadp,
  136. const pthread_attr_t *__restrict __attr,
  137. void *(*__start_routine) (void *),
  138. void *__restrict __arg) __THROWNL;
  139. /* Obtain the identifier of the current thread. */
  140. extern pthread_t pthread_self (void) __THROW;
  141. /* Compare two thread identifiers. */
  142. extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __THROW;
  143. /* Terminate calling thread. */
  144. extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
  145. /* Make calling thread wait for termination of the thread TH. The
  146. exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
  147. is not NULL. */
  148. extern int pthread_join (pthread_t __th, void **__thread_return);
  149. #ifdef __USE_GNU
  150. /* Check whether thread TH has terminated. If yes return the status of
  151. the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
  152. extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
  153. /* Make calling thread wait for termination of the thread TH, but only
  154. until TIMEOUT. The exit status of the thread is stored in
  155. *THREAD_RETURN, if THREAD_RETURN is not NULL.
  156. This function is a cancellation point and therefore not marked with
  157. __THROW. */
  158. extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
  159. __const struct timespec *__abstime);
  160. #endif
  161. /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
  162. The resources of TH will therefore be freed immediately when it
  163. terminates, instead of waiting for another thread to perform PTHREAD_JOIN
  164. on it. */
  165. extern int pthread_detach (pthread_t __th) __THROW;
  166. /* Functions for handling attributes. */
  167. /* Initialize thread attribute *ATTR with default attributes
  168. (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
  169. no user-provided stack). */
  170. extern int pthread_attr_init (pthread_attr_t *__attr) __THROW;
  171. /* Destroy thread attribute *ATTR. */
  172. extern int pthread_attr_destroy (pthread_attr_t *__attr) __THROW;
  173. /* Set the `detachstate' attribute in *ATTR according to DETACHSTATE. */
  174. extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
  175. int __detachstate) __THROW;
  176. /* Return in *DETACHSTATE the `detachstate' attribute in *ATTR. */
  177. extern int pthread_attr_getdetachstate (const pthread_attr_t *__attr,
  178. int *__detachstate) __THROW;
  179. /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
  180. extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
  181. const struct sched_param *__restrict
  182. __param) __THROW;
  183. /* Return in *PARAM the scheduling parameters of *ATTR. */
  184. extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict
  185. __attr,
  186. struct sched_param *__restrict __param)
  187. __THROW;
  188. /* Set scheduling policy in *ATTR according to POLICY. */
  189. extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
  190. __THROW;
  191. /* Return in *POLICY the scheduling policy of *ATTR. */
  192. extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict
  193. __attr, int *__restrict __policy)
  194. __THROW;
  195. /* Set scheduling inheritance mode in *ATTR according to INHERIT. */
  196. extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
  197. int __inherit) __THROW;
  198. /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
  199. extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict
  200. __attr, int *__restrict __inherit)
  201. __THROW;
  202. /* Set scheduling contention scope in *ATTR according to SCOPE. */
  203. extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
  204. __THROW;
  205. /* Return in *SCOPE the scheduling contention scope of *ATTR. */
  206. extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr,
  207. int *__restrict __scope) __THROW;
  208. /* Set the size of the guard area at the bottom of the thread. */
  209. extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
  210. size_t __guardsize) __THROW;
  211. /* Get the size of the guard area at the bottom of the thread. */
  212. extern int pthread_attr_getguardsize (const pthread_attr_t *__restrict
  213. __attr, size_t *__restrict __guardsize)
  214. __THROW;
  215. #if 0 /* uClibc: deprecated stuff disabled. def __UCLIBC_SUSV3_LEGACY__ */
  216. /* Set the starting address of the stack of the thread to be created.
  217. Depending on whether the stack grows up or down the value must either
  218. be higher or lower than all the address in the memory block. The
  219. minimal size of the block must be PTHREAD_STACK_SIZE. */
  220. extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
  221. void *__stackaddr) __THROW;
  222. /* Return the previously set address for the stack. */
  223. extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict
  224. __attr, void **__restrict __stackaddr)
  225. __THROW;
  226. #endif
  227. #ifdef __USE_XOPEN2K
  228. /* The following two interfaces are intended to replace the last two. They
  229. require setting the address as well as the size since only setting the
  230. address will make the implementation on some architectures impossible. */
  231. extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
  232. size_t __stacksize) __THROW;
  233. /* Return the previously set address for the stack. */
  234. extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr,
  235. void **__restrict __stackaddr,
  236. size_t *__restrict __stacksize) __THROW;
  237. #endif
  238. /* Add information about the minimum stack size needed for the thread
  239. to be started. This size must never be less than PTHREAD_STACK_SIZE
  240. and must also not exceed the system limits. */
  241. extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
  242. size_t __stacksize) __THROW;
  243. /* Return the currently used minimal stack size. */
  244. extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict
  245. __attr, size_t *__restrict __stacksize)
  246. __THROW;
  247. #if 0
  248. /* Not yet implemented in uClibc! */
  249. #ifdef __USE_GNU
  250. /* Initialize thread attribute *ATTR with attributes corresponding to the
  251. already running thread TH. It shall be called on uninitialized ATTR
  252. and destroyed with pthread_attr_destroy when no longer needed. */
  253. extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) __THROW;
  254. #endif
  255. #endif
  256. /* Functions for scheduling control. */
  257. /* Set the scheduling parameters for TARGET_THREAD according to POLICY
  258. and *PARAM. */
  259. extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
  260. const struct sched_param *__param)
  261. __THROW;
  262. /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
  263. extern int pthread_getschedparam (pthread_t __target_thread,
  264. int *__restrict __policy,
  265. struct sched_param *__restrict __param)
  266. __THROW;
  267. #ifdef __USE_UNIX98
  268. /* Determine level of concurrency. */
  269. extern int pthread_getconcurrency (void) __THROW;
  270. /* Set new concurrency level to LEVEL. */
  271. extern int pthread_setconcurrency (int __level) __THROW;
  272. #endif
  273. #ifdef __USE_GNU
  274. /* Same thing, different name */
  275. #define pthread_yield() sched_yield()
  276. #endif
  277. /* Functions for mutex handling. */
  278. /* Initialize MUTEX using attributes in *MUTEX_ATTR, or use the
  279. default values if later is NULL. */
  280. extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,
  281. const pthread_mutexattr_t *__restrict
  282. __mutex_attr) __THROW;
  283. /* Destroy MUTEX. */
  284. extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) __THROW;
  285. /* Try to lock MUTEX. */
  286. extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) __THROWNL;
  287. /* Wait until lock for MUTEX becomes available and lock it. */
  288. extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __THROWNL;
  289. #ifdef __USE_XOPEN2K
  290. /* Wait until lock becomes available, or specified time passes. */
  291. extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
  292. const struct timespec *__restrict
  293. __abstime) __THROWNL;
  294. #endif
  295. /* Unlock MUTEX. */
  296. extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROWNL;
  297. /* Functions for handling mutex attributes. */
  298. /* Initialize mutex attribute object ATTR with default attributes
  299. (kind is PTHREAD_MUTEX_TIMED_NP). */
  300. extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr) __THROW;
  301. /* Destroy mutex attribute object ATTR. */
  302. extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr) __THROW;
  303. /* Get the process-shared flag of the mutex attribute ATTR. */
  304. extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t *
  305. __restrict __attr,
  306. int *__restrict __pshared) __THROW;
  307. /* Set the process-shared flag of the mutex attribute ATTR. */
  308. extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
  309. int __pshared) __THROW;
  310. #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
  311. /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
  312. PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
  313. PTHREAD_MUTEX_DEFAULT). */
  314. extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
  315. __THROW;
  316. /* Return in *KIND the mutex kind attribute in *ATTR. */
  317. extern int pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict
  318. __attr, int *__restrict __kind) __THROW;
  319. #endif
  320. /* Functions for handling conditional variables. */
  321. /* Initialize condition variable COND using attributes ATTR, or use
  322. the default values if later is NULL. */
  323. extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
  324. const pthread_condattr_t *__restrict
  325. __cond_attr) __THROW;
  326. libpthread_hidden_proto(pthread_cond_init)
  327. /* Destroy condition variable COND. */
  328. extern int pthread_cond_destroy (pthread_cond_t *__cond) __THROW;
  329. libpthread_hidden_proto(pthread_cond_destroy)
  330. /* Wake up one thread waiting for condition variable COND. */
  331. extern int pthread_cond_signal (pthread_cond_t *__cond) __THROWNL;
  332. libpthread_hidden_proto(pthread_cond_signal)
  333. /* Wake up all threads waiting for condition variables COND. */
  334. extern int pthread_cond_broadcast (pthread_cond_t *__cond) __THROWNL;
  335. libpthread_hidden_proto(pthread_cond_broadcast)
  336. /* Wait for condition variable COND to be signaled or broadcast.
  337. MUTEX is assumed to be locked before. */
  338. extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
  339. pthread_mutex_t *__restrict __mutex);
  340. libpthread_hidden_proto(pthread_cond_wait)
  341. /* Wait for condition variable COND to be signaled or broadcast until
  342. ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an
  343. absolute time specification; zero is the beginning of the epoch
  344. (00:00:00 GMT, January 1, 1970). */
  345. extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
  346. pthread_mutex_t *__restrict __mutex,
  347. const struct timespec *__restrict
  348. __abstime);
  349. libpthread_hidden_proto(pthread_cond_timedwait)
  350. /* Functions for handling condition variable attributes. */
  351. /* Initialize condition variable attribute ATTR. */
  352. extern int pthread_condattr_init (pthread_condattr_t *__attr) __THROW;
  353. libpthread_hidden_proto(pthread_condattr_init)
  354. /* Destroy condition variable attribute ATTR. */
  355. extern int pthread_condattr_destroy (pthread_condattr_t *__attr) __THROW;
  356. libpthread_hidden_proto(pthread_condattr_destroy)
  357. /* Get the process-shared flag of the condition variable attribute ATTR. */
  358. extern int pthread_condattr_getpshared (const pthread_condattr_t *
  359. __restrict __attr,
  360. int *__restrict __pshared) __THROW;
  361. /* Set the process-shared flag of the condition variable attribute ATTR. */
  362. extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
  363. int __pshared) __THROW;
  364. #ifdef __USE_XOPEN2K
  365. /* Get the clock selected for the condition variable attribute ATTR. */
  366. extern int pthread_condattr_getclock (const pthread_condattr_t *
  367. __restrict __attr,
  368. __clockid_t *__restrict __clock_id)
  369. __THROW __nonnull ((1, 2));
  370. /* Set the clock selected for the condition variable attribute ATTR. */
  371. extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
  372. __clockid_t __clock_id)
  373. __THROW __nonnull ((1));
  374. #endif
  375. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  376. /* Functions for handling read-write locks. */
  377. /* Initialize read-write lock RWLOCK using attributes ATTR, or use
  378. the default values if later is NULL. */
  379. extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
  380. const pthread_rwlockattr_t *__restrict
  381. __attr) __THROW;
  382. /* Destroy read-write lock RWLOCK. */
  383. extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) __THROW;
  384. /* Acquire read lock for RWLOCK. */
  385. extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) __THROWNL;
  386. /* Try to acquire read lock for RWLOCK. */
  387. extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) __THROWNL;
  388. # ifdef __USE_XOPEN2K
  389. /* Try to acquire read lock for RWLOCK or return after specfied time. */
  390. extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
  391. const struct timespec *__restrict
  392. __abstime) __THROWNL;
  393. # endif
  394. /* Acquire write lock for RWLOCK. */
  395. extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) __THROWNL;
  396. /* Try to acquire write lock for RWLOCK. */
  397. extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) __THROWNL;
  398. # ifdef __USE_XOPEN2K
  399. /* Try to acquire write lock for RWLOCK or return after specfied time. */
  400. extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
  401. const struct timespec *__restrict
  402. __abstime) __THROWNL;
  403. # endif
  404. /* Unlock RWLOCK. */
  405. extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) __THROWNL;
  406. /* Functions for handling read-write lock attributes. */
  407. /* Initialize attribute object ATTR with default values. */
  408. extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr) __THROW;
  409. /* Destroy attribute object ATTR. */
  410. extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr) __THROW;
  411. /* Return current setting of process-shared attribute of ATTR in PSHARED. */
  412. extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *
  413. __restrict __attr,
  414. int *__restrict __pshared) __THROW;
  415. /* Set process-shared attribute of ATTR to PSHARED. */
  416. extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
  417. int __pshared) __THROW;
  418. /* Return current setting of reader/writer preference. */
  419. extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t *__attr,
  420. int *__pref) __THROW;
  421. /* Set reader/write preference. */
  422. extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
  423. int __pref) __THROW;
  424. #endif
  425. #if 0
  426. /* Not yet implemented in uClibc! */
  427. #ifdef __USE_XOPEN2K
  428. /* The IEEE Std. 1003.1j-2000 introduces functions to implement
  429. spinlocks. */
  430. /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can
  431. be shared between different processes. */
  432. extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
  433. __THROW;
  434. /* Destroy the spinlock LOCK. */
  435. extern int pthread_spin_destroy (pthread_spinlock_t *__lock) __THROW;
  436. /* Wait until spinlock LOCK is retrieved. */
  437. extern int pthread_spin_lock (pthread_spinlock_t *__lock) __THROWNL;
  438. /* Try to lock spinlock LOCK. */
  439. extern int pthread_spin_trylock (pthread_spinlock_t *__lock) __THROWNL;
  440. /* Release spinlock LOCK. */
  441. extern int pthread_spin_unlock (pthread_spinlock_t *__lock) __THROWNL;
  442. /* Barriers are a also a new feature in 1003.1j-2000. */
  443. extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
  444. const pthread_barrierattr_t *__restrict
  445. __attr, unsigned int __count) __THROW;
  446. extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) __THROW;
  447. extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr) __THROW;
  448. extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr) __THROW;
  449. extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t *
  450. __restrict __attr,
  451. int *__restrict __pshared) __THROW;
  452. extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
  453. int __pshared) __THROW;
  454. extern int pthread_barrier_wait (pthread_barrier_t *__barrier) __THROWNL;
  455. #endif
  456. #endif
  457. /* Functions for handling thread-specific data. */
  458. /* Create a key value identifying a location in the thread-specific
  459. data area. Each thread maintains a distinct thread-specific data
  460. area. DESTR_FUNCTION, if non-NULL, is called with the value
  461. associated to that key when the key is destroyed.
  462. DESTR_FUNCTION is not called if the value associated is NULL when
  463. the key is destroyed. */
  464. extern int pthread_key_create (pthread_key_t *__key,
  465. void (*__destr_function) (void *)) __THROW;
  466. /* Destroy KEY. */
  467. extern int pthread_key_delete (pthread_key_t __key) __THROW;
  468. /* Store POINTER in the thread-specific data slot identified by KEY. */
  469. extern int pthread_setspecific (pthread_key_t __key,
  470. const void *__pointer) __THROW;
  471. /* Return current value of the thread-specific data slot identified by KEY. */
  472. extern void *pthread_getspecific (pthread_key_t __key) __THROW;
  473. /* Functions for handling initialization. */
  474. /* Guarantee that the initialization function INIT_ROUTINE will be called
  475. only once, even if pthread_once is executed several times with the
  476. same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
  477. extern variable initialized to PTHREAD_ONCE_INIT.
  478. The initialization functions might throw exception which is why
  479. this function is not marked with __THROW. */
  480. extern int pthread_once (pthread_once_t *__once_control,
  481. void (*__init_routine) (void));
  482. /* Functions for handling cancellation. */
  483. /* Set cancelability state of current thread to STATE, returning old
  484. state in *OLDSTATE if OLDSTATE is not NULL. */
  485. extern int pthread_setcancelstate (int __state, int *__oldstate);
  486. /* Set cancellation state of current thread to TYPE, returning the old
  487. type in *OLDTYPE if OLDTYPE is not NULL. */
  488. extern int pthread_setcanceltype (int __type, int *__oldtype);
  489. /* Cancel THREAD immediately or at the next possibility. */
  490. extern int pthread_cancel (pthread_t __cancelthread);
  491. /* Test for pending cancellation for the current thread and terminate
  492. the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
  493. cancelled. */
  494. extern void pthread_testcancel (void);
  495. /* Install a cleanup handler: ROUTINE will be called with arguments ARG
  496. when the thread is cancelled or calls pthread_exit. ROUTINE will also
  497. be called with arguments ARG when the matching pthread_cleanup_pop
  498. is executed with non-zero EXECUTE argument.
  499. pthread_cleanup_push and pthread_cleanup_pop are macros and must always
  500. be used in matching pairs at the same nesting level of braces. */
  501. #define pthread_cleanup_push(routine,arg) \
  502. { struct _pthread_cleanup_buffer _buffer; \
  503. _pthread_cleanup_push (&_buffer, (routine), (arg));
  504. extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer,
  505. void (*__routine) (void *),
  506. void *__arg) __THROW;
  507. /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
  508. If EXECUTE is non-zero, the handler function is called. */
  509. #define pthread_cleanup_pop(execute) \
  510. _pthread_cleanup_pop (&_buffer, (execute)); }
  511. extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer,
  512. int __execute) __THROW;
  513. /* Install a cleanup handler as pthread_cleanup_push does, but also
  514. saves the current cancellation type and set it to deferred cancellation. */
  515. #ifdef __USE_GNU
  516. # define pthread_cleanup_push_defer_np(routine,arg) \
  517. { struct _pthread_cleanup_buffer _buffer; \
  518. _pthread_cleanup_push_defer (&_buffer, (routine), (arg));
  519. extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *__buffer,
  520. void (*__routine) (void *),
  521. void *__arg) __THROW;
  522. extern void __pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *__buffer,
  523. void (*__routine) (void *),
  524. void *__arg) __THROW;
  525. /* Remove a cleanup handler as pthread_cleanup_pop does, but also
  526. restores the cancellation type that was in effect when the matching
  527. pthread_cleanup_push_defer was called. */
  528. # define pthread_cleanup_pop_restore_np(execute) \
  529. _pthread_cleanup_pop_restore (&_buffer, (execute)); }
  530. extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *__buffer,
  531. int __execute) __THROW;
  532. extern void __pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *__buffer,
  533. int __execute) __THROW;
  534. #endif
  535. #if 0
  536. /* Not yet implemented in uClibc! */
  537. #ifdef __USE_XOPEN2K
  538. /* Get ID of CPU-time clock for thread THREAD_ID. */
  539. extern int pthread_getcpuclockid (pthread_t __thread_id,
  540. clockid_t *__clock_id) __THROW;
  541. #endif
  542. #endif
  543. /* Functions for handling signals. */
  544. #include <bits/sigthread.h>
  545. /* Functions for handling process creation and process execution. */
  546. #ifdef __ARCH_USE_MMU__
  547. /* Install handlers to be called when a new process is created with FORK.
  548. The PREPARE handler is called in the parent process just before performing
  549. FORK. The PARENT handler is called in the parent process just after FORK.
  550. The CHILD handler is called in the child process. Each of the three
  551. handlers can be NULL, meaning that no handler needs to be called at that
  552. point.
  553. PTHREAD_ATFORK can be called several times, in which case the PREPARE
  554. handlers are called in LIFO order (last added with PTHREAD_ATFORK,
  555. first called before FORK), and the PARENT and CHILD handlers are called
  556. in FIFO (first added, first called). */
  557. extern int pthread_atfork (void (*__prepare) (void),
  558. void (*__parent) (void),
  559. void (*__child) (void)) __THROW;
  560. #endif
  561. /* Terminate all threads in the program except the calling process.
  562. Should be called just before invoking one of the exec*() functions. */
  563. extern void pthread_kill_other_threads_np (void) __THROW;
  564. __END_DECLS
  565. #endif /* pthread.h */