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/wordsize.h>
  26. #if defined _LIBC && ( defined IS_IN_libc || defined NOT_IN_libc )
  27. #include <bits/uClibc_pthread.h>
  28. #endif
  29. /* Detach state. */
  30. enum
  31. {
  32. PTHREAD_CREATE_JOINABLE,
  33. #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
  34. PTHREAD_CREATE_DETACHED
  35. #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
  36. };
  37. /* Mutex types. */
  38. enum
  39. {
  40. PTHREAD_MUTEX_TIMED_NP,
  41. PTHREAD_MUTEX_RECURSIVE_NP,
  42. PTHREAD_MUTEX_ERRORCHECK_NP,
  43. PTHREAD_MUTEX_ADAPTIVE_NP
  44. #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
  45. ,
  46. PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
  47. PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
  48. PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
  49. PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
  50. #endif
  51. #ifdef __USE_GNU
  52. /* For compatibility. */
  53. , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP
  54. #endif
  55. };
  56. #ifdef __USE_XOPEN2K
  57. /* Robust mutex or not flags. */
  58. enum
  59. {
  60. PTHREAD_MUTEX_STALLED,
  61. PTHREAD_MUTEX_STALLED_NP = PTHREAD_MUTEX_STALLED,
  62. PTHREAD_MUTEX_ROBUST,
  63. PTHREAD_MUTEX_ROBUST_NP = PTHREAD_MUTEX_ROBUST
  64. };
  65. #endif
  66. #ifdef __USE_UNIX98
  67. /* Mutex protocols. */
  68. enum
  69. {
  70. PTHREAD_PRIO_NONE,
  71. PTHREAD_PRIO_INHERIT,
  72. PTHREAD_PRIO_PROTECT
  73. };
  74. #endif
  75. /* Mutex initializers. */
  76. #if __WORDSIZE == 64
  77. # define PTHREAD_MUTEX_INITIALIZER \
  78. { { 0, 0, 0, 0, 0, 0, { 0, 0 } } }
  79. # ifdef __USE_GNU
  80. # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
  81. { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0, 0 } } }
  82. # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
  83. { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0, 0 } } }
  84. # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
  85. { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0, 0 } } }
  86. # endif
  87. #else
  88. # define PTHREAD_MUTEX_INITIALIZER \
  89. { { 0, 0, 0, 0, 0, { 0 } } }
  90. # ifdef __USE_GNU
  91. # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
  92. { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { 0 } } }
  93. # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
  94. { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { 0 } } }
  95. # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
  96. { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { 0 } } }
  97. # endif
  98. #endif
  99. /* Read-write lock types. */
  100. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  101. enum
  102. {
  103. PTHREAD_RWLOCK_PREFER_READER_NP,
  104. PTHREAD_RWLOCK_PREFER_WRITER_NP,
  105. PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
  106. PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP
  107. };
  108. /* Read-write lock initializers. */
  109. # define PTHREAD_RWLOCK_INITIALIZER \
  110. { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
  111. # ifdef __USE_GNU
  112. # if __WORDSIZE == 64
  113. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  114. { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
  115. PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
  116. # else
  117. # if __BYTE_ORDER == __LITTLE_ENDIAN
  118. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  119. { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, \
  120. 0, 0, 0, 0 } }
  121. # else
  122. # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
  123. { { 0, 0, 0, 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,\
  124. 0 } }
  125. # endif
  126. # endif
  127. # endif
  128. #endif /* Unix98 or XOpen2K */
  129. /* Scheduler inheritance. */
  130. enum
  131. {
  132. PTHREAD_INHERIT_SCHED,
  133. #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
  134. PTHREAD_EXPLICIT_SCHED
  135. #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
  136. };
  137. /* Scope handling. */
  138. enum
  139. {
  140. PTHREAD_SCOPE_SYSTEM,
  141. #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
  142. PTHREAD_SCOPE_PROCESS
  143. #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
  144. };
  145. /* Process shared or private flag. */
  146. enum
  147. {
  148. PTHREAD_PROCESS_PRIVATE,
  149. #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
  150. PTHREAD_PROCESS_SHARED
  151. #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
  152. };
  153. /* Conditional variable handling. */
  154. #define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
  155. /* Cleanup buffers */
  156. struct _pthread_cleanup_buffer
  157. {
  158. void (*__routine) (void *); /* Function to call. */
  159. void *__arg; /* Its argument. */
  160. int __canceltype; /* Saved cancellation type. */
  161. struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */
  162. };
  163. /* Cancellation */
  164. enum
  165. {
  166. PTHREAD_CANCEL_ENABLE,
  167. #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
  168. PTHREAD_CANCEL_DISABLE
  169. #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
  170. };
  171. enum
  172. {
  173. PTHREAD_CANCEL_DEFERRED,
  174. #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
  175. PTHREAD_CANCEL_ASYNCHRONOUS
  176. #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
  177. };
  178. #define PTHREAD_CANCELED ((void *) -1)
  179. /* Single execution handling. */
  180. #define PTHREAD_ONCE_INIT 0
  181. #ifdef __USE_XOPEN2K
  182. /* Value returned by 'pthread_barrier_wait' for one of the threads after
  183. the required number of threads have called this function.
  184. -1 is distinct from 0 and all errno constants */
  185. # define PTHREAD_BARRIER_SERIAL_THREAD -1
  186. #endif
  187. __BEGIN_DECLS
  188. /* Create a new thread, starting with execution of START-ROUTINE
  189. getting passed ARG. Creation attributed come from ATTR. The new
  190. handle is stored in *NEWTHREAD. */
  191. extern int pthread_create (pthread_t *__restrict __newthread,
  192. const pthread_attr_t *__restrict __attr,
  193. void *(*__start_routine) (void *),
  194. void *__restrict __arg) __THROWNL __nonnull ((1, 3));
  195. /* Terminate calling thread.
  196. The registered cleanup handlers are called via exception handling
  197. so we cannot mark this function with __THROW.*/
  198. extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
  199. /* Make calling thread wait for termination of the thread TH. The
  200. exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
  201. is not NULL.
  202. This function is a cancellation point and therefore not marked with
  203. __THROW. */
  204. extern int pthread_join (pthread_t __th, void **__thread_return);
  205. #ifdef __USE_GNU
  206. /* Check whether thread TH has terminated. If yes return the status of
  207. the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
  208. extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
  209. /* Make calling thread wait for termination of the thread TH, but only
  210. until TIMEOUT. The exit status of the thread is stored in
  211. *THREAD_RETURN, if THREAD_RETURN is not NULL.
  212. This function is a cancellation point and therefore not marked with
  213. __THROW. */
  214. extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
  215. const struct timespec *__abstime);
  216. #endif
  217. /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
  218. The resources of TH will therefore be freed immediately when it
  219. terminates, instead of waiting for another thread to perform PTHREAD_JOIN
  220. on it. */
  221. extern int pthread_detach (pthread_t __th) __THROW;
  222. /* Obtain the identifier of the current thread. */
  223. extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__));
  224. /* Compare two thread identifiers. */
  225. extern int pthread_equal (pthread_t __thread1, pthread_t __thread2)
  226. __THROW __attribute__ ((__const__));
  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 __attr,
  253. struct sched_param *__restrict __param)
  254. __THROW __nonnull ((1, 2));
  255. /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
  256. extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
  257. const struct sched_param *__restrict
  258. __param) __THROW __nonnull ((1, 2));
  259. /* Return in *POLICY the scheduling policy of *ATTR. */
  260. extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict
  261. __attr, int *__restrict __policy)
  262. __THROW __nonnull ((1, 2));
  263. /* Set scheduling policy in *ATTR according to POLICY. */
  264. extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
  265. __THROW __nonnull ((1));
  266. /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
  267. extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict
  268. __attr, int *__restrict __inherit)
  269. __THROW __nonnull ((1, 2));
  270. /* Set scheduling inheritance mode in *ATTR according to INHERIT. */
  271. extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
  272. int __inherit)
  273. __THROW __nonnull ((1));
  274. /* Return in *SCOPE the scheduling contention scope of *ATTR. */
  275. extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr,
  276. int *__restrict __scope)
  277. __THROW __nonnull ((1, 2));
  278. /* Set scheduling contention scope in *ATTR according to SCOPE. */
  279. extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
  280. __THROW __nonnull ((1));
  281. /* Return the previously set address for the stack. */
  282. extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict
  283. __attr, void **__restrict __stackaddr)
  284. __THROW __nonnull ((1, 2)) __attribute_deprecated__;
  285. /* Set the starting address of the stack of the thread to be created.
  286. Depending on whether the stack grows up or down the value must either
  287. be higher or lower than all the address in the memory block. The
  288. minimal size of the block must be PTHREAD_STACK_MIN. */
  289. extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
  290. void *__stackaddr)
  291. __THROW __nonnull ((1)) __attribute_deprecated__;
  292. /* Return the currently used minimal stack size. */
  293. extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict
  294. __attr, size_t *__restrict __stacksize)
  295. __THROW __nonnull ((1, 2));
  296. /* Add information about the minimum stack size needed for the thread
  297. to be started. This size must never be less than PTHREAD_STACK_MIN
  298. and must also not exceed the system limits. */
  299. extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
  300. size_t __stacksize)
  301. __THROW __nonnull ((1));
  302. #ifdef __USE_XOPEN2K
  303. /* Return the previously set address for the stack. */
  304. extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr,
  305. void **__restrict __stackaddr,
  306. size_t *__restrict __stacksize)
  307. __THROW __nonnull ((1, 2, 3));
  308. /* The following two interfaces are intended to replace the last two. They
  309. require setting the address as well as the size since only setting the
  310. address will make the implementation on some architectures impossible. */
  311. extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
  312. size_t __stacksize) __THROW __nonnull ((1));
  313. #endif
  314. #ifdef __USE_GNU
  315. /* Thread created with attribute ATTR will be limited to run only on
  316. the processors represented in CPUSET. */
  317. extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr,
  318. size_t __cpusetsize,
  319. const cpu_set_t *__cpuset)
  320. __THROW __nonnull ((1, 3));
  321. /* Get bit set in CPUSET representing the processors threads created with
  322. ATTR can run on. */
  323. extern int pthread_attr_getaffinity_np (const pthread_attr_t *__attr,
  324. size_t __cpusetsize,
  325. cpu_set_t *__cpuset)
  326. __THROW __nonnull ((1, 3));
  327. /* Initialize thread attribute *ATTR with attributes corresponding to the
  328. already running thread TH. It shall be called on uninitialized ATTR
  329. and destroyed with pthread_attr_destroy when no longer needed. */
  330. extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
  331. __THROW __nonnull ((2));
  332. #endif
  333. /* Functions for scheduling control. */
  334. /* Set the scheduling parameters for TARGET_THREAD according to POLICY
  335. and *PARAM. */
  336. extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
  337. const struct sched_param *__param)
  338. __THROW __nonnull ((3));
  339. /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
  340. extern int pthread_getschedparam (pthread_t __target_thread,
  341. int *__restrict __policy,
  342. struct sched_param *__restrict __param)
  343. __THROW __nonnull ((2, 3));
  344. /* Set the scheduling priority for TARGET_THREAD. */
  345. extern int pthread_setschedprio (pthread_t __target_thread, int __prio)
  346. __THROW;
  347. #ifdef __USE_GNU
  348. /* Get thread name visible in the kernel and its interfaces. */
  349. extern int pthread_getname_np (pthread_t __target_thread, char *__buf,
  350. size_t __buflen)
  351. __THROW __nonnull ((2));
  352. /* Set thread name visible in the kernel and its interfaces. */
  353. extern int pthread_setname_np (pthread_t __target_thread, const char *__name)
  354. __THROW __nonnull ((2));
  355. #endif
  356. #if defined __USE_UNIX98 && defined __UCLIBC_SUSV4_LEGACY__
  357. /* Determine level of concurrency. */
  358. extern int pthread_getconcurrency (void) __THROW;
  359. /* Set new concurrency level to LEVEL. */
  360. extern int pthread_setconcurrency (int __level) __THROW;
  361. #endif
  362. #ifdef __USE_GNU
  363. /* Yield the processor to another thread or process.
  364. This function is similar to the POSIX `sched_yield' function but
  365. might be differently implemented in the case of a m-on-n thread
  366. implementation. */
  367. extern int pthread_yield (void) __THROW;
  368. /* Limit specified thread TH to run only on the processors represented
  369. in CPUSET. */
  370. extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
  371. const cpu_set_t *__cpuset)
  372. __THROW __nonnull ((3));
  373. /* Get bit set in CPUSET representing the processors TH can run on. */
  374. extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
  375. cpu_set_t *__cpuset)
  376. __THROW __nonnull ((3));
  377. #endif
  378. /* Functions for handling initialization. */
  379. /* Guarantee that the initialization function INIT_ROUTINE will be called
  380. only once, even if pthread_once is executed several times with the
  381. same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
  382. extern variable initialized to PTHREAD_ONCE_INIT.
  383. The initialization functions might throw exception which is why
  384. this function is not marked with __THROW. */
  385. extern int pthread_once (pthread_once_t *__once_control,
  386. void (*__init_routine) (void)) __nonnull ((1, 2));
  387. /* Functions for handling cancellation.
  388. Note that these functions are explicitly not marked to not throw an
  389. exception in C++ code. If cancellation is implemented by unwinding
  390. this is necessary to have the compiler generate the unwind information. */
  391. /* Set cancelability state of current thread to STATE, returning old
  392. state in *OLDSTATE if OLDSTATE is not NULL. */
  393. extern int pthread_setcancelstate (int __state, int *__oldstate);
  394. /* Set cancellation state of current thread to TYPE, returning the old
  395. type in *OLDTYPE if OLDTYPE is not NULL. */
  396. extern int pthread_setcanceltype (int __type, int *__oldtype);
  397. /* Cancel THREAD immediately or at the next possibility. */
  398. extern int pthread_cancel (pthread_t __th);
  399. /* Test for pending cancellation for the current thread and terminate
  400. the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
  401. cancelled. */
  402. extern void pthread_testcancel (void);
  403. /* Cancellation handling with integration into exception handling. */
  404. typedef struct
  405. {
  406. struct
  407. {
  408. __jmp_buf __cancel_jmp_buf;
  409. int __mask_was_saved;
  410. } __cancel_jmp_buf[1];
  411. void *__pad[4];
  412. } __pthread_unwind_buf_t __attribute__ ((__aligned__));
  413. /* No special attributes by default. */
  414. #ifndef __cleanup_fct_attribute
  415. # define __cleanup_fct_attribute
  416. #endif
  417. /* Structure to hold the cleanup handler information. */
  418. struct __pthread_cleanup_frame
  419. {
  420. void (*__cancel_routine) (void *);
  421. void *__cancel_arg;
  422. int __do_it;
  423. int __cancel_type;
  424. };
  425. #if defined __GNUC__ && defined __EXCEPTIONS
  426. # ifdef __cplusplus
  427. /* Class to handle cancellation handler invocation. */
  428. class __pthread_cleanup_class
  429. {
  430. void (*__cancel_routine) (void *);
  431. void *__cancel_arg;
  432. int __do_it;
  433. int __cancel_type;
  434. public:
  435. __pthread_cleanup_class (void (*__fct) (void *), void *__arg)
  436. : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { }
  437. ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); }
  438. void __setdoit (int __newval) { __do_it = __newval; }
  439. void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,
  440. &__cancel_type); }
  441. void __restore () const { pthread_setcanceltype (__cancel_type, 0); }
  442. };
  443. /* Install a cleanup handler: ROUTINE will be called with arguments ARG
  444. when the thread is canceled or calls pthread_exit. ROUTINE will also
  445. be called with arguments ARG when the matching pthread_cleanup_pop
  446. is executed with non-zero EXECUTE argument.
  447. pthread_cleanup_push and pthread_cleanup_pop are macros and must always
  448. be used in matching pairs at the same nesting level of braces. */
  449. # define pthread_cleanup_push(routine, arg) \
  450. do { \
  451. __pthread_cleanup_class __clframe (routine, arg)
  452. /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
  453. If EXECUTE is non-zero, the handler function is called. */
  454. # define pthread_cleanup_pop(execute) \
  455. __clframe.__setdoit (execute); \
  456. } while (0)
  457. # ifdef __USE_GNU
  458. /* Install a cleanup handler as pthread_cleanup_push does, but also
  459. saves the current cancellation type and sets it to deferred
  460. cancellation. */
  461. # define pthread_cleanup_push_defer_np(routine, arg) \
  462. do { \
  463. __pthread_cleanup_class __clframe (routine, arg); \
  464. __clframe.__defer ()
  465. /* Remove a cleanup handler as pthread_cleanup_pop does, but also
  466. restores the cancellation type that was in effect when the matching
  467. pthread_cleanup_push_defer was called. */
  468. # define pthread_cleanup_pop_restore_np(execute) \
  469. __clframe.__restore (); \
  470. __clframe.__setdoit (execute); \
  471. } while (0)
  472. # endif
  473. # else
  474. /* Function called to call the cleanup handler. As an extern inline
  475. function the compiler is free to decide inlining the change when
  476. needed or fall back on the copy which must exist somewhere
  477. else. */
  478. void __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame);
  479. __extern_inline void
  480. __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
  481. {
  482. if (__frame->__do_it)
  483. __frame->__cancel_routine (__frame->__cancel_arg);
  484. }
  485. /* Install a cleanup handler: ROUTINE will be called with arguments ARG
  486. when the thread is canceled or calls pthread_exit. ROUTINE will also
  487. be called with arguments ARG when the matching pthread_cleanup_pop
  488. is executed with non-zero EXECUTE argument.
  489. pthread_cleanup_push and pthread_cleanup_pop are macros and must always
  490. be used in matching pairs at the same nesting level of braces. */
  491. # define pthread_cleanup_push(routine, arg) \
  492. do { \
  493. struct __pthread_cleanup_frame __clframe \
  494. __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
  495. = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
  496. .__do_it = 1 };
  497. /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
  498. If EXECUTE is non-zero, the handler function is called. */
  499. # define pthread_cleanup_pop(execute) \
  500. __clframe.__do_it = (execute); \
  501. } while (0)
  502. # ifdef __USE_GNU
  503. /* Install a cleanup handler as pthread_cleanup_push does, but also
  504. saves the current cancellation type and sets it to deferred
  505. cancellation. */
  506. # define pthread_cleanup_push_defer_np(routine, arg) \
  507. do { \
  508. struct __pthread_cleanup_frame __clframe \
  509. __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
  510. = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
  511. .__do_it = 1 }; \
  512. (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \
  513. &__clframe.__cancel_type)
  514. /* Remove a cleanup handler as pthread_cleanup_pop does, but also
  515. restores the cancellation type that was in effect when the matching
  516. pthread_cleanup_push_defer was called. */
  517. # define pthread_cleanup_pop_restore_np(execute) \
  518. (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \
  519. __clframe.__do_it = (execute); \
  520. } while (0)
  521. # endif
  522. # endif
  523. #else
  524. /* Install a cleanup handler: ROUTINE will be called with arguments ARG
  525. when the thread is canceled or calls pthread_exit. ROUTINE will also
  526. be called with arguments ARG when the matching pthread_cleanup_pop
  527. is executed with non-zero EXECUTE argument.
  528. pthread_cleanup_push and pthread_cleanup_pop are macros and must always
  529. be used in matching pairs at the same nesting level of braces. */
  530. # define pthread_cleanup_push(routine, arg) \
  531. do { \
  532. __pthread_unwind_buf_t __cancel_buf; \
  533. void (*__cancel_routine) (void *) = (routine); \
  534. void *__cancel_arg = (arg); \
  535. int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \
  536. __cancel_buf.__cancel_jmp_buf, 0); \
  537. if (__builtin_expect (__not_first_call, 0)) \
  538. { \
  539. __cancel_routine (__cancel_arg); \
  540. __pthread_unwind_next (&__cancel_buf); \
  541. /* NOTREACHED */ \
  542. } \
  543. \
  544. __pthread_register_cancel (&__cancel_buf); \
  545. do {
  546. extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
  547. __cleanup_fct_attribute;
  548. /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
  549. If EXECUTE is non-zero, the handler function is called. */
  550. # define pthread_cleanup_pop(execute) \
  551. do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
  552. } while (0); \
  553. __pthread_unregister_cancel (&__cancel_buf); \
  554. if (execute) \
  555. __cancel_routine (__cancel_arg); \
  556. } while (0)
  557. extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
  558. __cleanup_fct_attribute;
  559. # ifdef __USE_GNU
  560. /* Install a cleanup handler as pthread_cleanup_push does, but also
  561. saves the current cancellation type and sets it to deferred
  562. cancellation. */
  563. # define pthread_cleanup_push_defer_np(routine, arg) \
  564. do { \
  565. __pthread_unwind_buf_t __cancel_buf; \
  566. void (*__cancel_routine) (void *) = (routine); \
  567. void *__cancel_arg = (arg); \
  568. int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \
  569. __cancel_buf.__cancel_jmp_buf, 0); \
  570. if (__builtin_expect (__not_first_call, 0)) \
  571. { \
  572. __cancel_routine (__cancel_arg); \
  573. __pthread_unwind_next (&__cancel_buf); \
  574. /* NOTREACHED */ \
  575. } \
  576. \
  577. __pthread_register_cancel_defer (&__cancel_buf); \
  578. do {
  579. extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf)
  580. __cleanup_fct_attribute;
  581. /* Remove a cleanup handler as pthread_cleanup_pop does, but also
  582. restores the cancellation type that was in effect when the matching
  583. pthread_cleanup_push_defer was called. */
  584. # define pthread_cleanup_pop_restore_np(execute) \
  585. do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
  586. } while (0); \
  587. __pthread_unregister_cancel_restore (&__cancel_buf); \
  588. if (execute) \
  589. __cancel_routine (__cancel_arg); \
  590. } while (0)
  591. extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf)
  592. __cleanup_fct_attribute;
  593. # endif
  594. /* Internal interface to initiate cleanup. */
  595. extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
  596. __cleanup_fct_attribute __attribute__ ((__noreturn__))
  597. # ifndef SHARED
  598. __attribute__ ((__weak__))
  599. # endif
  600. ;
  601. #endif
  602. /* Function used in the macros. */
  603. struct __jmp_buf_tag;
  604. extern int __sigsetjmp (struct __jmp_buf_tag *__env, 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 */