pthread.h 25 KB

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