pthread.h 39 KB

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