pthread.h 40 KB

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