pthread.h 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616
  1. /*++
  2. Copyright (c) 2015 Minoca Corp.
  3. This file is licensed under the terms of the GNU Lesser General Public
  4. License version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details.
  6. Module Name:
  7. pthread.h
  8. Abstract:
  9. This header contains definitions for the POSIX thread library.
  10. Author:
  11. Evan Green 27-Apr-2015
  12. --*/
  13. #ifndef _PTHREAD_H
  14. #define _PTHREAD_H
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. #include <libcbase.h>
  19. #include <sched.h>
  20. #include <stdarg.h>
  21. #include <stddef.h>
  22. //
  23. // --------------------------------------------------------------------- Macros
  24. //
  25. //
  26. // These macros push and pop a cleanup item. They must be used in matching
  27. // pairs. They introduce braces, so the use of setjmp, longjmp, return, break,
  28. // or continue in between matching calls to push and pop will cause undefined
  29. // results. Interestingly enough, this is POSIX compliant behavior.
  30. //
  31. #define pthread_cleanup_push(_CleanupRoutine, _Argument) \
  32. do { \
  33. __pthread_cleanup_t __CleanupItem; \
  34. __pthread_cleanup_push(&__CleanupItem, (_CleanupRoutine), (_Argument));
  35. //
  36. // The execute parameter is an integer that is zero if the cleanup item should
  37. // just be popped, or non-zero if it should be popped and executed.
  38. //
  39. #define pthread_cleanup_pop(_Execute) \
  40. __pthread_cleanup_pop(&__CleanupItem, (_Execute)); \
  41. } while (0);
  42. //
  43. // ---------------------------------------------------------------- Definitions
  44. //
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. //
  49. // Currently the pthread library is built into the C library, so its API
  50. // decorator should be whatever the C library is.
  51. //
  52. #define PTHREAD_API LIBC_API
  53. //
  54. // Define mutex types.
  55. //
  56. //
  57. // This type of mutex does not detect deadlock.
  58. //
  59. #define PTHREAD_MUTEX_NORMAL 0
  60. //
  61. // This type of mutex provides error checking. A thread attempting to relock
  62. // this mutex without first unlocking fails. A thread attempting to unlock a
  63. // mutex that another thread has locked will also fail.
  64. //
  65. #define PTHREAD_MUTEX_ERRORCHECK 1
  66. //
  67. // This type of mutex allows a thread to succeed a call to acquire the mutex
  68. // after already acquiring the mutex. A count will be maintained of acquire
  69. // counts for the owning thread, and the mutex will only be released to other
  70. // threads when the acquire count drops to zero.
  71. //
  72. #define PTHREAD_MUTEX_RECURSIVE 2
  73. //
  74. // This type is the default type for an initialized mutex.
  75. //
  76. #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
  77. //
  78. // This value indicates an object such as a mutex is private to the process.
  79. //
  80. #define PTHREAD_PROCESS_PRIVATE 0
  81. //
  82. // This value indicates an object such as a mutex is shared across all
  83. // processes.
  84. //
  85. #define PTHREAD_PROCESS_SHARED 1
  86. //
  87. // This (default) value indicates that use of the thread ID as a parameter to
  88. // the thread join or detach routines is permitted.
  89. //
  90. #define PTHREAD_CREATE_JOINABLE 0
  91. //
  92. // This value indicates that the use of the thread ID in the join or detach
  93. // routines is prohibited, as the thread may exit and the ID may be reused at
  94. // any time.
  95. //
  96. #define PTHREAD_CREATE_DETACHED 1
  97. //
  98. // This value indicates that created threads contend with all other threads
  99. // in the system for CPU resources.
  100. //
  101. #define PTHREAD_SCOPE_SYSTEM 0
  102. //
  103. // This value indicates that created threads only contend with other threads
  104. // in their parent process for CPU resources. This is not currently supported.
  105. //
  106. #define PTHREAD_SCOPE_PROCESS 1
  107. //
  108. // This value indicates that thread cancellation is enabled: thread can be
  109. // canceled.
  110. //
  111. #define PTHREAD_CANCEL_ENABLE 0
  112. //
  113. // This value indicates that thread cancellation is currently disabled.
  114. //
  115. #define PTHREAD_CANCEL_DISABLE 1
  116. //
  117. // This value indicates that thread cancellation requests will be deferred
  118. // until the next cancellation point.
  119. //
  120. #define PTHREAD_CANCEL_DEFERRED 0
  121. //
  122. // This value indicates that thread cancellation requests will be processed
  123. // immediately.
  124. //
  125. #define PTHREAD_CANCEL_ASYNCHRONOUS 1
  126. //
  127. // This thread return value indicates that the thread was canceled, rather than
  128. // returning naturally.
  129. //
  130. #define PTHREAD_CANCELED ((void *)-1)
  131. //
  132. // Define the constant initializer for a mutex, which can be assigned as the
  133. // initial value for a global variable mutex.
  134. //
  135. #define PTHREAD_MUTEX_INITIALIZER {{0}}
  136. //
  137. // Define the constant initializer for a recursive mutex.
  138. //
  139. #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
  140. {{0, 0, 0, 0x40}}
  141. //
  142. // Define the constant initializer for an error-checking mutex.
  143. //
  144. #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
  145. {{0, 0, 0, 0x80}}
  146. //
  147. // Define the constant initializer for a condition variable.
  148. //
  149. #define PTHREAD_COND_INITIALIZER {{0}}
  150. //
  151. // Define the constant initializer for a read/write lock.
  152. //
  153. #define PTHREAD_RWLOCK_INITIALIZER {{0}}
  154. //
  155. // Define the constant initializer for a once object.
  156. //
  157. #define PTHREAD_ONCE_INIT 0
  158. //
  159. // Define the value returned to one arbitrary thread after a pthread barrier
  160. // wait is satisfied. This value must be distinct from all error numbers and
  161. // cannot be 0.
  162. //
  163. #define PTHREAD_BARRIER_SERIAL_THREAD -1
  164. //
  165. // ------------------------------------------------------ Data Type Definitions
  166. //
  167. typedef
  168. void
  169. (*__pthread_cleanup_func_t) (
  170. void *Parameter
  171. );
  172. /*++
  173. Routine Description:
  174. This routine prototype represents a function that is called when a thread
  175. is exiting.
  176. Arguments:
  177. Parameter - Supplies a pointer's worth of data.
  178. Return Value:
  179. None.
  180. --*/
  181. /*++
  182. Structure Description:
  183. This structure stores the context for a thread cleanup routine.
  184. Members:
  185. __cleanup_prev - Stores a pointer to the previous item on the stack.
  186. __cleanup_routine - Stores a pointer to the routine to call.
  187. __cleanup_arg - Stores an argument to pass to the cleanup routine.
  188. --*/
  189. typedef struct __pthread_cleanup_t {
  190. struct __pthread_cleanup_t *__cleanup_prev;
  191. __pthread_cleanup_func_t __cleanup_routine;
  192. void *__cleanup_arg;
  193. } __pthread_cleanup_t;
  194. //
  195. // -------------------------------------------------------------------- Globals
  196. //
  197. //
  198. // -------------------------------------------------------- Function Prototypes
  199. //
  200. PTHREAD_API
  201. int
  202. pthread_mutex_init (
  203. pthread_mutex_t *Mutex,
  204. const pthread_mutexattr_t *Attribute
  205. );
  206. /*++
  207. Routine Description:
  208. This routine initializes a mutex.
  209. Arguments:
  210. Mutex - Supplies a pointer to the mutex to initialize.
  211. Attribute - Supplies an optional pointer to the initialized attributes to
  212. set in the mutex.
  213. Return Value:
  214. 0 on success.
  215. Returns an error number on failure.
  216. --*/
  217. PTHREAD_API
  218. int
  219. pthread_mutex_destroy (
  220. pthread_mutex_t *Mutex
  221. );
  222. /*++
  223. Routine Description:
  224. This routine destroys a mutex.
  225. Arguments:
  226. Mutex - Supplies a pointer to the mutex to destroy.
  227. Return Value:
  228. 0 on success.
  229. Returns an error number on failure.
  230. --*/
  231. PTHREAD_API
  232. int
  233. pthread_mutex_lock (
  234. pthread_mutex_t *Mutex
  235. );
  236. /*++
  237. Routine Description:
  238. This routine acquires a mutex.
  239. Arguments:
  240. Mutex - Supplies a pointer to the mutex to acquire.
  241. Return Value:
  242. 0 on success.
  243. Returns an error number on failure.
  244. --*/
  245. PTHREAD_API
  246. int
  247. pthread_mutex_unlock (
  248. pthread_mutex_t *Mutex
  249. );
  250. /*++
  251. Routine Description:
  252. This routine releases a mutex.
  253. Arguments:
  254. Mutex - Supplies a pointer to the mutex to release.
  255. Return Value:
  256. 0 on success.
  257. EPERM if this thread is not the thread that originally acquire the mutex.
  258. --*/
  259. PTHREAD_API
  260. int
  261. pthread_mutex_trylock (
  262. pthread_mutex_t *Mutex
  263. );
  264. /*++
  265. Routine Description:
  266. This routine attempts to acquire the given mutex once.
  267. Arguments:
  268. Mutex - Supplies a pointer to the mutex to attempt to acquire.
  269. Return Value:
  270. 0 on success.
  271. EBUSY if the mutex is already held by another thread and this is an error
  272. checking mutex.
  273. --*/
  274. PTHREAD_API
  275. int
  276. pthread_mutex_timedlock (
  277. pthread_mutex_t *Mutex,
  278. const struct timespec *AbsoluteTimeout
  279. );
  280. /*++
  281. Routine Description:
  282. This routine attempts to acquire a mutex, giving up after a specified
  283. deadline.
  284. Arguments:
  285. Mutex - Supplies a pointer to the mutex to acquire.
  286. AbsoluteTimeout - Supplies the absolute timeout after which the attempt
  287. shall fail and time out.
  288. Return Value:
  289. 0 on success.
  290. Returns an error number on failure.
  291. --*/
  292. PTHREAD_API
  293. int
  294. pthread_mutexattr_init (
  295. pthread_mutexattr_t *Attribute
  296. );
  297. /*++
  298. Routine Description:
  299. This routine initializes a mutex attribute object.
  300. Arguments:
  301. Attribute - Supplies a pointer to the attribute to initialize.
  302. Return Value:
  303. 0 on success.
  304. Returns an error number on failure.
  305. --*/
  306. PTHREAD_API
  307. int
  308. pthread_mutexattr_destroy (
  309. pthread_mutexattr_t *Attribute
  310. );
  311. /*++
  312. Routine Description:
  313. This routine destroys a mutex attribute object.
  314. Arguments:
  315. Attribute - Supplies a pointer to the attribute to destroy.
  316. Return Value:
  317. 0 on success.
  318. Returns an error number on failure.
  319. --*/
  320. PTHREAD_API
  321. int
  322. pthread_mutexattr_gettype (
  323. const pthread_mutexattr_t *Attribute,
  324. int *Type
  325. );
  326. /*++
  327. Routine Description:
  328. This routine returns the mutex type given an attribute that was previously
  329. set.
  330. Arguments:
  331. Attribute - Supplies a pointer to the attribute to get the type from.
  332. Type - Supplies a pointer where the mutex type will be returned on success.
  333. Return Value:
  334. 0 on success.
  335. Returns an error number on failure.
  336. --*/
  337. PTHREAD_API
  338. int
  339. pthread_mutexattr_settype (
  340. pthread_mutexattr_t *Attribute,
  341. int Type
  342. );
  343. /*++
  344. Routine Description:
  345. This routine sets a mutex type in the given mutex attributes object.
  346. Arguments:
  347. Attribute - Supplies a pointer to the attribute to set the type in.
  348. Type - Supplies the mutex type to set. See PTHREAD_MUTEX_* definitions.
  349. Return Value:
  350. 0 on success.
  351. Returns an error number on failure.
  352. --*/
  353. PTHREAD_API
  354. int
  355. pthread_mutexattr_getpshared (
  356. const pthread_mutexattr_t *Attribute,
  357. int *Shared
  358. );
  359. /*++
  360. Routine Description:
  361. This routine returns the mutex sharing type given an attribute that was
  362. previously set.
  363. Arguments:
  364. Attribute - Supplies a pointer to the attribute to get the sharing
  365. information from.
  366. Shared - Supplies a pointer where the sharing type will be returned on
  367. success. See PTHREAD_PROCESS_* definitions.
  368. Return Value:
  369. 0 on success.
  370. Returns an error number on failure.
  371. --*/
  372. PTHREAD_API
  373. int
  374. pthread_mutexattr_setpshared (
  375. pthread_mutexattr_t *Attribute,
  376. int Shared
  377. );
  378. /*++
  379. Routine Description:
  380. This routine sets a mutex sharing type in the given mutex attributes object.
  381. Arguments:
  382. Attribute - Supplies a pointer to the attribute to set the type in.
  383. Shared - Supplies the mutex type to set. See PTHREAD_PROCESS_* definitions.
  384. Return Value:
  385. 0 on success.
  386. Returns an error number on failure.
  387. --*/
  388. PTHREAD_API
  389. int
  390. pthread_cond_init (
  391. pthread_cond_t *Condition,
  392. pthread_condattr_t *Attribute
  393. );
  394. /*++
  395. Routine Description:
  396. This routine initializes a condition variable structure.
  397. Arguments:
  398. Condition - Supplies a pointer to the condition variable structure.
  399. Attribute - Supplies an optional pointer to the condition variable
  400. attributes.
  401. Return Value:
  402. 0 on success.
  403. Returns an error number on failure.
  404. --*/
  405. PTHREAD_API
  406. int
  407. pthread_cond_destroy (
  408. pthread_cond_t *Condition
  409. );
  410. /*++
  411. Routine Description:
  412. This routine destroys a condition variable structure.
  413. Arguments:
  414. Condition - Supplies a pointer to the condition variable structure.
  415. Return Value:
  416. 0 on success.
  417. Returns an error number on failure.
  418. --*/
  419. PTHREAD_API
  420. int
  421. pthread_cond_broadcast (
  422. pthread_cond_t *Condition
  423. );
  424. /*++
  425. Routine Description:
  426. This routine wakes up all threads waiting on the given condition variable.
  427. This is useful when there are multiple different predicates behind the
  428. same condition variable.
  429. Arguments:
  430. Condition - Supplies a pointer to the condition variable to wake.
  431. Return Value:
  432. 0 on success.
  433. Returns an error number on failure.
  434. --*/
  435. PTHREAD_API
  436. int
  437. pthread_cond_signal (
  438. pthread_cond_t *Condition
  439. );
  440. /*++
  441. Routine Description:
  442. This routine wakes up at least one thread waiting on the given condition
  443. variable. This is preferred over the broadcast function if all waiting
  444. threads are checking the same mutex, as it prevents the thundering herd
  445. associated with broadcast (all woken threads race to acquire the same
  446. mutex). Multiple threads may exit a condition wait, so it is critical to
  447. check the predicate on return.
  448. Arguments:
  449. Condition - Supplies a pointer to the condition variable to wake.
  450. Return Value:
  451. 0 on success.
  452. Returns an error number on failure.
  453. --*/
  454. PTHREAD_API
  455. int
  456. pthread_cond_wait (
  457. pthread_cond_t *Condition,
  458. pthread_mutex_t *Mutex
  459. );
  460. /*++
  461. Routine Description:
  462. This routine unlocks the given mutex, blocks until the given condition
  463. variable is signaled, and then reacquires the mutex.
  464. Arguments:
  465. Condition - Supplies a pointer to the condition variable to wait on.
  466. Mutex - Supplies a pointer to the mutex to operate on.
  467. Return Value:
  468. 0 on success.
  469. Returns an error number on failure.
  470. --*/
  471. PTHREAD_API
  472. int
  473. pthread_cond_timedwait (
  474. pthread_cond_t *Condition,
  475. pthread_mutex_t *Mutex,
  476. const struct timespec *AbsoluteTimeout
  477. );
  478. /*++
  479. Routine Description:
  480. This routine unlocks the given mutex, blocks until the given condition
  481. variable is signaled, and then reacquires the mutex. This wait can time
  482. out after the specified deadline.
  483. Arguments:
  484. Condition - Supplies a pointer to the condition variable to wait on.
  485. Mutex - Supplies a pointer to the mutex to operate on.
  486. AbsoluteTimeout - Supplies a pointer to an absolute time after which the
  487. wait should return anyway.
  488. Return Value:
  489. 0 on success.
  490. ETIMEDOUT if the operation timed out. The predicate may have become true
  491. naturally anyway, so the caller should always check their predicates.
  492. Returns an error number on failure.
  493. --*/
  494. PTHREAD_API
  495. int
  496. pthread_condattr_init (
  497. pthread_condattr_t *Attribute
  498. );
  499. /*++
  500. Routine Description:
  501. This routine initializes a condition variable attribute structure.
  502. Arguments:
  503. Attribute - Supplies a pointer to the condition variable attribute
  504. structure.
  505. Return Value:
  506. 0 on success.
  507. Returns an error number on failure.
  508. --*/
  509. PTHREAD_API
  510. int
  511. pthread_condattr_destroy (
  512. pthread_condattr_t *Attribute
  513. );
  514. /*++
  515. Routine Description:
  516. This routine destroys a condition variable attribute structure.
  517. Arguments:
  518. Attribute - Supplies a pointer to the condition variable attribute
  519. structure.
  520. Return Value:
  521. 0 on success.
  522. Returns an error number on failure.
  523. --*/
  524. PTHREAD_API
  525. int
  526. pthread_condattr_getpshared (
  527. const pthread_condattr_t *Attribute,
  528. int *Shared
  529. );
  530. /*++
  531. Routine Description:
  532. This routine determines the shared attribute in a condition variable.
  533. Arguments:
  534. Attribute - Supplies a pointer to the condition variable attribute
  535. structure.
  536. Shared - Supplies a pointer where the shared attribute will be returned,
  537. indicating whether the condition variable is visible across processes.
  538. See PTHREAD_PROCESS_* definitions.
  539. Return Value:
  540. 0 on success.
  541. Returns an error number on failure.
  542. --*/
  543. PTHREAD_API
  544. int
  545. pthread_condattr_setpshared (
  546. pthread_condattr_t *Attribute,
  547. int Shared
  548. );
  549. /*++
  550. Routine Description:
  551. This routine sets the shared attribute in a condition variable.
  552. Arguments:
  553. Attribute - Supplies a pointer to the condition variable attribute
  554. structure.
  555. Shared - Supplies the value indicating whether this condition variable
  556. should be visible across processes. See PTHREAD_PROCESS_* definitions.
  557. Return Value:
  558. 0 on success.
  559. Returns an error number on failure.
  560. --*/
  561. PTHREAD_API
  562. int
  563. pthread_condattr_getclock (
  564. const pthread_condattr_t *Attribute,
  565. int *Clock
  566. );
  567. /*++
  568. Routine Description:
  569. This routine determines which clock the condition variable uses for timed
  570. waits.
  571. Arguments:
  572. Attribute - Supplies a pointer to the condition variable attribute
  573. structure.
  574. Clock - Supplies a pointer where the clock source for timed waits on the
  575. condition variable with this attribute will be returned. See CLOCK_*
  576. definitions.
  577. Return Value:
  578. 0 on success.
  579. Returns an error number on failure.
  580. --*/
  581. PTHREAD_API
  582. int
  583. pthread_condattr_setclock (
  584. pthread_condattr_t *Attribute,
  585. int Clock
  586. );
  587. /*++
  588. Routine Description:
  589. This routine sets the clock used for condition variable timed waits.
  590. Arguments:
  591. Attribute - Supplies a pointer to the condition variable attribute
  592. structure.
  593. Clock - Supplies the clock to use when performing timed waits.
  594. Return Value:
  595. 0 on success.
  596. Returns an error number on failure.
  597. --*/
  598. PTHREAD_API
  599. int
  600. pthread_rwlock_init (
  601. pthread_rwlock_t *Lock,
  602. pthread_rwlockattr_t *Attribute
  603. );
  604. /*++
  605. Routine Description:
  606. This routine initializes a read/write lock.
  607. Arguments:
  608. Lock - Supplies a pointer to the read/write lock.
  609. Attribute - Supplies an optional pointer to an initialized attribute
  610. structure governing the internal behavior of the lock.
  611. Return Value:
  612. 0 on success.
  613. Returns an error number on failure.
  614. --*/
  615. PTHREAD_API
  616. int
  617. pthread_rwlock_destroy (
  618. pthread_rwlock_t *Lock
  619. );
  620. /*++
  621. Routine Description:
  622. This routine destroys a read/write lock.
  623. Arguments:
  624. Lock - Supplies a pointer to the read/write lock.
  625. Return Value:
  626. 0 on success.
  627. Returns an error number on failure.
  628. --*/
  629. PTHREAD_API
  630. int
  631. pthread_rwlock_rdlock (
  632. pthread_rwlock_t *Lock
  633. );
  634. /*++
  635. Routine Description:
  636. This routine acquires the read/write lock for read access. Multiple readers
  637. can acquire the lock simultaneously, but any writes that try to acquire
  638. the lock while it's held for read will block. Readers that try to
  639. acquire the lock while it's held for write will also block.
  640. Arguments:
  641. Lock - Supplies a pointer to the read/write lock.
  642. Return Value:
  643. 0 on success.
  644. Returns an error number on failure.
  645. --*/
  646. PTHREAD_API
  647. int
  648. pthread_rwlock_timedrdlock (
  649. pthread_rwlock_t *Lock,
  650. const struct timespec *AbsoluteTimeout
  651. );
  652. /*++
  653. Routine Description:
  654. This routine acquires the read/write lock for read access just like the
  655. read lock function, except that this function will return after the
  656. specified deadline if the lock could not be acquired.
  657. Arguments:
  658. Lock - Supplies a pointer to the read/write lock.
  659. AbsoluteTimeout - Supplies a pointer to the absolute deadline after which
  660. this function should give up and return failure.
  661. Return Value:
  662. 0 on success.
  663. ETIMEDOUT if the operation timed out. This thread will not own the lock.
  664. Returns an error number on failure.
  665. --*/
  666. PTHREAD_API
  667. int
  668. pthread_rwlock_tryrdlock (
  669. pthread_rwlock_t *Lock
  670. );
  671. /*++
  672. Routine Description:
  673. This routine performs a single attempt at acquiring the lock for read
  674. access.
  675. Arguments:
  676. Lock - Supplies a pointer to the read/write lock.
  677. Return Value:
  678. 0 on success.
  679. Returns an error number on failure.
  680. --*/
  681. PTHREAD_API
  682. int
  683. pthread_rwlock_wrlock (
  684. pthread_rwlock_t *Lock
  685. );
  686. /*++
  687. Routine Description:
  688. This routine acquires the read/write lock for write access. The lock can
  689. only be acquired for write access if there are no readers and no other
  690. writers.
  691. Arguments:
  692. Lock - Supplies a pointer to the read/write lock.
  693. Return Value:
  694. 0 on success.
  695. Returns an error number on failure.
  696. --*/
  697. PTHREAD_API
  698. int
  699. pthread_rwlock_timedwrlock (
  700. pthread_rwlock_t *Lock,
  701. const struct timespec *AbsoluteTimeout
  702. );
  703. /*++
  704. Routine Description:
  705. This routine acquires the read/write lock for write access just like the
  706. write lock function, except that this function will return after the
  707. specified deadline if the lock could not be acquired.
  708. Arguments:
  709. Lock - Supplies a pointer to the read/write lock.
  710. AbsoluteTimeout - Supplies a pointer to the absolute deadline after which
  711. this function should give up and return failure.
  712. Return Value:
  713. 0 on success.
  714. ETIMEDOUT if the operation timed out. This thread will not own the lock.
  715. Returns an error number on failure.
  716. --*/
  717. PTHREAD_API
  718. int
  719. pthread_rwlock_trywrlock (
  720. pthread_rwlock_t *Lock
  721. );
  722. /*++
  723. Routine Description:
  724. This routine performs a single attempt at acquiring the lock for write
  725. access.
  726. Arguments:
  727. Lock - Supplies a pointer to the read/write lock.
  728. Return Value:
  729. 0 on success.
  730. Returns an error number on failure.
  731. --*/
  732. PTHREAD_API
  733. int
  734. pthread_rwlock_unlock (
  735. pthread_rwlock_t *Lock
  736. );
  737. /*++
  738. Routine Description:
  739. This routine unlocks a read/write lock that's been acquired by this thread
  740. for either read or write.
  741. Arguments:
  742. Lock - Supplies a pointer to the read/write lock.
  743. Return Value:
  744. 0 on success.
  745. Returns an error number on failure.
  746. --*/
  747. PTHREAD_API
  748. int
  749. pthread_rwlockattr_init (
  750. pthread_rwlockattr_t *Attribute
  751. );
  752. /*++
  753. Routine Description:
  754. This routine initializes a read/write lock attribute structure.
  755. Arguments:
  756. Attribute - Supplies a pointer to the read/write lock attribute.
  757. Return Value:
  758. 0 on success.
  759. Returns an error number on failure.
  760. --*/
  761. PTHREAD_API
  762. int
  763. pthread_rwlockattr_destroy (
  764. pthread_rwlockattr_t *Attribute
  765. );
  766. /*++
  767. Routine Description:
  768. This routine destroys a read/write lock attribute structure.
  769. Arguments:
  770. Attribute - Supplies a pointer to the read/write lock attribute.
  771. Return Value:
  772. 0 on success.
  773. Returns an error number on failure.
  774. --*/
  775. PTHREAD_API
  776. int
  777. pthread_rwlockattr_getpshared (
  778. const pthread_rwlockattr_t *Attribute,
  779. int *Shared
  780. );
  781. /*++
  782. Routine Description:
  783. This routine reads the shared attribute from a read/write lock attributes
  784. structure.
  785. Arguments:
  786. Attribute - Supplies a pointer to the read/write lock attribute.
  787. Shared - Supplies a pointer where the shared attribute of the lock will be
  788. returned on success. See PTHREAD_PROCESS_* definitions.
  789. Return Value:
  790. 0 on success.
  791. Returns an error number on failure.
  792. --*/
  793. PTHREAD_API
  794. int
  795. pthread_rwlockattr_setpshared (
  796. pthread_rwlockattr_t *Attribute,
  797. int Shared
  798. );
  799. /*++
  800. Routine Description:
  801. This routine sets the shared attribute in a read/write lock attributes
  802. structure.
  803. Arguments:
  804. Attribute - Supplies a pointer to the read/write lock attribute.
  805. Shared - Supplies the new shared value to set. See PTHREAD_PROCESS_*
  806. definitions.
  807. Return Value:
  808. 0 on success.
  809. Returns an error number on failure.
  810. --*/
  811. PTHREAD_API
  812. pthread_t
  813. pthread_self (
  814. void
  815. );
  816. /*++
  817. Routine Description:
  818. This routine returns the thread ID for the current thread.
  819. Arguments:
  820. None.
  821. Return Value:
  822. None.
  823. --*/
  824. PTHREAD_API
  825. int
  826. pthread_create (
  827. pthread_t *CreatedThread,
  828. const pthread_attr_t *Attribute,
  829. void *(*StartRoutine)(void *),
  830. void *Argument
  831. );
  832. /*++
  833. Routine Description:
  834. This routine creates and starts a new thread. The signal mask of the new
  835. thread is inherited from the current thread. The set of pending signals in
  836. the new thread will be initially empty.
  837. Arguments:
  838. CreatedThread - Supplies a pointer where the identifier of the new thread
  839. will be returned on success.
  840. Attribute - Supplies an optional pointer to the attributes of the thread.
  841. StartRoutine - Supplies a pointer to the routine to call on the new thread.
  842. Argument - Supplies the argument to pass to the start routine.
  843. Return Value:
  844. 0 on success.
  845. Returns an error number on failure.
  846. --*/
  847. PTHREAD_API
  848. int
  849. pthread_detach (
  850. pthread_t ThreadId
  851. );
  852. /*++
  853. Routine Description:
  854. This routine marks the given thread as detached, which means that when it
  855. exits, its resources are automatically released without needing another
  856. thread to call join on it. It is illegal to call join on a detached thread,
  857. as the thread ID may be already released and reused.
  858. Arguments:
  859. ThreadId - Supplies the thread ID to detach.
  860. Return Value:
  861. 0 on success.
  862. Returns an error number on failure.
  863. --*/
  864. PTHREAD_API
  865. int
  866. pthread_join (
  867. pthread_t ThreadId,
  868. void **ReturnValue
  869. );
  870. /*++
  871. Routine Description:
  872. This routine waits for the given thread to exit and collects its return
  873. value. Detached threads cannot be joined.
  874. Arguments:
  875. ThreadId - Supplies the identifier of the thread to join with.
  876. ReturnValue - Supplies a pointer where the thread return value will be
  877. returned on success.
  878. Return Value:
  879. 0 on success.
  880. Returns an error number on failure.
  881. --*/
  882. PTHREAD_API
  883. __NO_RETURN
  884. void
  885. pthread_exit (
  886. void *ReturnValue
  887. );
  888. /*++
  889. Routine Description:
  890. This routine exits the current thread. If this is a detached thread, then
  891. all thread resources are destroyed immediately. If this is a joinable
  892. thread, then some state is kept around until another thread calls join to
  893. collect the return value.
  894. Arguments:
  895. ReturnValue - Supplies an optional return value to give to anyone that
  896. calls join.
  897. Return Value:
  898. None. This routine does not return.
  899. --*/
  900. PTHREAD_API
  901. int
  902. pthread_equal (
  903. pthread_t FirstThread,
  904. pthread_t SecondThread
  905. );
  906. /*++
  907. Routine Description:
  908. This routine compares two thread identifiers.
  909. Arguments:
  910. FirstThread - Supplies the first thread identifier to compare.
  911. SecondThread - Supplies the second thread identifier to compare.
  912. Return Value:
  913. Returns non-zero if the two thread IDs are equal.
  914. 0 if the thread IDs are not equal.
  915. --*/
  916. PTHREAD_API
  917. int
  918. pthread_kill (
  919. pthread_t ThreadId,
  920. int Signal
  921. );
  922. /*++
  923. Routine Description:
  924. This routine sends a signal to the given thread.
  925. Arguments:
  926. ThreadId - Supplies the identifier of the thread to send the signal to.
  927. Signal - Supplies the signal number to send. Supply 0 to test if a signal
  928. can be sent, but not actually send any signal.
  929. Return Value:
  930. 0 on success.
  931. Returns an error number on failure.
  932. --*/
  933. PTHREAD_API
  934. int
  935. pthread_sigqueue (
  936. pthread_t ThreadId,
  937. int Signal,
  938. const union sigval Value
  939. );
  940. /*++
  941. Routine Description:
  942. This routine queues a signal with data the given thread.
  943. Arguments:
  944. ThreadId - Supplies the identifier of the thread to send the signal to.
  945. Signal - Supplies the signal number to send. Supply 0 to test if a signal
  946. can be sent, but not actually send any signal.
  947. Value - Supplies the signal value to send.
  948. Return Value:
  949. 0 on success.
  950. Returns an error number on failure.
  951. --*/
  952. PTHREAD_API
  953. int
  954. pthread_cancel (
  955. pthread_t ThreadId
  956. );
  957. /*++
  958. Routine Description:
  959. This routine attempts to cancel (terminate) the thread with the given
  960. thread ID. This may not terminate the thread immediately if it has disabled
  961. or deferred cancellation.
  962. Arguments:
  963. ThreadId - Supplies the identifier of the thread to cancel.
  964. Return Value:
  965. 0 on success.
  966. ESRCH if a thread with the given ID could not be found.
  967. --*/
  968. PTHREAD_API
  969. int
  970. pthread_setcancelstate (
  971. int State,
  972. int *OldState
  973. );
  974. /*++
  975. Routine Description:
  976. This routine atomically sets the thread cancellation state for the current
  977. thread and returns the old state. By default, new threads are created with
  978. cancellation enabled.
  979. Arguments:
  980. State - Supplies the new state to set. Valid values are
  981. PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_DISABLE.
  982. OldState - Supplies the previously set cancellation state.
  983. Return Value:
  984. 0 on success.
  985. EINVAL if an invalid new state was supplied.
  986. --*/
  987. PTHREAD_API
  988. int
  989. pthread_setcanceltype (
  990. int Type,
  991. int *OldType
  992. );
  993. /*++
  994. Routine Description:
  995. This routine atomically sets the thread cancellation type for the current
  996. thread and returns the old type. By default, new threads are created with
  997. deferred cancellation.
  998. Arguments:
  999. Type - Supplies the new type to set. Valid values are
  1000. PTHREAD_CANCEL_DEFERRED and PTHREAD_CANCEL_ASYNCHRONOUS.
  1001. OldType - Supplies the previously set cancellation type.
  1002. Return Value:
  1003. 0 on success.
  1004. EINVAL if an invalid new type was supplied.
  1005. --*/
  1006. PTHREAD_API
  1007. void
  1008. pthread_testcancel (
  1009. void
  1010. );
  1011. /*++
  1012. Routine Description:
  1013. This routine creates a cancellation point in the calling thread. If
  1014. cancellation is currently disabled, this does nothing.
  1015. Arguments:
  1016. None.
  1017. Return Value:
  1018. None.
  1019. --*/
  1020. PTHREAD_API
  1021. int
  1022. pthread_once (
  1023. pthread_once_t *Once,
  1024. void (*Routine)(void)
  1025. );
  1026. /*++
  1027. Routine Description:
  1028. This routine can be called by any thread in the process. The first call
  1029. to this routine will execute the given method. All others calls will do
  1030. nothing. On return from this routine, the routine will have completed
  1031. executing. If the routine is a cancellation point and is canceled, then
  1032. the effect will be as if the routine was never called.
  1033. Arguments:
  1034. Once - Supplies a pointer to the initialized once object. Initialize it
  1035. with the value PTHREAD_ONCE_INIT.
  1036. Routine - Supplies a pointer to the routine to be called exactly once.
  1037. Return Value:
  1038. 0 on success.
  1039. EINVAL if the given once object or routine is invalid.
  1040. --*/
  1041. PTHREAD_API
  1042. pid_t
  1043. pthread_gettid_np (
  1044. pthread_t ThreadId
  1045. );
  1046. /*++
  1047. Routine Description:
  1048. This routine returns the kernel thread ID for the given POSIX thread ID.
  1049. Arguments:
  1050. ThreadId - Supplies the POSIX thread ID.
  1051. Return Value:
  1052. Returns the kernel thread ID.
  1053. --*/
  1054. PTHREAD_API
  1055. pid_t
  1056. pthread_getthreadid_np (
  1057. void
  1058. );
  1059. /*++
  1060. Routine Description:
  1061. This routine returns the kernel thread ID for the current thread.
  1062. Arguments:
  1063. None.
  1064. Return Value:
  1065. Returns the kernel thread ID.
  1066. --*/
  1067. PTHREAD_API
  1068. int
  1069. pthread_getattr_np (
  1070. pthread_t ThreadId,
  1071. pthread_attr_t *Attribute
  1072. );
  1073. /*++
  1074. Routine Description:
  1075. This routine returns the current attributes for a given thread.
  1076. Arguments:
  1077. ThreadId - Supplies the thread to get attributes for.
  1078. Attribute - Supplies a pointer where the attributes will be returned. The
  1079. detach state, stack size, stack base, and guard size may be different
  1080. from when the thread was created to reflect their actual values.
  1081. Return Value:
  1082. 0 on success.
  1083. Returns an error number on failure.
  1084. --*/
  1085. PTHREAD_API
  1086. void
  1087. __pthread_cleanup_push (
  1088. __pthread_cleanup_t *CleanupItem,
  1089. __pthread_cleanup_func_t CleanupRoutine,
  1090. void *Argument
  1091. );
  1092. /*++
  1093. Routine Description:
  1094. This routine pushes a new element onto the cleanup stack for the current
  1095. thread.
  1096. Arguments:
  1097. CleanupItem - Supplies a pointer to the cleanup item context. This routine
  1098. uses this buffer, so it cannot be freed until the cleanup item is
  1099. popped.
  1100. CleanupRoutine - Supplies a pointer to the routine to call if the thread
  1101. exits.
  1102. Argument - Supplies a pointer to pass to the cleanup routine.
  1103. Return Value:
  1104. None.
  1105. --*/
  1106. PTHREAD_API
  1107. void
  1108. __pthread_cleanup_pop (
  1109. __pthread_cleanup_t *CleanupItem,
  1110. int Execute
  1111. );
  1112. /*++
  1113. Routine Description:
  1114. This routine potentially pops an element from the cleanup stack.
  1115. Arguments:
  1116. CleanupItem - Supplies a pointer to the cleanup item to pop.
  1117. Execute - Supplies an integer that is non-zero if the cleanup routine
  1118. should be run, or zero if it should just be popped.
  1119. Return Value:
  1120. None.
  1121. --*/
  1122. PTHREAD_API
  1123. int
  1124. pthread_attr_init (
  1125. pthread_attr_t *Attribute
  1126. );
  1127. /*++
  1128. Routine Description:
  1129. This routine initializes a thread attribute structure.
  1130. Arguments:
  1131. Attribute - Supplies a pointer to the attribute to initialize.
  1132. Return Value:
  1133. 0 on success.
  1134. Returns an error number on failure.
  1135. --*/
  1136. PTHREAD_API
  1137. int
  1138. pthread_attr_destroy (
  1139. pthread_attr_t *Attribute
  1140. );
  1141. /*++
  1142. Routine Description:
  1143. This routine destroys a thread attribute structure.
  1144. Arguments:
  1145. Attribute - Supplies a pointer to the attribute to destroy.
  1146. Return Value:
  1147. 0 on success.
  1148. Returns an error number on failure.
  1149. --*/
  1150. PTHREAD_API
  1151. int
  1152. pthread_attr_getdetachstate (
  1153. const pthread_attr_t *Attribute,
  1154. int *State
  1155. );
  1156. /*++
  1157. Routine Description:
  1158. This routine returns the thread detach state for the given attribute.
  1159. Arguments:
  1160. Attribute - Supplies a pointer to the attribute.
  1161. State - Supplies a pointer where the state will be returned on success. See
  1162. PTHREAD_CREATE_* definitions.
  1163. Return Value:
  1164. 0 on success.
  1165. Returns an error number on failure.
  1166. --*/
  1167. PTHREAD_API
  1168. int
  1169. pthread_attr_setdetachstate (
  1170. pthread_attr_t *Attribute,
  1171. int State
  1172. );
  1173. /*++
  1174. Routine Description:
  1175. This routine sets the thread detach state for the given attribute.
  1176. Arguments:
  1177. Attribute - Supplies a pointer to the attribute.
  1178. State - Supplies the new detach state to set. See PTHREAD_CREATE_*
  1179. definitions.
  1180. Return Value:
  1181. 0 on success.
  1182. Returns an error number on failure.
  1183. --*/
  1184. PTHREAD_API
  1185. int
  1186. pthread_attr_getschedpolicy (
  1187. const pthread_attr_t *Attribute,
  1188. int *Policy
  1189. );
  1190. /*++
  1191. Routine Description:
  1192. This routine returns the thread scheduling policy for the given attribute.
  1193. Arguments:
  1194. Attribute - Supplies a pointer to the attribute.
  1195. Policy - Supplies a pointer where the policy will be returned on success.
  1196. Return Value:
  1197. 0 on success.
  1198. Returns an error number on failure.
  1199. --*/
  1200. PTHREAD_API
  1201. int
  1202. pthread_attr_setschedpolicy (
  1203. const pthread_attr_t *Attribute,
  1204. int Policy
  1205. );
  1206. /*++
  1207. Routine Description:
  1208. This routine sets the thread scheduling policy for the given attribute.
  1209. Arguments:
  1210. Attribute - Supplies a pointer to the attribute.
  1211. Policy - Supplies the new policy to set.
  1212. Return Value:
  1213. 0 on success.
  1214. Returns an error number on failure.
  1215. --*/
  1216. PTHREAD_API
  1217. int
  1218. pthread_attr_getschedparam (
  1219. const pthread_attr_t *Attribute,
  1220. int *Parameter
  1221. );
  1222. /*++
  1223. Routine Description:
  1224. This routine returns the thread scheduling parameter for the given
  1225. attribute.
  1226. Arguments:
  1227. Attribute - Supplies a pointer to the attribute.
  1228. Parameter - Supplies a pointer where the scheduling parameter will be
  1229. returned on success.
  1230. Return Value:
  1231. 0 on success.
  1232. Returns an error number on failure.
  1233. --*/
  1234. PTHREAD_API
  1235. int
  1236. pthread_attr_setschedparam (
  1237. pthread_attr_t *Attribute,
  1238. int Parameter
  1239. );
  1240. /*++
  1241. Routine Description:
  1242. This routine sets the thread scheduling parameter for the given attribute.
  1243. Arguments:
  1244. Attribute - Supplies a pointer to the attribute.
  1245. Parameter - Supplies the new parameter to set.
  1246. Return Value:
  1247. 0 on success.
  1248. Returns an error number on failure.
  1249. --*/
  1250. PTHREAD_API
  1251. int
  1252. pthread_attr_getscope (
  1253. const pthread_attr_t *Attribute,
  1254. int *Scope
  1255. );
  1256. /*++
  1257. Routine Description:
  1258. This routine returns the thread scheduling scope for the given attribute.
  1259. Arguments:
  1260. Attribute - Supplies a pointer to the attribute.
  1261. Scope - Supplies a pointer where the thread scope will be returned on
  1262. success.
  1263. Return Value:
  1264. 0 on success.
  1265. Returns an error number on failure.
  1266. --*/
  1267. PTHREAD_API
  1268. int
  1269. pthread_attr_setscope (
  1270. pthread_attr_t *Attribute,
  1271. int Scope
  1272. );
  1273. /*++
  1274. Routine Description:
  1275. This routine sets the thread scheduling scope for the given attribute.
  1276. Arguments:
  1277. Attribute - Supplies a pointer to the attribute.
  1278. Scope - Supplies the new scope to set.
  1279. Return Value:
  1280. 0 on success.
  1281. Returns an error number on failure.
  1282. --*/
  1283. PTHREAD_API
  1284. int
  1285. pthread_attr_getstacksize (
  1286. const pthread_attr_t *Attribute,
  1287. size_t *StackSize
  1288. );
  1289. /*++
  1290. Routine Description:
  1291. This routine returns the thread stack size for the given attribute.
  1292. Arguments:
  1293. Attribute - Supplies a pointer to the attribute.
  1294. StackSize - Supplies a pointer where the stack size will be returned on
  1295. success.
  1296. Return Value:
  1297. 0 on success.
  1298. Returns an error number on failure.
  1299. --*/
  1300. PTHREAD_API
  1301. int
  1302. pthread_attr_setstacksize (
  1303. pthread_attr_t *Attribute,
  1304. size_t StackSize
  1305. );
  1306. /*++
  1307. Routine Description:
  1308. This routine sets the thread stack size for the given attribute.
  1309. Arguments:
  1310. Attribute - Supplies a pointer to the attribute.
  1311. StackSize - Supplies the desired stack size. This should not be less than
  1312. PTHREAD_STACK_MIN and should be a multiple of the page size.
  1313. Return Value:
  1314. 0 on success.
  1315. Returns an error number on failure.
  1316. --*/
  1317. PTHREAD_API
  1318. int
  1319. pthread_attr_getstack (
  1320. const pthread_attr_t *Attribute,
  1321. void **StackBase,
  1322. size_t *StackSize
  1323. );
  1324. /*++
  1325. Routine Description:
  1326. This routine returns the thread stack information for the given attribute.
  1327. Arguments:
  1328. Attribute - Supplies a pointer to the attribute.
  1329. StackBase - Supplies a pointer where the stack base will be returned on
  1330. success.
  1331. StackSize - Supplies a pointer where the stack size will be returned on
  1332. success.
  1333. Return Value:
  1334. 0 on success.
  1335. Returns an error number on failure.
  1336. --*/
  1337. PTHREAD_API
  1338. int
  1339. pthread_attr_setstack (
  1340. pthread_attr_t *Attribute,
  1341. void *StackBase,
  1342. size_t StackSize
  1343. );
  1344. /*++
  1345. Routine Description:
  1346. This routine sets the thread stack information for the given attribute.
  1347. Arguments:
  1348. Attribute - Supplies a pointer to the attribute.
  1349. StackBase - Supplies the stack base pointer.
  1350. StackSize - Supplies the desired stack size. This should not be less than
  1351. PTHREAD_STACK_MIN.
  1352. Return Value:
  1353. 0 on success.
  1354. Returns an error number on failure.
  1355. --*/
  1356. PTHREAD_API
  1357. int
  1358. pthread_attr_getguardsize (
  1359. const pthread_attr_t *Attribute,
  1360. size_t *GuardSize
  1361. );
  1362. /*++
  1363. Routine Description:
  1364. This routine returns the thread stack guard region size for the given
  1365. attribute.
  1366. Arguments:
  1367. Attribute - Supplies a pointer to the attribute.
  1368. GuardSize - Supplies a pointer where the stack guard region size will be
  1369. returned on success.
  1370. Return Value:
  1371. 0 on success.
  1372. Returns an error number on failure.
  1373. --*/
  1374. PTHREAD_API
  1375. int
  1376. pthread_attr_setguardsize (
  1377. pthread_attr_t *Attribute,
  1378. size_t GuardSize
  1379. );
  1380. /*++
  1381. Routine Description:
  1382. This routine sets the thread stack guard region size for the given
  1383. attribute.
  1384. Arguments:
  1385. Attribute - Supplies a pointer to the attribute.
  1386. GuardSize - Supplies the desired stack guard region size.
  1387. Return Value:
  1388. 0 on success.
  1389. Returns an error number on failure.
  1390. --*/
  1391. PTHREAD_API
  1392. int
  1393. pthread_key_create (
  1394. pthread_key_t *Key,
  1395. void (*KeyDestructorRoutine)(void *)
  1396. );
  1397. /*++
  1398. Routine Description:
  1399. This routine attempts to create and reserve a new thread key.
  1400. Arguments:
  1401. Key - Supplies a pointer where the key information will be returned.
  1402. KeyDestructorRoutine - Supplies an optional pointer to a routine to call
  1403. when the key is destroyed on a particular thread. This routine will
  1404. be called with a pointer to the thread-specific value for the key.
  1405. Return Value:
  1406. 0 on success.
  1407. EAGAIN if the system lacked the resources to create a new key slot, or
  1408. there are too many keys.
  1409. ENOMEM if insufficient memory exists to create the key.
  1410. --*/
  1411. PTHREAD_API
  1412. int
  1413. pthread_key_delete (
  1414. pthread_key_t Key
  1415. );
  1416. /*++
  1417. Routine Description:
  1418. This routine releases a thread key. It is the responsibility of the
  1419. application to release any thread-specific data associated with the old key.
  1420. No destructors are called from this function.
  1421. Arguments:
  1422. Key - Supplies a pointer to the key to delete.
  1423. Return Value:
  1424. 0 on success.
  1425. EINVAL if the key is invalid.
  1426. --*/
  1427. PTHREAD_API
  1428. void *
  1429. pthread_getspecific (
  1430. pthread_key_t Key
  1431. );
  1432. /*++
  1433. Routine Description:
  1434. This routine returns the thread-specific value for the given key.
  1435. Arguments:
  1436. Key - Supplies a pointer to the key whose value should be returned.
  1437. Return Value:
  1438. Returns the last value set for the current thread and key combination, or
  1439. NULL if no value has been set or the key is not valid.
  1440. --*/
  1441. PTHREAD_API
  1442. int
  1443. pthread_setspecific (
  1444. pthread_key_t Key,
  1445. const void *Value
  1446. );
  1447. /*++
  1448. Routine Description:
  1449. This routine sets the thread-specific value for the given key and current
  1450. thread.
  1451. Arguments:
  1452. Key - Supplies the key whose value should be set.
  1453. Value - Supplies the value to set.
  1454. Return Value:
  1455. 0 on success.
  1456. EINVAL if the key passed was invalid.
  1457. --*/
  1458. __HIDDEN
  1459. int
  1460. pthread_atfork (
  1461. void (*PrepareRoutine)(void),
  1462. void (*ParentRoutine)(void),
  1463. void (*ChildRoutine)(void)
  1464. );
  1465. /*++
  1466. Routine Description:
  1467. This routine is called to register an at-fork handler, whose callbacks are
  1468. called immediately before and after any fork operation.
  1469. Arguments:
  1470. PrepareRoutine - Supplies an optional pointer to a routine to be called
  1471. immediately before a fork operation.
  1472. ParentRoutine - Supplies an optional pointer to a routine to be called
  1473. after a fork in the parent process.
  1474. ChildRoutine - Supplies an optional pointer to a routine to be called
  1475. after a fork in the child process.
  1476. Return Value:
  1477. 0 on success.
  1478. Returns an error number on failure.
  1479. --*/
  1480. PTHREAD_API
  1481. int
  1482. __register_atfork (
  1483. void (*PrepareRoutine)(void),
  1484. void (*ParentRoutine)(void),
  1485. void (*ChildRoutine)(void),
  1486. void *DynamicObjectHandle
  1487. );
  1488. /*++
  1489. Routine Description:
  1490. This routine is called to register an at-fork handler, remembering the
  1491. dynamic object it was registered from.
  1492. Arguments:
  1493. PrepareRoutine - Supplies an optional pointer to a routine to be called
  1494. immediately before a fork operation.
  1495. ParentRoutine - Supplies an optional pointer to a routine to be called
  1496. after a fork in the parent process.
  1497. ChildRoutine - Supplies an optional pointer to ao routine to be called
  1498. after a fork in the child process.
  1499. DynamicObjectHandle - Supplies an identifier unique to the dynamic object
  1500. registering the handlers. This can be used to unregister the handles if
  1501. the dynamic object is unloaded.
  1502. Return Value:
  1503. 0 on success.
  1504. Returns an error number on failure.
  1505. --*/
  1506. PTHREAD_API
  1507. int
  1508. pthread_barrier_init (
  1509. pthread_barrier_t *Barrier,
  1510. const pthread_barrierattr_t *Attribute,
  1511. unsigned Count
  1512. );
  1513. /*++
  1514. Routine Description:
  1515. This routine initializes the given POSIX thread barrier with the given
  1516. attributes and thread count.
  1517. Arguments:
  1518. Barrier - Supplies a pointer to the POSIX thread barrier to be initialized.
  1519. Attribute - Supplies an optional pointer to the attribute to use for
  1520. initializing the barrier.
  1521. Count - Supplies the number of threads that must wait on the barrier for it
  1522. to be satisfied.
  1523. Return Value:
  1524. 0 on success.
  1525. Returns an error number on failure.
  1526. --*/
  1527. PTHREAD_API
  1528. int
  1529. pthread_barrier_destroy (
  1530. pthread_barrier_t *Barrier
  1531. );
  1532. /*++
  1533. Routine Description:
  1534. This routine destroys the given POSIX thread barrier.
  1535. Arguments:
  1536. Barrier - Supplies a pointer to the POSIX thread barrier to destroy.
  1537. Return Value:
  1538. 0 on success.
  1539. Returns an error number on failure.
  1540. --*/
  1541. PTHREAD_API
  1542. int
  1543. pthread_barrier_wait (
  1544. pthread_barrier_t *Barrier
  1545. );
  1546. /*++
  1547. Routine Description:
  1548. This routine blocks untils the required number of threads have waited on
  1549. the barrier. Upon success, an arbitrary thread will receive
  1550. PTHREAD_BARRIER_SERIAL_THREAD as a return value; the rest will receive 0.
  1551. This routine does not get interrupted by signals and will continue to block
  1552. after a signal is handled.
  1553. Arguments:
  1554. Barrier - Supplies a pointer to the POSIX thread barrier.
  1555. Return Value:
  1556. 0 or PTHREAD_BARRIER_SERIAL_THREAD on success.
  1557. Returns an error number on failure.
  1558. --*/
  1559. PTHREAD_API
  1560. int
  1561. pthread_barrierattr_init (
  1562. pthread_barrierattr_t *Attribute
  1563. );
  1564. /*++
  1565. Routine Description:
  1566. This routine initializes a barrier attribute structure.
  1567. Arguments:
  1568. Attribute - Supplies a pointer to the barrier attribute structure to
  1569. initialize.
  1570. Return Value:
  1571. 0 on success.
  1572. Returns an error number on failure.
  1573. --*/
  1574. PTHREAD_API
  1575. int
  1576. pthread_barrierattr_destroy (
  1577. pthread_barrierattr_t *Attribute
  1578. );
  1579. /*++
  1580. Routine Description:
  1581. This routine destroys the given barrier attribute structure.
  1582. Arguments:
  1583. Attribute - Supplies a pointer to the barrier attribute to destroy.
  1584. Return Value:
  1585. 0 on success.
  1586. Returns an error number on failure.
  1587. --*/
  1588. PTHREAD_API
  1589. int
  1590. pthread_barrierattr_getpshared (
  1591. const pthread_barrierattr_t *Attribute,
  1592. int *Shared
  1593. );
  1594. /*++
  1595. Routine Description:
  1596. This routine determines the shared state in a barrier attribute.
  1597. Arguments:
  1598. Attribute - Supplies a pointer to the barrier attribute structure.
  1599. Shared - Supplies a pointer where the shared attribute will be returned,
  1600. indicating whether the condition variable is visible across processes.
  1601. See PTHREAD_PROCESS_* definitions.
  1602. Return Value:
  1603. 0 on success.
  1604. Returns an error number on failure.
  1605. --*/
  1606. PTHREAD_API
  1607. int
  1608. pthread_barrierattr_setpshared (
  1609. const pthread_barrierattr_t *Attribute,
  1610. int Shared
  1611. );
  1612. /*++
  1613. Routine Description:
  1614. This routine sets the shared state in a barrier attribute.
  1615. Arguments:
  1616. Attribute - Supplies a pointer to the barrier attribute structure.
  1617. Shared - Supplies the value indicating whether this barrier should be
  1618. visible across processes. See PTHREAD_PROCESS_* definitions.
  1619. Return Value:
  1620. 0 on success.
  1621. Returns an error number on failure.
  1622. --*/
  1623. #ifdef __cplusplus
  1624. }
  1625. #endif
  1626. #endif