pthread.h 41 KB

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