pthread.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. /* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _PTHREAD_H
  17. #define _PTHREAD_H 1
  18. #include <features.h>
  19. #include <endian.h>
  20. #include <sched.h>
  21. #include <time.h>
  22. #define __need_sigset_t
  23. #include <signal.h>
  24. #include <bits/pthreadtypes.h>
  25. #include <bits/setjmp.h>
  26. #include <bits/wordsize.h>
  27. #if defined _LIBC && ( defined IS_IN_libc || defined NOT_IN_libc )
  28. #include <bits/uClibc_pthread.h>
  29. #endif
  30. /* Detach state. */
  31. enum
  32. {
  33. PTHREAD_CREATE_JOINABLE,
  34. #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
  35. PTHREAD_CREATE_DETACHED
  36. #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
  37. };
  38. /* Mutex types. */
  39. enum
  40. {
  41. PTHREAD_MUTEX_TIMED_NP,
  42. PTHREAD_MUTEX_RECURSIVE_NP,
  43. PTHREAD_MUTEX_ERRORCHECK_NP,
  44. PTHREAD_MUTEX_ADAPTIVE_NP
  45. #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
  46. ,
  47. PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
  48. PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
  49. PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
  50. PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
  51. #endif
  52. #ifdef __USE_GNU
  53. /* For compatibility. */
  54. , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP
  55. #endif
  56. };
  57. #ifdef __USE_XOPEN2K
  58. /* Robust mutex or not flags. */
  59. enum
  60. {
  61. PTHREAD_MUTEX_STALLED,
  62. PTHREAD_MUTEX_STALLED_NP = PTHREAD_MUTEX_STALLED,
  63. PTHREAD_MUTEX_ROBUST,
  64. PTHREAD_MUTEX_ROBUST_NP = PTHREAD_MUTEX_ROBUST
  65. };
  66. #endif
  67. #ifdef __USE_UNIX98
  68. /* Mutex protocols. */
  69. enum
  70. {
  71. PTHREAD_PRIO_NONE,
  72. PTHREAD_PRIO_INHERIT,
  73. PTHREAD_PRIO_PROTECT
  74. };
  75. #endif
  76. /* Mutex initializers. */
  77. #if __WORDSIZE == 64
  78. # define PTHREAD_MUTEX_INITIALIZER \
  79. { { 0, 0, 0, 0, 0, 0, { 0, 0 } } }
  80. # ifdef __USE_GNU
  81. # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
  82. { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0, 0 } } }
  83. # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
  84. { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0, 0 } } }
  85. # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
  86. { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0, 0 } } }
  87. # endif
  88. #else
  89. # define PTHREAD_MUTEX_INITIALIZER \
  90. { { 0, 0, 0, 0, 0, { 0 } } }
  91. # ifdef __USE_GNU
  92. # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
  93. { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0 } } }
  94. # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
  95. { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0 } } }
  96. # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
  97. { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0 } } }
  98. # endif
  99. #endif
  100. /* Read-write lock types. */
  101. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  102. enum
  103. {
  104. PTHREAD_RWLOCK_PREFER_READER_NP,
  105. PTHREAD_RWLOCK_PREFER_WRITER_NP,
  106. PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
  107. PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP
  108. };
  109. /* Read-write lock initializers. */
  110. # define PTHREAD_RWLOCK_INITIALIZER \
  111. { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
  112. # ifdef __USE_GNU
  113. # if __WORDSIZE == 64
  114. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  115. { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
  116. PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
  117. # else
  118. # if __BYTE_ORDER == __LITTLE_ENDIAN
  119. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  120. { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, \
  121. 0, 0, 0, 0 } }
  122. # else
  123. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  124. { { 0, 0, 0, 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,\
  125. 0 } }
  126. # endif
  127. # endif
  128. # endif
  129. #endif /* Unix98 or XOpen2K */
  130. /* Scheduler inheritance. */
  131. enum
  132. {
  133. PTHREAD_INHERIT_SCHED,
  134. #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
  135. PTHREAD_EXPLICIT_SCHED
  136. #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
  137. };
  138. /* Scope handling. */
  139. enum
  140. {
  141. PTHREAD_SCOPE_SYSTEM,
  142. #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
  143. PTHREAD_SCOPE_PROCESS
  144. #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
  145. };
  146. /* Process shared or private flag. */
  147. enum
  148. {
  149. PTHREAD_PROCESS_PRIVATE,
  150. #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
  151. PTHREAD_PROCESS_SHARED
  152. #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
  153. };
  154. /* Conditional variable handling. */
  155. #define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
  156. /* Cleanup buffers */
  157. struct _pthread_cleanup_buffer
  158. {
  159. void (*__routine) (void *); /* Function to call. */
  160. void *__arg; /* Its argument. */
  161. int __canceltype; /* Saved cancellation type. */
  162. struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */
  163. };
  164. /* Cancellation */
  165. enum
  166. {
  167. PTHREAD_CANCEL_ENABLE,
  168. #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
  169. PTHREAD_CANCEL_DISABLE
  170. #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
  171. };
  172. enum
  173. {
  174. PTHREAD_CANCEL_DEFERRED,
  175. #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
  176. PTHREAD_CANCEL_ASYNCHRONOUS
  177. #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
  178. };
  179. #define PTHREAD_CANCELED ((void *) -1)
  180. /* Single execution handling. */
  181. #define PTHREAD_ONCE_INIT 0
  182. #ifdef __USE_XOPEN2K
  183. /* Value returned by 'pthread_barrier_wait' for one of the threads after
  184. the required number of threads have called this function.
  185. -1 is distinct from 0 and all errno constants */
  186. # define PTHREAD_BARRIER_SERIAL_THREAD -1
  187. #endif
  188. __BEGIN_DECLS
  189. /* Create a new thread, starting with execution of START-ROUTINE
  190. getting passed ARG. Creation attributed come from ATTR. The new
  191. handle is stored in *NEWTHREAD. */
  192. extern int pthread_create (pthread_t *__restrict __newthread,
  193. __const pthread_attr_t *__restrict __attr,
  194. void *(*__start_routine) (void *),
  195. void *__restrict __arg) __THROW __nonnull ((1, 3));
  196. /* Terminate calling thread.
  197. The registered cleanup handlers are called via exception handling
  198. so we cannot mark this function with __THROW.*/
  199. extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
  200. /* Make calling thread wait for termination of the thread TH. The
  201. exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
  202. is not NULL.
  203. This function is a cancellation point and therefore not marked with
  204. __THROW. */
  205. extern int pthread_join (pthread_t __th, void **__thread_return);
  206. #ifdef __USE_GNU
  207. /* Check whether thread TH has terminated. If yes return the status of
  208. the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
  209. extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
  210. /* Make calling thread wait for termination of the thread TH, but only
  211. until TIMEOUT. The exit status of the thread is stored in
  212. *THREAD_RETURN, if THREAD_RETURN is not NULL.
  213. This function is a cancellation point and therefore not marked with
  214. __THROW. */
  215. extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
  216. __const struct timespec *__abstime);
  217. #endif
  218. /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
  219. The resources of TH will therefore be freed immediately when it
  220. terminates, instead of waiting for another thread to perform PTHREAD_JOIN
  221. on it. */
  222. extern int pthread_detach (pthread_t __th) __THROW;
  223. /* Obtain the identifier of the current thread. */
  224. extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__));
  225. /* Compare two thread identifiers. */
  226. extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __THROW;
  227. /* Thread attribute handling. */
  228. /* Initialize thread attribute *ATTR with default attributes
  229. (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
  230. no user-provided stack). */
  231. extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1));
  232. /* Destroy thread attribute *ATTR. */
  233. extern int pthread_attr_destroy (pthread_attr_t *__attr)
  234. __THROW __nonnull ((1));
  235. /* Get detach state attribute. */
  236. extern int pthread_attr_getdetachstate (__const pthread_attr_t *__attr,
  237. int *__detachstate)
  238. __THROW __nonnull ((1, 2));
  239. /* Set detach state attribute. */
  240. extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
  241. int __detachstate)
  242. __THROW __nonnull ((1));
  243. /* Get the size of the guard area created for stack overflow protection. */
  244. extern int pthread_attr_getguardsize (__const pthread_attr_t *__attr,
  245. size_t *__guardsize)
  246. __THROW __nonnull ((1, 2));
  247. /* Set the size of the guard area created for stack overflow protection. */
  248. extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
  249. size_t __guardsize)
  250. __THROW __nonnull ((1));
  251. /* Return in *PARAM the scheduling parameters of *ATTR. */
  252. extern int pthread_attr_getschedparam (__const pthread_attr_t *__restrict
  253. __attr,
  254. struct sched_param *__restrict __param)
  255. __THROW __nonnull ((1, 2));
  256. /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
  257. extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
  258. __const struct sched_param *__restrict
  259. __param) __THROW __nonnull ((1, 2));
  260. /* Return in *POLICY the scheduling policy of *ATTR. */
  261. extern int pthread_attr_getschedpolicy (__const pthread_attr_t *__restrict
  262. __attr, int *__restrict __policy)
  263. __THROW __nonnull ((1, 2));
  264. /* Set scheduling policy in *ATTR according to POLICY. */
  265. extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
  266. __THROW __nonnull ((1));
  267. /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
  268. extern int pthread_attr_getinheritsched (__const pthread_attr_t *__restrict
  269. __attr, int *__restrict __inherit)
  270. __THROW __nonnull ((1, 2));
  271. /* Set scheduling inheritance mode in *ATTR according to INHERIT. */
  272. extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
  273. int __inherit)
  274. __THROW __nonnull ((1));
  275. /* Return in *SCOPE the scheduling contention scope of *ATTR. */
  276. extern int pthread_attr_getscope (__const pthread_attr_t *__restrict __attr,
  277. int *__restrict __scope)
  278. __THROW __nonnull ((1, 2));
  279. /* Set scheduling contention scope in *ATTR according to SCOPE. */
  280. extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
  281. __THROW __nonnull ((1));
  282. /* Return the previously set address for the stack. */
  283. extern int pthread_attr_getstackaddr (__const pthread_attr_t *__restrict
  284. __attr, void **__restrict __stackaddr)
  285. __THROW __nonnull ((1, 2)) __attribute_deprecated__;
  286. /* Set the starting address of the stack of the thread to be created.
  287. Depending on whether the stack grows up or down the value must either
  288. be higher or lower than all the address in the memory block. The
  289. minimal size of the block must be PTHREAD_STACK_MIN. */
  290. extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
  291. void *__stackaddr)
  292. __THROW __nonnull ((1)) __attribute_deprecated__;
  293. /* Return the currently used minimal stack size. */
  294. extern int pthread_attr_getstacksize (__const pthread_attr_t *__restrict
  295. __attr, size_t *__restrict __stacksize)
  296. __THROW __nonnull ((1, 2));
  297. /* Add information about the minimum stack size needed for the thread
  298. to be started. This size must never be less than PTHREAD_STACK_MIN
  299. and must also not exceed the system limits. */
  300. extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
  301. size_t __stacksize)
  302. __THROW __nonnull ((1));
  303. #ifdef __USE_XOPEN2K
  304. /* Return the previously set address for the stack. */
  305. extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
  306. void **__restrict __stackaddr,
  307. size_t *__restrict __stacksize)
  308. __THROW __nonnull ((1, 2, 3));
  309. /* The following two interfaces are intended to replace the last two. They
  310. require setting the address as well as the size since only setting the
  311. address will make the implementation on some architectures impossible. */
  312. extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
  313. size_t __stacksize) __THROW __nonnull ((1));
  314. #endif
  315. #ifdef __USE_GNU
  316. /* Thread created with attribute ATTR will be limited to run only on
  317. the processors represented in CPUSET. */
  318. extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr,
  319. size_t __cpusetsize,
  320. __const cpu_set_t *__cpuset)
  321. __THROW __nonnull ((1, 3));
  322. /* Get bit set in CPUSET representing the processors threads created with
  323. ATTR can run on. */
  324. extern int pthread_attr_getaffinity_np (__const pthread_attr_t *__attr,
  325. size_t __cpusetsize,
  326. cpu_set_t *__cpuset)
  327. __THROW __nonnull ((1, 3));
  328. /* Initialize thread attribute *ATTR with attributes corresponding to the
  329. already running thread TH. It shall be called on uninitialized ATTR
  330. and destroyed with pthread_attr_destroy when no longer needed. */
  331. extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
  332. __THROW __nonnull ((2));
  333. #endif
  334. /* Functions for scheduling control. */
  335. /* Set the scheduling parameters for TARGET_THREAD according to POLICY
  336. and *PARAM. */
  337. extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
  338. __const struct sched_param *__param)
  339. __THROW __nonnull ((3));
  340. /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
  341. extern int pthread_getschedparam (pthread_t __target_thread,
  342. int *__restrict __policy,
  343. struct sched_param *__restrict __param)
  344. __THROW __nonnull ((2, 3));
  345. /* Set the scheduling priority for TARGET_THREAD. */
  346. extern int pthread_setschedprio (pthread_t __target_thread, int __prio)
  347. __THROW;
  348. #ifdef __USE_UNIX98
  349. /* Determine level of concurrency. */
  350. extern int pthread_getconcurrency (void) __THROW;
  351. /* Set new concurrency level to LEVEL. */
  352. extern int pthread_setconcurrency (int __level) __THROW;
  353. #endif
  354. #ifdef __USE_GNU
  355. /* Yield the processor to another thread or process.
  356. This function is similar to the POSIX `sched_yield' function but
  357. might be differently implemented in the case of a m-on-n thread
  358. implementation. */
  359. extern int pthread_yield (void) __THROW;
  360. /* Limit specified thread TH to run only on the processors represented
  361. in CPUSET. */
  362. extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
  363. __const cpu_set_t *__cpuset)
  364. __THROW __nonnull ((3));
  365. /* Get bit set in CPUSET representing the processors TH can run on. */
  366. extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
  367. cpu_set_t *__cpuset)
  368. __THROW __nonnull ((3));
  369. #endif
  370. /* Functions for handling initialization. */
  371. /* Guarantee that the initialization function INIT_ROUTINE will be called
  372. only once, even if pthread_once is executed several times with the
  373. same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
  374. extern variable initialized to PTHREAD_ONCE_INIT.
  375. The initialization functions might throw exception which is why
  376. this function is not marked with __THROW. */
  377. extern int pthread_once (pthread_once_t *__once_control,
  378. void (*__init_routine) (void)) __nonnull ((1, 2));
  379. /* Functions for handling cancellation.
  380. Note that these functions are explicitly not marked to not throw an
  381. exception in C++ code. If cancellation is implemented by unwinding
  382. this is necessary to have the compiler generate the unwind information. */
  383. /* Set cancelability state of current thread to STATE, returning old
  384. state in *OLDSTATE if OLDSTATE is not NULL. */
  385. extern int pthread_setcancelstate (int __state, int *__oldstate);
  386. /* Set cancellation state of current thread to TYPE, returning the old
  387. type in *OLDTYPE if OLDTYPE is not NULL. */
  388. extern int pthread_setcanceltype (int __type, int *__oldtype);
  389. /* Cancel THREAD immediately or at the next possibility. */
  390. extern int pthread_cancel (pthread_t __th);
  391. /* Test for pending cancellation for the current thread and terminate
  392. the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
  393. cancelled. */
  394. extern void pthread_testcancel (void);
  395. /* Cancellation handling with integration into exception handling. */
  396. typedef struct
  397. {
  398. struct
  399. {
  400. __jmp_buf __cancel_jmp_buf;
  401. int __mask_was_saved;
  402. } __cancel_jmp_buf[1];
  403. void *__pad[4];
  404. } __pthread_unwind_buf_t __attribute__ ((__aligned__));
  405. /* No special attributes by default. */
  406. #ifndef __cleanup_fct_attribute
  407. # define __cleanup_fct_attribute
  408. #endif
  409. /* Structure to hold the cleanup handler information. */
  410. struct __pthread_cleanup_frame
  411. {
  412. void (*__cancel_routine) (void *);
  413. void *__cancel_arg;
  414. int __do_it;
  415. int __cancel_type;
  416. };
  417. #if defined __GNUC__ && defined __EXCEPTIONS
  418. # ifdef __cplusplus
  419. /* Class to handle cancellation handler invocation. */
  420. class __pthread_cleanup_class
  421. {
  422. void (*__cancel_routine) (void *);
  423. void *__cancel_arg;
  424. int __do_it;
  425. int __cancel_type;
  426. public:
  427. __pthread_cleanup_class (void (*__fct) (void *), void *__arg)
  428. : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { }
  429. ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); }
  430. void __setdoit (int __newval) { __do_it = __newval; }
  431. void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,
  432. &__cancel_type); }
  433. void __restore () const { pthread_setcanceltype (__cancel_type, 0); }
  434. };
  435. /* Install a cleanup handler: ROUTINE will be called with arguments ARG
  436. when the thread is canceled or calls pthread_exit. ROUTINE will also
  437. be called with arguments ARG when the matching pthread_cleanup_pop
  438. is executed with non-zero EXECUTE argument.
  439. pthread_cleanup_push and pthread_cleanup_pop are macros and must always
  440. be used in matching pairs at the same nesting level of braces. */
  441. # define pthread_cleanup_push(routine, arg) \
  442. do { \
  443. __pthread_cleanup_class __clframe (routine, arg)
  444. /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
  445. If EXECUTE is non-zero, the handler function is called. */
  446. # define pthread_cleanup_pop(execute) \
  447. __clframe.__setdoit (execute); \
  448. } while (0)
  449. # ifdef __USE_GNU
  450. /* Install a cleanup handler as pthread_cleanup_push does, but also
  451. saves the current cancellation type and sets it to deferred
  452. cancellation. */
  453. # define pthread_cleanup_push_defer_np(routine, arg) \
  454. do { \
  455. __pthread_cleanup_class __clframe (routine, arg); \
  456. __clframe.__defer ()
  457. /* Remove a cleanup handler as pthread_cleanup_pop does, but also
  458. restores the cancellation type that was in effect when the matching
  459. pthread_cleanup_push_defer was called. */
  460. # define pthread_cleanup_pop_restore_np(execute) \
  461. __clframe.__restore (); \
  462. __clframe.__setdoit (execute); \
  463. } while (0)
  464. # endif
  465. # else
  466. /* Function called to call the cleanup handler. As an extern inline
  467. function the compiler is free to decide inlining the change when
  468. needed or fall back on the copy which must exist somewhere
  469. else. */
  470. __extern_inline void
  471. __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
  472. {
  473. if (__frame->__do_it)
  474. __frame->__cancel_routine (__frame->__cancel_arg);
  475. }
  476. /* Install a cleanup handler: ROUTINE will be called with arguments ARG
  477. when the thread is canceled or calls pthread_exit. ROUTINE will also
  478. be called with arguments ARG when the matching pthread_cleanup_pop
  479. is executed with non-zero EXECUTE argument.
  480. pthread_cleanup_push and pthread_cleanup_pop are macros and must always
  481. be used in matching pairs at the same nesting level of braces. */
  482. # define pthread_cleanup_push(routine, arg) \
  483. do { \
  484. struct __pthread_cleanup_frame __clframe \
  485. __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
  486. = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
  487. .__do_it = 1 };
  488. /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
  489. If EXECUTE is non-zero, the handler function is called. */
  490. # define pthread_cleanup_pop(execute) \
  491. __clframe.__do_it = (execute); \
  492. } while (0)
  493. # ifdef __USE_GNU
  494. /* Install a cleanup handler as pthread_cleanup_push does, but also
  495. saves the current cancellation type and sets it to deferred
  496. cancellation. */
  497. # define pthread_cleanup_push_defer_np(routine, arg) \
  498. do { \
  499. struct __pthread_cleanup_frame __clframe \
  500. __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
  501. = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
  502. .__do_it = 1 }; \
  503. (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \
  504. &__clframe.__cancel_type)
  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. (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \
  510. __clframe.__do_it = (execute); \
  511. } while (0)
  512. # endif
  513. # endif
  514. #else
  515. /* Install a cleanup handler: ROUTINE will be called with arguments ARG
  516. when the thread is canceled or calls pthread_exit. ROUTINE will also
  517. be called with arguments ARG when the matching pthread_cleanup_pop
  518. is executed with non-zero EXECUTE argument.
  519. pthread_cleanup_push and pthread_cleanup_pop are macros and must always
  520. be used in matching pairs at the same nesting level of braces. */
  521. # define pthread_cleanup_push(routine, arg) \
  522. do { \
  523. __pthread_unwind_buf_t __cancel_buf; \
  524. void (*__cancel_routine) (void *) = (routine); \
  525. void *__cancel_arg = (arg); \
  526. int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \
  527. __cancel_buf.__cancel_jmp_buf, 0); \
  528. if (__builtin_expect (not_first_call, 0)) \
  529. { \
  530. __cancel_routine (__cancel_arg); \
  531. __pthread_unwind_next (&__cancel_buf); \
  532. /* NOTREACHED */ \
  533. } \
  534. \
  535. __pthread_register_cancel (&__cancel_buf); \
  536. do {
  537. extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
  538. __cleanup_fct_attribute;
  539. /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
  540. If EXECUTE is non-zero, the handler function is called. */
  541. # define pthread_cleanup_pop(execute) \
  542. do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
  543. } while (0); \
  544. __pthread_unregister_cancel (&__cancel_buf); \
  545. if (execute) \
  546. __cancel_routine (__cancel_arg); \
  547. } while (0)
  548. extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
  549. __cleanup_fct_attribute;
  550. # ifdef __USE_GNU
  551. /* Install a cleanup handler as pthread_cleanup_push does, but also
  552. saves the current cancellation type and sets it to deferred
  553. cancellation. */
  554. # define pthread_cleanup_push_defer_np(routine, arg) \
  555. do { \
  556. __pthread_unwind_buf_t __cancel_buf; \
  557. void (*__cancel_routine) (void *) = (routine); \
  558. void *__cancel_arg = (arg); \
  559. int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \
  560. __cancel_buf.__cancel_jmp_buf, 0); \
  561. if (__builtin_expect (not_first_call, 0)) \
  562. { \
  563. __cancel_routine (__cancel_arg); \
  564. __pthread_unwind_next (&__cancel_buf); \
  565. /* NOTREACHED */ \
  566. } \
  567. \
  568. __pthread_register_cancel_defer (&__cancel_buf); \
  569. do {
  570. extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf)
  571. __cleanup_fct_attribute;
  572. /* Remove a cleanup handler as pthread_cleanup_pop does, but also
  573. restores the cancellation type that was in effect when the matching
  574. pthread_cleanup_push_defer was called. */
  575. # define pthread_cleanup_pop_restore_np(execute) \
  576. do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
  577. } while (0); \
  578. __pthread_unregister_cancel_restore (&__cancel_buf); \
  579. if (execute) \
  580. __cancel_routine (__cancel_arg); \
  581. } while (0)
  582. extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf)
  583. __cleanup_fct_attribute;
  584. # endif
  585. /* Internal interface to initiate cleanup. */
  586. extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
  587. __cleanup_fct_attribute __attribute__ ((__noreturn__))
  588. # ifndef SHARED
  589. __attribute__ ((__weak__))
  590. # endif
  591. ;
  592. #endif
  593. /* Function used in the macros. */
  594. struct __jmp_buf_tag;
  595. extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROW;
  596. /* Mutex handling. */
  597. /* Initialize a mutex. */
  598. extern int pthread_mutex_init (pthread_mutex_t *__mutex,
  599. __const pthread_mutexattr_t *__mutexattr)
  600. __THROW __nonnull ((1));
  601. /* Destroy a mutex. */
  602. extern int pthread_mutex_destroy (pthread_mutex_t *__mutex)
  603. __THROW __nonnull ((1));
  604. /* Try locking a mutex. */
  605. extern int pthread_mutex_trylock (pthread_mutex_t *__mutex)
  606. __THROW __nonnull ((1));
  607. /* Lock a mutex. */
  608. extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
  609. __THROW __nonnull ((1));
  610. #ifdef __USE_XOPEN2K
  611. /* Wait until lock becomes available, or specified time passes. */
  612. extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
  613. __const struct timespec *__restrict
  614. __abstime) __THROW __nonnull ((1, 2));
  615. #endif
  616. /* Unlock a mutex. */
  617. extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
  618. __THROW __nonnull ((1));
  619. /* Get the priority ceiling of MUTEX. */
  620. extern int pthread_mutex_getprioceiling (__const pthread_mutex_t *
  621. __restrict __mutex,
  622. int *__restrict __prioceiling)
  623. __THROW __nonnull ((1, 2));
  624. /* Set the priority ceiling of MUTEX to PRIOCEILING, return old
  625. priority ceiling value in *OLD_CEILING. */
  626. extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex,
  627. int __prioceiling,
  628. int *__restrict __old_ceiling)
  629. __THROW __nonnull ((1, 3));
  630. #ifdef __USE_XOPEN2K8
  631. /* Declare the state protected by MUTEX as consistent. */
  632. extern int pthread_mutex_consistent (pthread_mutex_t *__mutex)
  633. __THROW __nonnull ((1));
  634. # ifdef __USE_GNU
  635. extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex)
  636. __THROW __nonnull ((1));
  637. # endif
  638. #endif
  639. /* Functions for handling mutex attributes. */
  640. /* Initialize mutex attribute object ATTR with default attributes
  641. (kind is PTHREAD_MUTEX_TIMED_NP). */
  642. extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr)
  643. __THROW __nonnull ((1));
  644. /* Destroy mutex attribute object ATTR. */
  645. extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr)
  646. __THROW __nonnull ((1));
  647. /* Get the process-shared flag of the mutex attribute ATTR. */
  648. extern int pthread_mutexattr_getpshared (__const pthread_mutexattr_t *
  649. __restrict __attr,
  650. int *__restrict __pshared)
  651. __THROW __nonnull ((1, 2));
  652. /* Set the process-shared flag of the mutex attribute ATTR. */
  653. extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
  654. int __pshared)
  655. __THROW __nonnull ((1));
  656. #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
  657. /* Return in *KIND the mutex kind attribute in *ATTR. */
  658. extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
  659. __attr, int *__restrict __kind)
  660. __THROW __nonnull ((1, 2));
  661. /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
  662. PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
  663. PTHREAD_MUTEX_DEFAULT). */
  664. extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
  665. __THROW __nonnull ((1));
  666. #endif
  667. /* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */
  668. extern int pthread_mutexattr_getprotocol (__const pthread_mutexattr_t *
  669. __restrict __attr,
  670. int *__restrict __protocol)
  671. __THROW __nonnull ((1, 2));
  672. /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
  673. PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */
  674. extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr,
  675. int __protocol)
  676. __THROW __nonnull ((1));
  677. /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */
  678. extern int pthread_mutexattr_getprioceiling (__const pthread_mutexattr_t *
  679. __restrict __attr,
  680. int *__restrict __prioceiling)
  681. __THROW __nonnull ((1, 2));
  682. /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */
  683. extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr,
  684. int __prioceiling)
  685. __THROW __nonnull ((1));
  686. #ifdef __USE_XOPEN2K
  687. /* Get the robustness flag of the mutex attribute ATTR. */
  688. extern int pthread_mutexattr_getrobust (__const pthread_mutexattr_t *__attr,
  689. int *__robustness)
  690. __THROW __nonnull ((1, 2));
  691. # ifdef __USE_GNU
  692. extern int pthread_mutexattr_getrobust_np (__const pthread_mutexattr_t *__attr,
  693. int *__robustness)
  694. __THROW __nonnull ((1, 2));
  695. # endif
  696. /* Set the robustness flag of the mutex attribute ATTR. */
  697. extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr,
  698. int __robustness)
  699. __THROW __nonnull ((1));
  700. # ifdef __USE_GNU
  701. extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr,
  702. int __robustness)
  703. __THROW __nonnull ((1));
  704. # endif
  705. #endif
  706. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  707. /* Functions for handling read-write locks. */
  708. /* Initialize read-write lock RWLOCK using attributes ATTR, or use
  709. the default values if later is NULL. */
  710. extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
  711. __const pthread_rwlockattr_t *__restrict
  712. __attr) __THROW __nonnull ((1));
  713. /* Destroy read-write lock RWLOCK. */
  714. extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock)
  715. __THROW __nonnull ((1));
  716. /* Acquire read lock for RWLOCK. */
  717. extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock)
  718. __THROW __nonnull ((1));
  719. /* Try to acquire read lock for RWLOCK. */
  720. extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
  721. __THROW __nonnull ((1));
  722. # ifdef __USE_XOPEN2K
  723. /* Try to acquire read lock for RWLOCK or return after specfied time. */
  724. extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
  725. __const struct timespec *__restrict
  726. __abstime) __THROW __nonnull ((1, 2));
  727. # endif
  728. /* Acquire write lock for RWLOCK. */
  729. extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
  730. __THROW __nonnull ((1));
  731. /* Try to acquire write lock for RWLOCK. */
  732. extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
  733. __THROW __nonnull ((1));
  734. # ifdef __USE_XOPEN2K
  735. /* Try to acquire write lock for RWLOCK or return after specfied time. */
  736. extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
  737. __const struct timespec *__restrict
  738. __abstime) __THROW __nonnull ((1, 2));
  739. # endif
  740. /* Unlock RWLOCK. */
  741. extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
  742. __THROW __nonnull ((1));
  743. /* Functions for handling read-write lock attributes. */
  744. /* Initialize attribute object ATTR with default values. */
  745. extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr)
  746. __THROW __nonnull ((1));
  747. /* Destroy attribute object ATTR. */
  748. extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr)
  749. __THROW __nonnull ((1));
  750. /* Return current setting of process-shared attribute of ATTR in PSHARED. */
  751. extern int pthread_rwlockattr_getpshared (__const pthread_rwlockattr_t *
  752. __restrict __attr,
  753. int *__restrict __pshared)
  754. __THROW __nonnull ((1, 2));
  755. /* Set process-shared attribute of ATTR to PSHARED. */
  756. extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
  757. int __pshared)
  758. __THROW __nonnull ((1));
  759. /* Return current setting of reader/writer preference. */
  760. extern int pthread_rwlockattr_getkind_np (__const pthread_rwlockattr_t *
  761. __restrict __attr,
  762. int *__restrict __pref)
  763. __THROW __nonnull ((1, 2));
  764. /* Set reader/write preference. */
  765. extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
  766. int __pref) __THROW __nonnull ((1));
  767. #endif
  768. /* Functions for handling conditional variables. */
  769. /* Initialize condition variable COND using attributes ATTR, or use
  770. the default values if later is NULL. */
  771. extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
  772. __const pthread_condattr_t *__restrict
  773. __cond_attr) __THROW __nonnull ((1));
  774. /* Destroy condition variable COND. */
  775. extern int pthread_cond_destroy (pthread_cond_t *__cond)
  776. __THROW __nonnull ((1));
  777. /* Wake up one thread waiting for condition variable COND. */
  778. extern int pthread_cond_signal (pthread_cond_t *__cond)
  779. __THROW __nonnull ((1));
  780. /* Wake up all threads waiting for condition variables COND. */
  781. extern int pthread_cond_broadcast (pthread_cond_t *__cond)
  782. __THROW __nonnull ((1));
  783. /* Wait for condition variable COND to be signaled or broadcast.
  784. MUTEX is assumed to be locked before.
  785. This function is a cancellation point and therefore not marked with
  786. __THROW. */
  787. extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
  788. pthread_mutex_t *__restrict __mutex)
  789. __nonnull ((1, 2));
  790. /* Wait for condition variable COND to be signaled or broadcast until
  791. ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an
  792. absolute time specification; zero is the beginning of the epoch
  793. (00:00:00 GMT, January 1, 1970).
  794. This function is a cancellation point and therefore not marked with
  795. __THROW. */
  796. extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
  797. pthread_mutex_t *__restrict __mutex,
  798. __const struct timespec *__restrict
  799. __abstime) __nonnull ((1, 2, 3));
  800. /* Functions for handling condition variable attributes. */
  801. /* Initialize condition variable attribute ATTR. */
  802. extern int pthread_condattr_init (pthread_condattr_t *__attr)
  803. __THROW __nonnull ((1));
  804. /* Destroy condition variable attribute ATTR. */
  805. extern int pthread_condattr_destroy (pthread_condattr_t *__attr)
  806. __THROW __nonnull ((1));
  807. /* Get the process-shared flag of the condition variable attribute ATTR. */
  808. extern int pthread_condattr_getpshared (__const pthread_condattr_t *
  809. __restrict __attr,
  810. int *__restrict __pshared)
  811. __THROW __nonnull ((1, 2));
  812. /* Set the process-shared flag of the condition variable attribute ATTR. */
  813. extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
  814. int __pshared) __THROW __nonnull ((1));
  815. #ifdef __USE_XOPEN2K
  816. /* Get the clock selected for the conditon variable attribute ATTR. */
  817. extern int pthread_condattr_getclock (__const pthread_condattr_t *
  818. __restrict __attr,
  819. __clockid_t *__restrict __clock_id)
  820. __THROW __nonnull ((1, 2));
  821. /* Set the clock selected for the conditon variable attribute ATTR. */
  822. extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
  823. __clockid_t __clock_id)
  824. __THROW __nonnull ((1));
  825. #endif
  826. #ifdef __USE_XOPEN2K
  827. /* Functions to handle spinlocks. */
  828. /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can
  829. be shared between different processes. */
  830. extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
  831. __THROW __nonnull ((1));
  832. /* Destroy the spinlock LOCK. */
  833. extern int pthread_spin_destroy (pthread_spinlock_t *__lock)
  834. __THROW __nonnull ((1));
  835. /* Wait until spinlock LOCK is retrieved. */
  836. extern int pthread_spin_lock (pthread_spinlock_t *__lock)
  837. __THROW __nonnull ((1));
  838. /* Try to lock spinlock LOCK. */
  839. extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
  840. __THROW __nonnull ((1));
  841. /* Release spinlock LOCK. */
  842. extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
  843. __THROW __nonnull ((1));
  844. /* Functions to handle barriers. */
  845. /* Initialize BARRIER with the attributes in ATTR. The barrier is
  846. opened when COUNT waiters arrived. */
  847. extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
  848. __const pthread_barrierattr_t *__restrict
  849. __attr, unsigned int __count)
  850. __THROW __nonnull ((1));
  851. /* Destroy a previously dynamically initialized barrier BARRIER. */
  852. extern int pthread_barrier_destroy (pthread_barrier_t *__barrier)
  853. __THROW __nonnull ((1));
  854. /* Wait on barrier BARRIER. */
  855. extern int pthread_barrier_wait (pthread_barrier_t *__barrier)
  856. __THROW __nonnull ((1));
  857. /* Initialize barrier attribute ATTR. */
  858. extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr)
  859. __THROW __nonnull ((1));
  860. /* Destroy previously dynamically initialized barrier attribute ATTR. */
  861. extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr)
  862. __THROW __nonnull ((1));
  863. /* Get the process-shared flag of the barrier attribute ATTR. */
  864. extern int pthread_barrierattr_getpshared (__const pthread_barrierattr_t *
  865. __restrict __attr,
  866. int *__restrict __pshared)
  867. __THROW __nonnull ((1, 2));
  868. /* Set the process-shared flag of the barrier attribute ATTR. */
  869. extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
  870. int __pshared)
  871. __THROW __nonnull ((1));
  872. #endif
  873. /* Functions for handling thread-specific data. */
  874. /* Create a key value identifying a location in the thread-specific
  875. data area. Each thread maintains a distinct thread-specific data
  876. area. DESTR_FUNCTION, if non-NULL, is called with the value
  877. associated to that key when the key is destroyed.
  878. DESTR_FUNCTION is not called if the value associated is NULL when
  879. the key is destroyed. */
  880. extern int pthread_key_create (pthread_key_t *__key,
  881. void (*__destr_function) (void *))
  882. __THROW __nonnull ((1));
  883. /* Destroy KEY. */
  884. extern int pthread_key_delete (pthread_key_t __key) __THROW;
  885. /* Return current value of the thread-specific data slot identified by KEY. */
  886. extern void *pthread_getspecific (pthread_key_t __key) __THROW;
  887. /* Store POINTER in the thread-specific data slot identified by KEY. */
  888. extern int pthread_setspecific (pthread_key_t __key,
  889. __const void *__pointer) __THROW ;
  890. #ifdef __USE_XOPEN2K
  891. /* Get ID of CPU-time clock for thread THREAD_ID. */
  892. extern int pthread_getcpuclockid (pthread_t __thread_id,
  893. __clockid_t *__clock_id)
  894. __THROW __nonnull ((2));
  895. #endif
  896. /* Install handlers to be called when a new process is created with FORK.
  897. The PREPARE handler is called in the parent process just before performing
  898. FORK. The PARENT handler is called in the parent process just after FORK.
  899. The CHILD handler is called in the child process. Each of the three
  900. handlers can be NULL, meaning that no handler needs to be called at that
  901. point.
  902. PTHREAD_ATFORK can be called several times, in which case the PREPARE
  903. handlers are called in LIFO order (last added with PTHREAD_ATFORK,
  904. first called before FORK), and the PARENT and CHILD handlers are called
  905. in FIFO (first added, first called). */
  906. extern int pthread_atfork (void (*__prepare) (void),
  907. void (*__parent) (void),
  908. void (*__child) (void)) __THROW;
  909. #ifdef __USE_EXTERN_INLINES
  910. /* Optimizations. */
  911. __extern_inline int
  912. __NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2))
  913. {
  914. return __thread1 == __thread2;
  915. }
  916. #endif
  917. __END_DECLS
  918. #endif /* pthread.h */