pthread.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  1. /* This is an implementation of the threads API of POSIX 1003.1-2001.
  2. *
  3. * --------------------------------------------------------------------------
  4. *
  5. * Pthreads-win32 - POSIX Threads Library for Win32
  6. * Copyright(C) 1998 John E. Bossom
  7. * Copyright(C) 1999,2003 Pthreads-win32 contributors
  8. *
  9. * Contact Email: [email protected]
  10. *
  11. * The current list of contributors is contained
  12. * in the file CONTRIBUTORS included with the source
  13. * code distribution. The list can also be seen at the
  14. * following World Wide Web location:
  15. * http://sources.redhat.com/pthreads-win32/contributors.html
  16. *
  17. * This library is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU Lesser General Public
  19. * License as published by the Free Software Foundation; either
  20. * version 2 of the License, or (at your option) any later version.
  21. *
  22. * This library is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. * Lesser General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Lesser General Public
  28. * License along with this library in the file COPYING.LIB;
  29. * if not, write to the Free Software Foundation, Inc.,
  30. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  31. */
  32. #if !defined( PTHREAD_H )
  33. #define PTHREAD_H
  34. #undef PTW32_LEVEL
  35. #if defined(_POSIX_SOURCE)
  36. #define PTW32_LEVEL 0
  37. /* Early POSIX */
  38. #endif
  39. #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
  40. #undef PTW32_LEVEL
  41. #define PTW32_LEVEL 1
  42. /* Include 1b, 1c and 1d */
  43. #endif
  44. #if defined(INCLUDE_NP)
  45. #undef PTW32_LEVEL
  46. #define PTW32_LEVEL 2
  47. /* Include Non-Portable extensions */
  48. #endif
  49. #define PTW32_LEVEL_MAX 3
  50. #if !defined(PTW32_LEVEL)
  51. #define PTW32_LEVEL PTW32_LEVEL_MAX
  52. /* Include everything */
  53. #endif
  54. #ifdef _UWIN
  55. # define HAVE_STRUCT_TIMESPEC 1
  56. # define HAVE_SIGNAL_H 1
  57. # undef HAVE_CONFIG_H
  58. # pragma comment(lib, "pthread")
  59. #endif
  60. /*
  61. * -------------------------------------------------------------
  62. *
  63. *
  64. * Module: pthread.h
  65. *
  66. * Purpose:
  67. * Provides an implementation of PThreads based upon the
  68. * standard:
  69. *
  70. * POSIX 1003.1-2001
  71. * and
  72. * The Single Unix Specification version 3
  73. *
  74. * (these two are equivalent)
  75. *
  76. * in order to enhance code portability between Windows,
  77. * various commercial Unix implementations, and Linux.
  78. *
  79. * See the ANNOUNCE file for a full list of conforming
  80. * routines and defined constants, and a list of missing
  81. * routines and constants not defined in this implementation.
  82. *
  83. * Authors:
  84. * There have been many contributors to this library.
  85. * The initial implementation was contributed by
  86. * John Bossom, and several others have provided major
  87. * sections or revisions of parts of the implementation.
  88. * Often significant effort has been contributed to
  89. * find and fix important bugs and other problems to
  90. * improve the reliability of the library, which sometimes
  91. * is not reflected in the amount of code which changed as
  92. * result.
  93. * As much as possible, the contributors are acknowledged
  94. * in the ChangeLog file in the source code distribution
  95. * where their changes are noted in detail.
  96. *
  97. * Contributors are listed in the CONTRIBUTORS file.
  98. *
  99. * As usual, all bouquets go to the contributors, and all
  100. * brickbats go to the project maintainer.
  101. *
  102. * Maintainer:
  103. * The code base for this project is coordinated and
  104. * eventually pre-tested, packaged, and made available by
  105. *
  106. * Ross Johnson <[email protected]>
  107. *
  108. * QA Testers:
  109. * Ultimately, the library is tested in the real world by
  110. * a host of competent and demanding scientists and
  111. * engineers who report bugs and/or provide solutions
  112. * which are then fixed or incorporated into subsequent
  113. * versions of the library. Each time a bug is fixed, a
  114. * test case is written to prove the fix and ensure
  115. * that later changes to the code don't reintroduce the
  116. * same error. The number of test cases is slowly growing
  117. * and therefore so is the code reliability.
  118. *
  119. * Compliance:
  120. * See the file ANNOUNCE for the list of implemented
  121. * and not-implemented routines and defined options.
  122. * Of course, these are all defined is this file as well.
  123. *
  124. * Web site:
  125. * The source code and other information about this library
  126. * are available from
  127. *
  128. * http://sources.redhat.com/pthreads-win32/
  129. *
  130. * -------------------------------------------------------------
  131. */
  132. /* Try to avoid including windows.h */
  133. #if defined(__MINGW32__) && defined(__cplusplus)
  134. /*
  135. * FIXME: The pthreadGCE.dll build gets linker unresolved errors
  136. * on pthread_key_create() unless windows.h is included here.
  137. * It appears to have something to do with an argument type mismatch.
  138. * Looking at tsd.o with 'nm' shows this line:
  139. * 00000000 T _pthread_key_create__FPP14pthread_key_t_PFPv_v
  140. * instead of
  141. * 00000000 T _pthread_key_create
  142. */
  143. #define PTW32_INCLUDE_WINDOWS_H
  144. #endif
  145. #ifdef PTW32_INCLUDE_WINDOWS_H
  146. #ifndef WIN32_LEAN_AND_MEAN
  147. #define WIN32_LEAN_AND_MEAN
  148. #endif
  149. #include <Windows.h>
  150. #endif
  151. /*
  152. * -----------------
  153. * autoconf switches
  154. * -----------------
  155. */
  156. #if HAVE_CONFIG_H
  157. #include "config.h"
  158. #endif /* HAVE_CONFIG_H */
  159. #if PTW32_LEVEL >= PTW32_LEVEL_MAX
  160. /* Try to avoid including windows.h */
  161. #if defined(__MINGW32__) && defined(__cplusplus)
  162. /*
  163. * FIXME: The pthreadGCE.dll build gets linker unresolved errors
  164. * on pthread_key_create() unless windows.h is included here.
  165. * It appears to have something to do with an argument type mismatch.
  166. * Looking at tsd.o with 'nm' shows this line:
  167. * 00000000 T _pthread_key_create__FPP14pthread_key_t_PFPv_v
  168. * instead of
  169. * 00000000 T _pthread_key_create
  170. */
  171. #define PTW32_INCLUDE_WINDOWS_H
  172. #endif
  173. #ifdef PTW32_INCLUDE_WINDOWS_H
  174. #ifndef WIN32_LEAN_AND_MEAN
  175. #define WIN32_LEAN_AND_MEAN
  176. #endif
  177. #include <Windows.h>
  178. #endif
  179. #ifndef NEED_FTIME
  180. #include <time.h>
  181. #else /* NEED_FTIME */
  182. /* use native WIN32 time API */
  183. #endif /* NEED_FTIME */
  184. #if HAVE_SIGNAL_H
  185. #include <signal.h>
  186. #endif /* HAVE_SIGNAL_H */
  187. #include <setjmp.h>
  188. #include <limits.h>
  189. /*
  190. * Boolean values to make us independent of system includes.
  191. */
  192. enum {
  193. PTW32_FALSE = 0,
  194. PTW32_TRUE = (! PTW32_FALSE)
  195. };
  196. /*
  197. * This is a duplicate of what is in the autoconf config.h,
  198. * which is only used when building the pthread-win32 libraries.
  199. */
  200. #ifndef PTW32_CONFIG_H
  201. # if defined(WINCE)
  202. # define NEED_ERRNO
  203. # define NEED_SEM
  204. # endif
  205. # if defined(_UWIN) || defined(__MINGW32__)
  206. # define HAVE_MODE_T
  207. # endif
  208. #endif
  209. /*
  210. *
  211. */
  212. #if PTW32_LEVEL >= PTW32_LEVEL_MAX
  213. #ifdef NEED_ERRNO
  214. #include "need_errno.h"
  215. #else
  216. #include <errno.h>
  217. #endif
  218. #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
  219. /*
  220. * Several systems don't define ENOTSUP. If not, we use
  221. * the same value as Solaris.
  222. */
  223. #ifndef ENOTSUP
  224. # define ENOTSUP 48
  225. #endif
  226. #ifndef ETIMEDOUT
  227. # define ETIMEDOUT 10060 /* This is the value in winsock.h. */
  228. #endif
  229. #include <sched.h>
  230. /*
  231. * To avoid including windows.h we define only those things that we
  232. * actually need from it. I don't like the potential incompatibility that
  233. * this creates with future versions of windows.
  234. */
  235. #ifndef PTW32_INCLUDE_WINDOWS_H
  236. #ifndef HANDLE
  237. # define PTW32__HANDLE_DEF
  238. # define HANDLE void *
  239. #endif
  240. #ifndef DWORD
  241. # define PTW32__DWORD_DEF
  242. # define DWORD unsigned long
  243. #endif
  244. #endif
  245. #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
  246. #ifndef HAVE_STRUCT_TIMESPEC
  247. struct timespec {
  248. long tv_sec;
  249. long tv_nsec;
  250. };
  251. #endif /* HAVE_STRUCT_TIMESPEC */
  252. #ifndef SIG_BLOCK
  253. #define SIG_BLOCK 0
  254. #endif /* SIG_BLOCK */
  255. #ifndef SIG_UNBLOCK
  256. #define SIG_UNBLOCK 1
  257. #endif /* SIG_UNBLOCK */
  258. #ifndef SIG_SETMASK
  259. #define SIG_SETMASK 2
  260. #endif /* SIG_SETMASK */
  261. #ifdef __cplusplus
  262. extern "C"
  263. {
  264. #endif /* __cplusplus */
  265. /*
  266. * -------------------------------------------------------------
  267. *
  268. * POSIX 1003.1-2001 Options
  269. * =========================
  270. *
  271. * _POSIX_THREADS (set)
  272. * If set, you can use threads
  273. *
  274. * _POSIX_THREAD_ATTR_STACKSIZE (set)
  275. * If set, you can control the size of a thread's
  276. * stack
  277. * pthread_attr_getstacksize
  278. * pthread_attr_setstacksize
  279. *
  280. * _POSIX_THREAD_ATTR_STACKADDR (not set)
  281. * If set, you can allocate and control a thread's
  282. * stack. If not supported, the following functions
  283. * will return ENOSYS, indicating they are not
  284. * supported:
  285. * pthread_attr_getstackaddr
  286. * pthread_attr_setstackaddr
  287. *
  288. * _POSIX_THREAD_PRIORITY_SCHEDULING (set)
  289. * If set, you can use realtime scheduling.
  290. * Indicates the availability of:
  291. * pthread_attr_getinheritsched
  292. * pthread_attr_getschedparam
  293. * pthread_attr_getschedpolicy
  294. * pthread_attr_getscope
  295. * pthread_attr_setinheritsched
  296. * pthread_attr_setschedparam
  297. * pthread_attr_setschedpolicy
  298. * pthread_attr_setscope
  299. * pthread_getschedparam
  300. * pthread_setschedparam
  301. * sched_get_priority_max
  302. * sched_get_priority_min
  303. * sched_rr_set_interval
  304. *
  305. * _POSIX_THREAD_PRIO_INHERIT (not set)
  306. * If set, you can create priority inheritance
  307. * mutexes.
  308. * pthread_mutexattr_getprotocol +
  309. * pthread_mutexattr_setprotocol +
  310. *
  311. * _POSIX_THREAD_PRIO_PROTECT (not set)
  312. * If set, you can create priority ceiling mutexes
  313. * Indicates the availability of:
  314. * pthread_mutex_getprioceiling
  315. * pthread_mutex_setprioceiling
  316. * pthread_mutexattr_getprioceiling
  317. * pthread_mutexattr_getprotocol +
  318. * pthread_mutexattr_setprioceiling
  319. * pthread_mutexattr_setprotocol +
  320. *
  321. * _POSIX_THREAD_PROCESS_SHARED (not set)
  322. * If set, you can create mutexes and condition
  323. * variables that can be shared with another
  324. * process.If set, indicates the availability
  325. * of:
  326. * pthread_mutexattr_getpshared
  327. * pthread_mutexattr_setpshared
  328. * pthread_condattr_getpshared
  329. * pthread_condattr_setpshared
  330. *
  331. * _POSIX_THREAD_SAFE_FUNCTIONS (set)
  332. * If set you can use the special *_r library
  333. * functions that provide thread-safe behaviour
  334. *
  335. * _POSIX_READER_WRITER_LOCKS (set)
  336. * If set, you can use read/write locks
  337. *
  338. * _POSIX_SPIN_LOCKS (set)
  339. * If set, you can use spin locks
  340. *
  341. * _POSIX_BARRIERS (set)
  342. * If set, you can use barriers
  343. *
  344. * + These functions provide both 'inherit' and/or
  345. * 'protect' protocol, based upon these macro
  346. * settings.
  347. *
  348. * POSIX 1003.1-2001 Limits
  349. * ===========================
  350. *
  351. * PTHREAD_DESTRUCTOR_ITERATIONS
  352. * Maximum number of attempts to destroy
  353. * a thread's thread-specific data on
  354. * termination (must be at least 4)
  355. *
  356. * PTHREAD_KEYS_MAX
  357. * Maximum number of thread-specific data keys
  358. * available per process (must be at least 128)
  359. *
  360. * PTHREAD_STACK_MIN
  361. * Minimum supported stack size for a thread
  362. *
  363. * PTHREAD_THREADS_MAX
  364. * Maximum number of threads supported per
  365. * process (must be at least 64).
  366. *
  367. * _POSIX_SEM_NSEMS_MAX
  368. * The maximum number of semaphores a process can have.
  369. * (only defined if not already defined)
  370. *
  371. * _POSIX_SEM_VALUE_MAX
  372. * The maximum value a semaphore can have.
  373. * (only defined if not already defined)
  374. *
  375. * -------------------------------------------------------------
  376. */
  377. /*
  378. * POSIX Options
  379. */
  380. #ifndef _POSIX_THREADS
  381. #define _POSIX_THREADS
  382. #endif
  383. #ifndef _POSIX_READER_WRITER_LOCKS
  384. #define _POSIX_READER_WRITER_LOCKS
  385. #endif
  386. #ifndef _POSIX_SPIN_LOCKS
  387. #define _POSIX_SPIN_LOCKS
  388. #endif
  389. #ifndef _POSIX_BARRIERS
  390. #define _POSIX_BARRIERS
  391. #endif
  392. #define _POSIX_THREAD_SAFE_FUNCTIONS
  393. #define _POSIX_THREAD_ATTR_STACKSIZE
  394. #define _POSIX_THREAD_PRIORITY_SCHEDULING
  395. #if defined( KLUDGE )
  396. /*
  397. * The following are not supported
  398. */
  399. #define _POSIX_THREAD_ATTR_STACKADDR
  400. #define _POSIX_THREAD_PRIO_INHERIT
  401. #define _POSIX_THREAD_PRIO_PROTECT
  402. #define _POSIX_THREAD_PROCESS_SHARED
  403. #endif /* KLUDGE */
  404. /*
  405. * POSIX Limits
  406. *
  407. * PTHREAD_DESTRUCTOR_ITERATIONS
  408. * Standard states this must be at least
  409. * 4.
  410. *
  411. * PTHREAD_KEYS_MAX
  412. * WIN32 permits only 64 TLS keys per process.
  413. * This limitation could be worked around by
  414. * simply simulating keys.
  415. *
  416. * PTHREADS_STACK_MIN
  417. * POSIX specifies 0 which is also the value WIN32
  418. * interprets as allowing the system to
  419. * set the size to that of the main thread. The
  420. * maximum stack size in Win32 is 1Meg. WIN32
  421. * allocates more stack as required up to the 1Meg
  422. * limit.
  423. *
  424. * PTHREAD_THREADS_MAX
  425. * Not documented by WIN32. Wrote a test program
  426. * that kept creating threads until it failed
  427. * revealed this approximate number (Windows NT).
  428. * This number is somewhat less for Windows 9x
  429. * and is effectively less than 64. Perhaps this
  430. * constant should be set at DLL load time.
  431. *
  432. */
  433. #define PTHREAD_DESTRUCTOR_ITERATIONS 4
  434. #define PTHREAD_KEYS_MAX 64
  435. #define PTHREAD_STACK_MIN 0
  436. #define PTHREAD_THREADS_MAX 2019
  437. #ifndef _POSIX_SEM_NSEMS_MAX
  438. /* Not used and only an arbitrary value. */
  439. # define _POSIX_SEM_NSEMS_MAX 1024
  440. #endif
  441. #ifndef _POSIX_SEM_VALUE_MAX
  442. # define _POSIX_SEM_VALUE_MAX (INT_MAX/2)
  443. #endif
  444. #if __GNUC__ && ! defined (__declspec)
  445. # error Please upgrade your GNU compiler to one that supports __declspec.
  446. #endif
  447. /*
  448. * When building the DLL code, you should define PTW32_BUILD so that
  449. * the variables/functions are exported correctly. When using the DLL,
  450. * do NOT define PTW32_BUILD, and then the variables/functions will
  451. * be imported correctly.
  452. */
  453. #ifdef _DLL
  454. # ifdef PTW32_BUILD
  455. # define PTW32_DLLPORT __declspec (dllexport)
  456. # else
  457. # define PTW32_DLLPORT __declspec (dllimport)
  458. # endif
  459. #endif
  460. #if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX
  461. # include <sys/types.h>
  462. #else
  463. typedef struct pthread_t_ *pthread_t;
  464. typedef struct pthread_attr_t_ *pthread_attr_t;
  465. typedef struct pthread_once_t_ pthread_once_t;
  466. typedef struct pthread_key_t_ *pthread_key_t;
  467. typedef struct pthread_mutex_t_ *pthread_mutex_t;
  468. typedef struct pthread_mutexattr_t_ *pthread_mutexattr_t;
  469. typedef struct pthread_cond_t_ *pthread_cond_t;
  470. typedef struct pthread_condattr_t_ *pthread_condattr_t;
  471. #endif
  472. typedef struct pthread_rwlock_t_ *pthread_rwlock_t;
  473. typedef struct pthread_rwlockattr_t_ *pthread_rwlockattr_t;
  474. typedef struct pthread_spinlock_t_ *pthread_spinlock_t;
  475. typedef struct pthread_barrier_t_ *pthread_barrier_t;
  476. typedef struct pthread_barrierattr_t_ *pthread_barrierattr_t;
  477. /*
  478. * ====================
  479. * ====================
  480. * POSIX Threads
  481. * ====================
  482. * ====================
  483. */
  484. enum {
  485. /*
  486. * pthread_attr_{get,set}detachstate
  487. */
  488. PTHREAD_CREATE_JOINABLE = 0, /* Default */
  489. PTHREAD_CREATE_DETACHED = 1,
  490. /*
  491. * pthread_attr_{get,set}inheritsched
  492. */
  493. PTHREAD_INHERIT_SCHED = 0,
  494. PTHREAD_EXPLICIT_SCHED = 1, /* Default */
  495. /*
  496. * pthread_{get,set}scope
  497. */
  498. PTHREAD_SCOPE_PROCESS = 0,
  499. PTHREAD_SCOPE_SYSTEM = 1, /* Default */
  500. /*
  501. * pthread_setcancelstate paramters
  502. */
  503. PTHREAD_CANCEL_ENABLE = 0, /* Default */
  504. PTHREAD_CANCEL_DISABLE = 1,
  505. /*
  506. * pthread_setcanceltype parameters
  507. */
  508. PTHREAD_CANCEL_ASYNCHRONOUS = 0,
  509. PTHREAD_CANCEL_DEFERRED = 1, /* Default */
  510. /*
  511. * pthread_mutexattr_{get,set}pshared
  512. * pthread_condattr_{get,set}pshared
  513. */
  514. PTHREAD_PROCESS_PRIVATE = 0,
  515. PTHREAD_PROCESS_SHARED = 1,
  516. /*
  517. * pthread_barrier_wait
  518. */
  519. PTHREAD_BARRIER_SERIAL_THREAD = -1
  520. };
  521. /*
  522. * ====================
  523. * ====================
  524. * Cancelation
  525. * ====================
  526. * ====================
  527. */
  528. #define PTHREAD_CANCELED ((void *) -1)
  529. /*
  530. * ====================
  531. * ====================
  532. * Once Key
  533. * ====================
  534. * ====================
  535. */
  536. #define PTHREAD_ONCE_INIT { PTW32_FALSE, -1 }
  537. struct pthread_once_t_
  538. {
  539. int done; /* indicates if user function executed */
  540. long started; /* First thread to increment this value */
  541. /* to zero executes the user function */
  542. };
  543. /*
  544. * ====================
  545. * ====================
  546. * Object initialisers
  547. * ====================
  548. * ====================
  549. */
  550. #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
  551. #define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
  552. #define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1)
  553. #define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t) -1)
  554. /*
  555. * Mutex types.
  556. */
  557. enum
  558. {
  559. /* Compatibility with LinuxThreads */
  560. PTHREAD_MUTEX_FAST_NP,
  561. PTHREAD_MUTEX_RECURSIVE_NP,
  562. PTHREAD_MUTEX_ERRORCHECK_NP,
  563. PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP,
  564. PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP,
  565. /* For compatibility with POSIX */
  566. PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP,
  567. PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
  568. PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
  569. PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
  570. };
  571. /* There are three implementations of cancel cleanup.
  572. * Note that pthread.h is included in both application
  573. * compilation units and also internally for the library.
  574. * The code here and within the library aims to work
  575. * for all reasonable combinations of environments.
  576. *
  577. * The three implementations are:
  578. *
  579. * WIN32 SEH
  580. * C
  581. * C++
  582. *
  583. * Please note that exiting a push/pop block via
  584. * "return", "exit", "break", or "continue" will
  585. * lead to different behaviour amongst applications
  586. * depending upon whether the library was built
  587. * using SEH, C++, or C. For example, a library built
  588. * with SEH will call the cleanup routine, while both
  589. * C++ and C built versions will not.
  590. */
  591. /*
  592. * Define defaults for cleanup code.
  593. * Note: Unless the build explicitly defines one of the following, then
  594. * we default to standard C style cleanup. This style uses setjmp/longjmp
  595. * in the cancelation and thread exit implementations and therefore won't
  596. * do stack unwinding if linked to applications that have it (e.g.
  597. * C++ apps). This is currently consistent with most/all commercial Unix
  598. * POSIX threads implementations.
  599. */
  600. #if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C )
  601. # define __CLEANUP_C
  602. #endif
  603. #if defined( __CLEANUP_SEH ) && defined(__GNUC__)
  604. #error ERROR [__FILE__, line __LINE__]: GNUC does not support SEH.
  605. #endif
  606. typedef struct ptw32_cleanup_t ptw32_cleanup_t;
  607. typedef void (__cdecl *ptw32_cleanup_callback_t)(void *);
  608. struct ptw32_cleanup_t
  609. {
  610. ptw32_cleanup_callback_t routine;
  611. void *arg;
  612. struct ptw32_cleanup_t *prev;
  613. };
  614. #ifdef __CLEANUP_SEH
  615. /*
  616. * WIN32 SEH version of cancel cleanup.
  617. */
  618. #define pthread_cleanup_push( _rout, _arg ) \
  619. { \
  620. ptw32_cleanup_t _cleanup; \
  621. \
  622. _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \
  623. _cleanup.arg = (_arg); \
  624. __try \
  625. { \
  626. #define pthread_cleanup_pop( _execute ) \
  627. } \
  628. __finally \
  629. { \
  630. if( _execute || AbnormalTermination()) \
  631. { \
  632. (*(_cleanup.routine))( _cleanup.arg ); \
  633. } \
  634. } \
  635. }
  636. #else /* __CLEANUP_SEH */
  637. #ifdef __CLEANUP_C
  638. /*
  639. * C implementation of PThreads cancel cleanup
  640. */
  641. #define pthread_cleanup_push( _rout, _arg ) \
  642. { \
  643. ptw32_cleanup_t _cleanup; \
  644. \
  645. ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \
  646. #define pthread_cleanup_pop( _execute ) \
  647. (void) ptw32_pop_cleanup( _execute ); \
  648. }
  649. #else /* __CLEANUP_C */
  650. #ifdef __CLEANUP_CXX
  651. /*
  652. * C++ version of cancel cleanup.
  653. * - John E. Bossom.
  654. */
  655. class PThreadCleanup {
  656. /*
  657. * PThreadCleanup
  658. *
  659. * Purpose
  660. * This class is a C++ helper class that is
  661. * used to implement pthread_cleanup_push/
  662. * pthread_cleanup_pop.
  663. * The destructor of this class automatically
  664. * pops the pushed cleanup routine regardless
  665. * of how the code exits the scope
  666. * (i.e. such as by an exception)
  667. */
  668. ptw32_cleanup_callback_t cleanUpRout;
  669. void * obj;
  670. int executeIt;
  671. public:
  672. PThreadCleanup() :
  673. cleanUpRout( 0 ),
  674. obj( 0 ),
  675. executeIt( 0 )
  676. /*
  677. * No cleanup performed
  678. */
  679. {
  680. }
  681. PThreadCleanup(
  682. ptw32_cleanup_callback_t routine,
  683. void * arg ) :
  684. cleanUpRout( routine ),
  685. obj( arg ),
  686. executeIt( 1 )
  687. /*
  688. * Registers a cleanup routine for 'arg'
  689. */
  690. {
  691. }
  692. ~PThreadCleanup()
  693. {
  694. if ( executeIt && ((void *) cleanUpRout != (void *) 0) )
  695. {
  696. (void) (*cleanUpRout)( obj );
  697. }
  698. }
  699. void execute( int exec )
  700. {
  701. executeIt = exec;
  702. }
  703. };
  704. /*
  705. * C++ implementation of PThreads cancel cleanup;
  706. * This implementation takes advantage of a helper
  707. * class who's destructor automatically calls the
  708. * cleanup routine if we exit our scope weirdly
  709. */
  710. #define pthread_cleanup_push( _rout, _arg ) \
  711. { \
  712. PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \
  713. (void *) (_arg) );
  714. #define pthread_cleanup_pop( _execute ) \
  715. cleanup.execute( _execute ); \
  716. }
  717. #else
  718. #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
  719. #endif /* __CLEANUP_CXX */
  720. #endif /* __CLEANUP_C */
  721. #endif /* __CLEANUP_SEH */
  722. /*
  723. * ===============
  724. * ===============
  725. * Methods
  726. * ===============
  727. * ===============
  728. */
  729. /*
  730. * PThread Attribute Functions
  731. */
  732. PTW32_DLLPORT int pthread_attr_init (pthread_attr_t * attr);
  733. PTW32_DLLPORT int pthread_attr_destroy (pthread_attr_t * attr);
  734. PTW32_DLLPORT int pthread_attr_getdetachstate (const pthread_attr_t * attr,
  735. int *detachstate);
  736. PTW32_DLLPORT int pthread_attr_getstackaddr (const pthread_attr_t * attr,
  737. void **stackaddr);
  738. PTW32_DLLPORT int pthread_attr_getstacksize (const pthread_attr_t * attr,
  739. size_t * stacksize);
  740. PTW32_DLLPORT int pthread_attr_setdetachstate (pthread_attr_t * attr,
  741. int detachstate);
  742. PTW32_DLLPORT int pthread_attr_setstackaddr (pthread_attr_t * attr,
  743. void *stackaddr);
  744. PTW32_DLLPORT int pthread_attr_setstacksize (pthread_attr_t * attr,
  745. size_t stacksize);
  746. PTW32_DLLPORT int pthread_attr_getschedparam (const pthread_attr_t *attr,
  747. struct sched_param *param);
  748. PTW32_DLLPORT int pthread_attr_setschedparam (pthread_attr_t *attr,
  749. const struct sched_param *param);
  750. PTW32_DLLPORT int pthread_attr_setschedpolicy (pthread_attr_t *,
  751. int);
  752. PTW32_DLLPORT int pthread_attr_getschedpolicy (pthread_attr_t *,
  753. int *);
  754. PTW32_DLLPORT int pthread_attr_setinheritsched(pthread_attr_t * attr,
  755. int inheritsched);
  756. PTW32_DLLPORT int pthread_attr_getinheritsched(pthread_attr_t * attr,
  757. int * inheritsched);
  758. PTW32_DLLPORT int pthread_attr_setscope (pthread_attr_t *,
  759. int);
  760. PTW32_DLLPORT int pthread_attr_getscope (const pthread_attr_t *,
  761. int *);
  762. /*
  763. * PThread Functions
  764. */
  765. PTW32_DLLPORT int pthread_create (pthread_t * tid,
  766. const pthread_attr_t * attr,
  767. void *(*start) (void *),
  768. void *arg);
  769. PTW32_DLLPORT int pthread_detach (pthread_t tid);
  770. PTW32_DLLPORT int pthread_equal (pthread_t t1,
  771. pthread_t t2);
  772. PTW32_DLLPORT void pthread_exit (void *value_ptr);
  773. PTW32_DLLPORT int pthread_join (pthread_t thread,
  774. void **value_ptr);
  775. PTW32_DLLPORT pthread_t pthread_self (void);
  776. PTW32_DLLPORT int pthread_cancel (pthread_t thread);
  777. PTW32_DLLPORT int pthread_setcancelstate (int state,
  778. int *oldstate);
  779. PTW32_DLLPORT int pthread_setcanceltype (int type,
  780. int *oldtype);
  781. PTW32_DLLPORT void pthread_testcancel (void);
  782. PTW32_DLLPORT int pthread_once (pthread_once_t * once_control,
  783. void (*init_routine) (void));
  784. #if PTW32_LEVEL >= PTW32_LEVEL_MAX
  785. PTW32_DLLPORT ptw32_cleanup_t *ptw32_pop_cleanup (int execute);
  786. PTW32_DLLPORT void ptw32_push_cleanup (ptw32_cleanup_t * cleanup,
  787. void (*routine) (void *),
  788. void *arg);
  789. #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
  790. /*
  791. * Thread Specific Data Functions
  792. */
  793. PTW32_DLLPORT int pthread_key_create (pthread_key_t * key,
  794. void (*destructor) (void *));
  795. PTW32_DLLPORT int pthread_key_delete (pthread_key_t key);
  796. PTW32_DLLPORT int pthread_setspecific (pthread_key_t key,
  797. const void *value);
  798. PTW32_DLLPORT void *pthread_getspecific (pthread_key_t key);
  799. /*
  800. * Mutex Attribute Functions
  801. */
  802. PTW32_DLLPORT int pthread_mutexattr_init (pthread_mutexattr_t * attr);
  803. PTW32_DLLPORT int pthread_mutexattr_destroy (pthread_mutexattr_t * attr);
  804. PTW32_DLLPORT int pthread_mutexattr_getpshared (const pthread_mutexattr_t
  805. * attr,
  806. int *pshared);
  807. PTW32_DLLPORT int pthread_mutexattr_setpshared (pthread_mutexattr_t * attr,
  808. int pshared);
  809. PTW32_DLLPORT int pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind);
  810. PTW32_DLLPORT int pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *kind);
  811. /*
  812. * Barrier Attribute Functions
  813. */
  814. PTW32_DLLPORT int pthread_barrierattr_init (pthread_barrierattr_t * attr);
  815. PTW32_DLLPORT int pthread_barrierattr_destroy (pthread_barrierattr_t * attr);
  816. PTW32_DLLPORT int pthread_barrierattr_getpshared (const pthread_barrierattr_t
  817. * attr,
  818. int *pshared);
  819. PTW32_DLLPORT int pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
  820. int pshared);
  821. /*
  822. * Mutex Functions
  823. */
  824. PTW32_DLLPORT int pthread_mutex_init (pthread_mutex_t * mutex,
  825. const pthread_mutexattr_t * attr);
  826. PTW32_DLLPORT int pthread_mutex_destroy (pthread_mutex_t * mutex);
  827. PTW32_DLLPORT int pthread_mutex_lock (pthread_mutex_t * mutex);
  828. PTW32_DLLPORT int pthread_mutex_timedlock(pthread_mutex_t *mutex,
  829. const struct timespec *abstime);
  830. PTW32_DLLPORT int pthread_mutex_trylock (pthread_mutex_t * mutex);
  831. PTW32_DLLPORT int pthread_mutex_unlock (pthread_mutex_t * mutex);
  832. /*
  833. * Spinlock Functions
  834. */
  835. PTW32_DLLPORT int pthread_spin_init (pthread_spinlock_t * lock, int pshared);
  836. PTW32_DLLPORT int pthread_spin_destroy (pthread_spinlock_t * lock);
  837. PTW32_DLLPORT int pthread_spin_lock (pthread_spinlock_t * lock);
  838. PTW32_DLLPORT int pthread_spin_trylock (pthread_spinlock_t * lock);
  839. PTW32_DLLPORT int pthread_spin_unlock (pthread_spinlock_t * lock);
  840. /*
  841. * Barrier Functions
  842. */
  843. PTW32_DLLPORT int pthread_barrier_init (pthread_barrier_t * barrier,
  844. const pthread_barrierattr_t * attr,
  845. unsigned int count);
  846. PTW32_DLLPORT int pthread_barrier_destroy (pthread_barrier_t * barrier);
  847. PTW32_DLLPORT int pthread_barrier_wait (pthread_barrier_t * barrier);
  848. /*
  849. * Condition Variable Attribute Functions
  850. */
  851. PTW32_DLLPORT int pthread_condattr_init (pthread_condattr_t * attr);
  852. PTW32_DLLPORT int pthread_condattr_destroy (pthread_condattr_t * attr);
  853. PTW32_DLLPORT int pthread_condattr_getpshared (const pthread_condattr_t * attr,
  854. int *pshared);
  855. PTW32_DLLPORT int pthread_condattr_setpshared (pthread_condattr_t * attr,
  856. int pshared);
  857. /*
  858. * Condition Variable Functions
  859. */
  860. PTW32_DLLPORT int pthread_cond_init (pthread_cond_t * cond,
  861. const pthread_condattr_t * attr);
  862. PTW32_DLLPORT int pthread_cond_destroy (pthread_cond_t * cond);
  863. PTW32_DLLPORT int pthread_cond_wait (pthread_cond_t * cond,
  864. pthread_mutex_t * mutex);
  865. PTW32_DLLPORT int pthread_cond_timedwait (pthread_cond_t * cond,
  866. pthread_mutex_t * mutex,
  867. const struct timespec *abstime);
  868. PTW32_DLLPORT int pthread_cond_signal (pthread_cond_t * cond);
  869. PTW32_DLLPORT int pthread_cond_broadcast (pthread_cond_t * cond);
  870. /*
  871. * Scheduling
  872. */
  873. PTW32_DLLPORT int pthread_setschedparam (pthread_t thread,
  874. int policy,
  875. const struct sched_param *param);
  876. PTW32_DLLPORT int pthread_getschedparam (pthread_t thread,
  877. int *policy,
  878. struct sched_param *param);
  879. PTW32_DLLPORT int pthread_setconcurrency (int);
  880. PTW32_DLLPORT int pthread_getconcurrency (void);
  881. /*
  882. * Read-Write Lock Functions
  883. */
  884. PTW32_DLLPORT int pthread_rwlock_init(pthread_rwlock_t *lock,
  885. const pthread_rwlockattr_t *attr);
  886. PTW32_DLLPORT int pthread_rwlock_destroy(pthread_rwlock_t *lock);
  887. PTW32_DLLPORT int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
  888. PTW32_DLLPORT int pthread_rwlock_trywrlock(pthread_rwlock_t *);
  889. PTW32_DLLPORT int pthread_rwlock_rdlock(pthread_rwlock_t *lock);
  890. PTW32_DLLPORT int pthread_rwlock_timedrdlock(pthread_rwlock_t *lock,
  891. const struct timespec *abstime);
  892. PTW32_DLLPORT int pthread_rwlock_wrlock(pthread_rwlock_t *lock);
  893. PTW32_DLLPORT int pthread_rwlock_timedwrlock(pthread_rwlock_t *lock,
  894. const struct timespec *abstime);
  895. PTW32_DLLPORT int pthread_rwlock_unlock(pthread_rwlock_t *lock);
  896. PTW32_DLLPORT int pthread_rwlockattr_init (pthread_rwlockattr_t * attr);
  897. PTW32_DLLPORT int pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr);
  898. PTW32_DLLPORT int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr,
  899. int *pshared);
  900. PTW32_DLLPORT int pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
  901. int pshared);
  902. /*
  903. * Errno reading function
  904. * Added by Paul Pedriana, 10/2003
  905. */
  906. PTW32_DLLPORT int pthread_win32_errno(void);
  907. #if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1
  908. /*
  909. * Signal Functions. Should be defined in <signal.h> but MSVC and MinGW32
  910. * already have signal.h that don't define these.
  911. */
  912. PTW32_DLLPORT int pthread_kill(pthread_t thread, int sig);
  913. /*
  914. * Non-portable functions
  915. */
  916. /*
  917. * Compatibility with Linux.
  918. */
  919. PTW32_DLLPORT int pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr,
  920. int kind);
  921. PTW32_DLLPORT int pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr,
  922. int *kind);
  923. /*
  924. * Possibly supported by other POSIX threads implementations
  925. */
  926. PTW32_DLLPORT int pthread_delay_np (struct timespec * interval);
  927. PTW32_DLLPORT int pthread_num_processors_np(void);
  928. /*
  929. * Useful if an application wants to statically link
  930. * the lib rather than load the DLL at run-time.
  931. */
  932. PTW32_DLLPORT int pthread_win32_process_attach_np(void);
  933. PTW32_DLLPORT int pthread_win32_process_detach_np(void);
  934. PTW32_DLLPORT int pthread_win32_thread_attach_np(void);
  935. PTW32_DLLPORT int pthread_win32_thread_detach_np(void);
  936. /*
  937. * Register a system time change with the library.
  938. * Causes the library to perform various functions
  939. * in response to the change. Should be called whenever
  940. * the application's top level window receives a
  941. * WM_TIMECHANGE message. It can be passed directly to
  942. * pthread_create() as a new thread if desired.
  943. */
  944. PTW32_DLLPORT void * pthread_timechange_handler_np(void *);
  945. #endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */
  946. #if PTW32_LEVEL >= PTW32_LEVEL_MAX
  947. /*
  948. * Returns the Win32 HANDLE for the POSIX thread.
  949. */
  950. PTW32_DLLPORT HANDLE pthread_getw32threadhandle_np(pthread_t thread);
  951. /*
  952. * Protected Methods
  953. *
  954. * This function blocks until the given WIN32 handle
  955. * is signaled or pthread_cancel had been called.
  956. * This function allows the caller to hook into the
  957. * PThreads cancel mechanism. It is implemented using
  958. *
  959. * WaitForMultipleObjects
  960. *
  961. * on 'waitHandle' and a manually reset WIN32 Event
  962. * used to implement pthread_cancel. The 'timeout'
  963. * argument to TimedWait is simply passed to
  964. * WaitForMultipleObjects.
  965. */
  966. PTW32_DLLPORT int pthreadCancelableWait (HANDLE waitHandle);
  967. PTW32_DLLPORT int pthreadCancelableTimedWait (HANDLE waitHandle,
  968. DWORD timeout);
  969. #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
  970. /*
  971. * Thread-Safe C Runtime Library Mappings.
  972. */
  973. #ifndef _UWIN
  974. # if defined(NEED_ERRNO)
  975. PTW32_DLLPORT int * _errno( void );
  976. # else
  977. # ifndef errno
  978. # if (defined(_MT) || defined(_DLL))
  979. __declspec(dllimport) extern int * __cdecl _errno(void);
  980. # define errno (*_errno())
  981. # endif
  982. # endif
  983. # endif
  984. #endif
  985. /*
  986. * WIN32 C runtime library had been made thread-safe
  987. * without affecting the user interface. Provide
  988. * mappings from the UNIX thread-safe versions to
  989. * the standard C runtime library calls.
  990. * Only provide function mappings for functions that
  991. * actually exist on WIN32.
  992. */
  993. #if !defined(__MINGW32__)
  994. #define strtok_r( _s, _sep, _lasts ) \
  995. ( *(_lasts) = strtok( (_s), (_sep) ) )
  996. #endif /* !__MINGW32__ */
  997. #define asctime_r( _tm, _buf ) \
  998. ( strcpy( (_buf), asctime( (_tm) ) ), \
  999. (_buf) )
  1000. #define ctime_r( _clock, _buf ) \
  1001. ( strcpy( (_buf), ctime( (_clock) ) ), \
  1002. (_buf) )
  1003. #define gmtime_r( _clock, _result ) \
  1004. ( *(_result) = *gmtime( (_clock) ), \
  1005. (_result) )
  1006. #define localtime_r( _clock, _result ) \
  1007. ( *(_result) = *localtime( (_clock) ), \
  1008. (_result) )
  1009. #define rand_r( _seed ) \
  1010. ( _seed == _seed? rand() : rand() )
  1011. #ifdef __cplusplus
  1012. /*
  1013. * Internal exceptions
  1014. */
  1015. class ptw32_exception {};
  1016. class ptw32_exception_cancel : public ptw32_exception {};
  1017. class ptw32_exception_exit : public ptw32_exception {};
  1018. #endif
  1019. #if PTW32_LEVEL >= PTW32_LEVEL_MAX
  1020. /* FIXME: This is only required if the library was built using SEH */
  1021. /*
  1022. * Get internal SEH tag
  1023. */
  1024. PTW32_DLLPORT DWORD ptw32_get_exception_services_code(void);
  1025. #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
  1026. #ifndef PTW32_BUILD
  1027. #ifdef __CLEANUP_SEH
  1028. /*
  1029. * Redefine the SEH __except keyword to ensure that applications
  1030. * propagate our internal exceptions up to the library's internal handlers.
  1031. */
  1032. #define __except( E ) \
  1033. __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \
  1034. ? EXCEPTION_CONTINUE_SEARCH : ( E ) )
  1035. #endif /* __CLEANUP_SEH */
  1036. #ifdef __CLEANUP_CXX
  1037. /*
  1038. * Redefine the C++ catch keyword to ensure that applications
  1039. * propagate our internal exceptions up to the library's internal handlers.
  1040. */
  1041. #ifdef _MSC_VER
  1042. /*
  1043. * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll'
  1044. * if you want Pthread-Win32 cancelation and pthread_exit to work.
  1045. */
  1046. #ifndef PtW32NoCatchWarn
  1047. #pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.")
  1048. #pragma message("------------------------------------------------------------------")
  1049. #pragma message("When compiling applications with MSVC++ and C++ exception handling:")
  1050. #pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads")
  1051. #pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread")
  1052. #pragma message(" cancelation and pthread_exit to work. For example:")
  1053. #pragma message("")
  1054. #pragma message(" #ifdef PtW32CatchAll")
  1055. #pragma message(" PtW32CatchAll")
  1056. #pragma message(" #else")
  1057. #pragma message(" catch(...)")
  1058. #pragma message(" #endif")
  1059. #pragma message(" {")
  1060. #pragma message(" /* Catchall block processing */")
  1061. #pragma message(" }")
  1062. #pragma message("------------------------------------------------------------------")
  1063. #endif
  1064. #define PtW32CatchAll \
  1065. catch( ptw32_exception & ) { throw; } \
  1066. catch( ... )
  1067. #else /* _MSC_VER */
  1068. #define catch( E ) \
  1069. catch( ptw32_exception & ) { throw; } \
  1070. catch( E )
  1071. #endif /* _MSC_VER */
  1072. #endif /* __CLEANUP_CXX */
  1073. #endif /* ! PTW32_BUILD */
  1074. #ifdef __cplusplus
  1075. } /* End of extern "C" */
  1076. #endif /* __cplusplus */
  1077. #ifdef PTW32__HANDLE_DEF
  1078. # undef HANDLE
  1079. #endif
  1080. #ifdef PTW32__DWORD_DEF
  1081. # undef DWORD
  1082. #endif
  1083. #undef PTW32_LEVEL
  1084. #undef PTW32_LEVEL_MAX
  1085. #endif /* PTHREAD_H */