pthread.h 24 KB

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