pthread.h 42 KB

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