pthread.h 26 KB

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