pthread.h 40 KB

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