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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _PTHREAD_H
  16. #define _PTHREAD_H 1
  17. #include <features.h>
  18. #include <endian.h>
  19. #include <sched.h>
  20. #include <time.h>
  21. #define __need_sigset_t
  22. #include <signal.h>
  23. #include <bits/pthreadtypes.h>
  24. #include <bits/setjmp.h>
  25. #include <bits/wordsize.h>
  26. #if defined _LIBC && ( defined IS_IN_libc || defined NOT_IN_libc )
  27. #include <bits/uClibc_pthread.h>
  28. #endif
  29. /* Detach state. */
  30. enum
  31. {
  32. PTHREAD_CREATE_JOINABLE,
  33. #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
  34. PTHREAD_CREATE_DETACHED
  35. #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
  36. };
  37. /* Mutex types. */
  38. enum
  39. {
  40. PTHREAD_MUTEX_TIMED_NP,
  41. PTHREAD_MUTEX_RECURSIVE_NP,
  42. PTHREAD_MUTEX_ERRORCHECK_NP,
  43. PTHREAD_MUTEX_ADAPTIVE_NP
  44. #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
  45. ,
  46. PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
  47. PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
  48. PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
  49. PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
  50. #endif
  51. #ifdef __USE_GNU
  52. /* For compatibility. */
  53. , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP
  54. #endif
  55. };
  56. #ifdef __USE_XOPEN2K
  57. /* Robust mutex or not flags. */
  58. enum
  59. {
  60. PTHREAD_MUTEX_STALLED,
  61. PTHREAD_MUTEX_STALLED_NP = PTHREAD_MUTEX_STALLED,
  62. PTHREAD_MUTEX_ROBUST,
  63. PTHREAD_MUTEX_ROBUST_NP = PTHREAD_MUTEX_ROBUST
  64. };
  65. #endif
  66. #ifdef __USE_UNIX98
  67. /* Mutex protocols. */
  68. enum
  69. {
  70. PTHREAD_PRIO_NONE,
  71. PTHREAD_PRIO_INHERIT,
  72. PTHREAD_PRIO_PROTECT
  73. };
  74. #endif
  75. /* Mutex initializers. */
  76. #if __WORDSIZE == 64
  77. # define PTHREAD_MUTEX_INITIALIZER \
  78. { { 0, 0, 0, 0, 0, 0, { 0, 0 } } }
  79. # ifdef __USE_GNU
  80. # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
  81. { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0, 0 } } }
  82. # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
  83. { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0, 0 } } }
  84. # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
  85. { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0, 0 } } }
  86. # endif
  87. #else
  88. # define PTHREAD_MUTEX_INITIALIZER \
  89. { { 0, 0, 0, 0, 0, { 0 } } }
  90. # ifdef __USE_GNU
  91. # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
  92. { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0 } } }
  93. # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
  94. { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0 } } }
  95. # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
  96. { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0 } } }
  97. # endif
  98. #endif
  99. /* Read-write lock types. */
  100. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  101. enum
  102. {
  103. PTHREAD_RWLOCK_PREFER_READER_NP,
  104. PTHREAD_RWLOCK_PREFER_WRITER_NP,
  105. PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
  106. PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP
  107. };
  108. /* Read-write lock initializers. */
  109. # define PTHREAD_RWLOCK_INITIALIZER \
  110. { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
  111. # ifdef __USE_GNU
  112. # if __WORDSIZE == 64
  113. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  114. { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
  115. PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
  116. # else
  117. # if __BYTE_ORDER == __LITTLE_ENDIAN
  118. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  119. { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, \
  120. 0, 0, 0, 0 } }
  121. # else
  122. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  123. { { 0, 0, 0, 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,\
  124. 0 } }
  125. # endif
  126. # endif
  127. # endif
  128. #endif /* Unix98 or XOpen2K */
  129. /* Scheduler inheritance. */
  130. enum
  131. {
  132. PTHREAD_INHERIT_SCHED,
  133. #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
  134. PTHREAD_EXPLICIT_SCHED
  135. #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
  136. };
  137. /* Scope handling. */
  138. enum
  139. {
  140. PTHREAD_SCOPE_SYSTEM,
  141. #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
  142. PTHREAD_SCOPE_PROCESS
  143. #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
  144. };
  145. /* Process shared or private flag. */
  146. enum
  147. {
  148. PTHREAD_PROCESS_PRIVATE,
  149. #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
  150. PTHREAD_PROCESS_SHARED
  151. #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
  152. };
  153. /* Conditional variable handling. */
  154. #define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
  155. /* Cleanup buffers */
  156. struct _pthread_cleanup_buffer
  157. {
  158. void (*__routine) (void *); /* Function to call. */
  159. void *__arg; /* Its argument. */
  160. int __canceltype; /* Saved cancellation type. */
  161. struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */
  162. };
  163. /* Cancellation */
  164. enum
  165. {
  166. PTHREAD_CANCEL_ENABLE,
  167. #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
  168. PTHREAD_CANCEL_DISABLE
  169. #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
  170. };
  171. enum
  172. {
  173. PTHREAD_CANCEL_DEFERRED,
  174. #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
  175. PTHREAD_CANCEL_ASYNCHRONOUS
  176. #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
  177. };
  178. #define PTHREAD_CANCELED ((void *) -1)
  179. /* Single execution handling. */
  180. #define PTHREAD_ONCE_INIT 0
  181. #ifdef __USE_XOPEN2K
  182. /* Value returned by 'pthread_barrier_wait' for one of the threads after
  183. the required number of threads have called this function.
  184. -1 is distinct from 0 and all errno constants */
  185. # define PTHREAD_BARRIER_SERIAL_THREAD -1
  186. #endif
  187. __BEGIN_DECLS
  188. /* Create a new thread, starting with execution of START-ROUTINE
  189. getting passed ARG. Creation attributed come from ATTR. The new
  190. handle is stored in *NEWTHREAD. */
  191. extern int pthread_create (pthread_t *__restrict __newthread,
  192. const pthread_attr_t *__restrict __attr,
  193. void *(*__start_routine) (void *),
  194. void *__restrict __arg) __THROWNL __nonnull ((1, 3));
  195. /* Terminate calling thread.
  196. The registered cleanup handlers are called via exception handling
  197. so we cannot mark this function with __THROW.*/
  198. extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
  199. /* Make calling thread wait for termination of the thread TH. The
  200. exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
  201. is not NULL.
  202. This function is a cancellation point and therefore not marked with
  203. __THROW. */
  204. extern int pthread_join (pthread_t __th, void **__thread_return);
  205. #ifdef __USE_GNU
  206. /* Check whether thread TH has terminated. If yes return the status of
  207. the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
  208. extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
  209. /* Make calling thread wait for termination of the thread TH, but only
  210. until TIMEOUT. The exit status of the thread is stored in
  211. *THREAD_RETURN, if THREAD_RETURN is not NULL.
  212. This function is a cancellation point and therefore not marked with
  213. __THROW. */
  214. extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
  215. const struct timespec *__abstime);
  216. #endif
  217. /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
  218. The resources of TH will therefore be freed immediately when it
  219. terminates, instead of waiting for another thread to perform PTHREAD_JOIN
  220. on it. */
  221. extern int pthread_detach (pthread_t __th) __THROW;
  222. /* Obtain the identifier of the current thread. */
  223. extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__));
  224. /* Compare two thread identifiers. */
  225. extern int pthread_equal (pthread_t __thread1, pthread_t __thread2)
  226. __THROW __attribute__ ((__const__));
  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 __attr,
  253. struct sched_param *__restrict __param)
  254. __THROW __nonnull ((1, 2));
  255. /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
  256. extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
  257. const struct sched_param *__restrict
  258. __param) __THROW __nonnull ((1, 2));
  259. /* Return in *POLICY the scheduling policy of *ATTR. */
  260. extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict
  261. __attr, int *__restrict __policy)
  262. __THROW __nonnull ((1, 2));
  263. /* Set scheduling policy in *ATTR according to POLICY. */
  264. extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
  265. __THROW __nonnull ((1));
  266. /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
  267. extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict
  268. __attr, int *__restrict __inherit)
  269. __THROW __nonnull ((1, 2));
  270. /* Set scheduling inheritance mode in *ATTR according to INHERIT. */
  271. extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
  272. int __inherit)
  273. __THROW __nonnull ((1));
  274. /* Return in *SCOPE the scheduling contention scope of *ATTR. */
  275. extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr,
  276. int *__restrict __scope)
  277. __THROW __nonnull ((1, 2));
  278. /* Set scheduling contention scope in *ATTR according to SCOPE. */
  279. extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
  280. __THROW __nonnull ((1));
  281. /* Return the previously set address for the stack. */
  282. extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict
  283. __attr, void **__restrict __stackaddr)
  284. __THROW __nonnull ((1, 2)) __attribute_deprecated__;
  285. /* Set the starting address of the stack of the thread to be created.
  286. Depending on whether the stack grows up or down the value must either
  287. be higher or lower than all the address in the memory block. The
  288. minimal size of the block must be PTHREAD_STACK_MIN. */
  289. extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
  290. void *__stackaddr)
  291. __THROW __nonnull ((1)) __attribute_deprecated__;
  292. /* Return the currently used minimal stack size. */
  293. extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict
  294. __attr, size_t *__restrict __stacksize)
  295. __THROW __nonnull ((1, 2));
  296. /* Add information about the minimum stack size needed for the thread
  297. to be started. This size must never be less than PTHREAD_STACK_MIN
  298. and must also not exceed the system limits. */
  299. extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
  300. size_t __stacksize)
  301. __THROW __nonnull ((1));
  302. #ifdef __USE_XOPEN2K
  303. /* Return the previously set address for the stack. */
  304. extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr,
  305. void **__restrict __stackaddr,
  306. size_t *__restrict __stacksize)
  307. __THROW __nonnull ((1, 2, 3));
  308. /* The following two interfaces are intended to replace the last two. They
  309. require setting the address as well as the size since only setting the
  310. address will make the implementation on some architectures impossible. */
  311. extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
  312. size_t __stacksize) __THROW __nonnull ((1));
  313. #endif
  314. #ifdef __USE_GNU
  315. /* Thread created with attribute ATTR will be limited to run only on
  316. the processors represented in CPUSET. */
  317. extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr,
  318. size_t __cpusetsize,
  319. const cpu_set_t *__cpuset)
  320. __THROW __nonnull ((1, 3));
  321. /* Get bit set in CPUSET representing the processors threads created with
  322. ATTR can run on. */
  323. extern int pthread_attr_getaffinity_np (const pthread_attr_t *__attr,
  324. size_t __cpusetsize,
  325. cpu_set_t *__cpuset)
  326. __THROW __nonnull ((1, 3));
  327. /* Initialize thread attribute *ATTR with attributes corresponding to the
  328. already running thread TH. It shall be called on uninitialized ATTR
  329. and destroyed with pthread_attr_destroy when no longer needed. */
  330. extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
  331. __THROW __nonnull ((2));
  332. #endif
  333. /* Functions for scheduling control. */
  334. /* Set the scheduling parameters for TARGET_THREAD according to POLICY
  335. and *PARAM. */
  336. extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
  337. const struct sched_param *__param)
  338. __THROW __nonnull ((3));
  339. /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
  340. extern int pthread_getschedparam (pthread_t __target_thread,
  341. int *__restrict __policy,
  342. struct sched_param *__restrict __param)
  343. __THROW __nonnull ((2, 3));
  344. /* Set the scheduling priority for TARGET_THREAD. */
  345. extern int pthread_setschedprio (pthread_t __target_thread, int __prio)
  346. __THROW;
  347. #if defined __USE_UNIX98 && defined __UCLIBC_SUSV4_LEGACY__
  348. /* Determine level of concurrency. */
  349. extern int pthread_getconcurrency (void) __THROW;
  350. /* Set new concurrency level to LEVEL. */
  351. extern int pthread_setconcurrency (int __level) __THROW;
  352. #endif
  353. #ifdef __USE_GNU
  354. /* Yield the processor to another thread or process.
  355. This function is similar to the POSIX `sched_yield' function but
  356. might be differently implemented in the case of a m-on-n thread
  357. implementation. */
  358. extern int pthread_yield (void) __THROW;
  359. /* Limit specified thread TH to run only on the processors represented
  360. in CPUSET. */
  361. extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
  362. const cpu_set_t *__cpuset)
  363. __THROW __nonnull ((3));
  364. /* Get bit set in CPUSET representing the processors TH can run on. */
  365. extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
  366. cpu_set_t *__cpuset)
  367. __THROW __nonnull ((3));
  368. #endif
  369. /* Functions for handling initialization. */
  370. /* Guarantee that the initialization function INIT_ROUTINE will be called
  371. only once, even if pthread_once is executed several times with the
  372. same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
  373. extern variable initialized to PTHREAD_ONCE_INIT.
  374. The initialization functions might throw exception which is why
  375. this function is not marked with __THROW. */
  376. extern int pthread_once (pthread_once_t *__once_control,
  377. void (*__init_routine) (void)) __nonnull ((1, 2));
  378. /* Functions for handling cancellation.
  379. Note that these functions are explicitly not marked to not throw an
  380. exception in C++ code. If cancellation is implemented by unwinding
  381. this is necessary to have the compiler generate the unwind information. */
  382. /* Set cancelability state of current thread to STATE, returning old
  383. state in *OLDSTATE if OLDSTATE is not NULL. */
  384. extern int pthread_setcancelstate (int __state, int *__oldstate);
  385. /* Set cancellation state of current thread to TYPE, returning the old
  386. type in *OLDTYPE if OLDTYPE is not NULL. */
  387. extern int pthread_setcanceltype (int __type, int *__oldtype);
  388. /* Cancel THREAD immediately or at the next possibility. */
  389. extern int pthread_cancel (pthread_t __th);
  390. /* Test for pending cancellation for the current thread and terminate
  391. the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
  392. cancelled. */
  393. extern void pthread_testcancel (void);
  394. /* Cancellation handling with integration into exception handling. */
  395. typedef struct
  396. {
  397. struct
  398. {
  399. __jmp_buf __cancel_jmp_buf;
  400. int __mask_was_saved;
  401. } __cancel_jmp_buf[1];
  402. void *__pad[4];
  403. } __pthread_unwind_buf_t __attribute__ ((__aligned__));
  404. /* No special attributes by default. */
  405. #ifndef __cleanup_fct_attribute
  406. # define __cleanup_fct_attribute
  407. #endif
  408. /* Structure to hold the cleanup handler information. */
  409. struct __pthread_cleanup_frame
  410. {
  411. void (*__cancel_routine) (void *);
  412. void *__cancel_arg;
  413. int __do_it;
  414. int __cancel_type;
  415. };
  416. #if defined __GNUC__ && defined __EXCEPTIONS
  417. # ifdef __cplusplus
  418. /* Class to handle cancellation handler invocation. */
  419. class __pthread_cleanup_class
  420. {
  421. void (*__cancel_routine) (void *);
  422. void *__cancel_arg;
  423. int __do_it;
  424. int __cancel_type;
  425. public:
  426. __pthread_cleanup_class (void (*__fct) (void *), void *__arg)
  427. : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { }
  428. ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); }
  429. void __setdoit (int __newval) { __do_it = __newval; }
  430. void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,
  431. &__cancel_type); }
  432. void __restore () const { pthread_setcanceltype (__cancel_type, 0); }
  433. };
  434. /* Install a cleanup handler: ROUTINE will be called with arguments ARG
  435. when the thread is canceled or calls pthread_exit. ROUTINE will also
  436. be called with arguments ARG when the matching pthread_cleanup_pop
  437. is executed with non-zero EXECUTE argument.
  438. pthread_cleanup_push and pthread_cleanup_pop are macros and must always
  439. be used in matching pairs at the same nesting level of braces. */
  440. # define pthread_cleanup_push(routine, arg) \
  441. do { \
  442. __pthread_cleanup_class __clframe (routine, arg)
  443. /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
  444. If EXECUTE is non-zero, the handler function is called. */
  445. # define pthread_cleanup_pop(execute) \
  446. __clframe.__setdoit (execute); \
  447. } while (0)
  448. # ifdef __USE_GNU
  449. /* Install a cleanup handler as pthread_cleanup_push does, but also
  450. saves the current cancellation type and sets it to deferred
  451. cancellation. */
  452. # define pthread_cleanup_push_defer_np(routine, arg) \
  453. do { \
  454. __pthread_cleanup_class __clframe (routine, arg); \
  455. __clframe.__defer ()
  456. /* Remove a cleanup handler as pthread_cleanup_pop does, but also
  457. restores the cancellation type that was in effect when the matching
  458. pthread_cleanup_push_defer was called. */
  459. # define pthread_cleanup_pop_restore_np(execute) \
  460. __clframe.__restore (); \
  461. __clframe.__setdoit (execute); \
  462. } while (0)
  463. # endif
  464. # else
  465. /* Function called to call the cleanup handler. As an extern inline
  466. function the compiler is free to decide inlining the change when
  467. needed or fall back on the copy which must exist somewhere
  468. else. */
  469. void __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame);
  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) __THROWNL;
  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. __THROWNL __nonnull ((1));
  607. /* Lock a mutex. */
  608. extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
  609. __THROWNL __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) __THROWNL __nonnull ((1, 2));
  615. #endif
  616. /* Unlock a mutex. */
  617. extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
  618. __THROWNL __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. __THROWNL __nonnull ((1));
  719. /* Try to acquire read lock for RWLOCK. */
  720. extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
  721. __THROWNL __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) __THROWNL __nonnull ((1, 2));
  727. # endif
  728. /* Acquire write lock for RWLOCK. */
  729. extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
  730. __THROWNL __nonnull ((1));
  731. /* Try to acquire write lock for RWLOCK. */
  732. extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
  733. __THROWNL __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) __THROWNL __nonnull ((1, 2));
  739. # endif
  740. /* Unlock RWLOCK. */
  741. extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
  742. __THROWNL __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 __cond_attr)
  773. __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. __THROWNL __nonnull ((1));
  780. /* Wake up all threads waiting for condition variables COND. */
  781. extern int pthread_cond_broadcast (pthread_cond_t *__cond)
  782. __THROWNL __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 __abstime)
  799. __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 condition 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 condition 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. __THROWNL __nonnull ((1));
  838. /* Try to lock spinlock LOCK. */
  839. extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
  840. __THROWNL __nonnull ((1));
  841. /* Release spinlock LOCK. */
  842. extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
  843. __THROWNL __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. __THROWNL __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 */