pthread.h 40 KB

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