properly handle meter channel count changes
[ardour.git] / msvc_extra_headers / ardourext / ptw32 / pthread.h.input
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,2005 Pthreads-win32 contributors
8  * 
9  *      Contact Email: rpj@callisto.canberra.edu.au
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
33 #if !defined( PTHREAD_H )
34 #ifdef  _PTHREAD_H  // Test added by JE - 12-12-2009
35 #error  "ptw32/pthread.h conflicts with an existing pthread library"
36 #endif
37 // Now make sure we can't accidentally include a conflicting library !!
38 #define _PTHREAD_H
39 #define PTHREAD_H
40
41 /*
42  * See the README file for an explanation of the pthreads-win32 version
43  * numbering scheme and how the DLL is named etc.
44  */
45 #define PTW32_VERSION 2,8,0,0
46 #define PTW32_VERSION_STRING "2, 8, 0, 0\0"
47
48 /* There are three implementations of cancel cleanup.
49  * Note that pthread.h is included in both application
50  * compilation units and also internally for the library.
51  * The code here and within the library aims to work
52  * for all reasonable combinations of environments.
53  *
54  * The three implementations are:
55  *
56  *   WIN32 SEH
57  *   C
58  *   C++
59  *
60  * Please note that exiting a push/pop block via
61  * "return", "exit", "break", or "continue" will
62  * lead to different behaviour amongst applications
63  * depending upon whether the library was built
64  * using SEH, C++, or C. For example, a library built
65  * with SEH will call the cleanup routine, while both
66  * C++ and C built versions will not.
67  */
68
69 /*
70  * Define defaults for cleanup code.
71  * Note: Unless the build explicitly defines one of the following, then
72  * we default to standard C style cleanup. This style uses setjmp/longjmp
73  * in the cancelation and thread exit implementations and therefore won't
74  * do stack unwinding if linked to applications that have it (e.g.
75  * C++ apps). This is currently consistent with most/all commercial Unix
76  * POSIX threads implementations.
77  */
78 #if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C )
79 # define __CLEANUP_C
80 #endif
81
82 #if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC))
83 #error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler.
84 #endif
85
86 /*
87  * Stop here if we are being included by the resource compiler.
88  */
89 #ifndef RC_INVOKED
90
91 #undef PTW32_LEVEL
92
93 #if defined(_POSIX_SOURCE)
94 #define PTW32_LEVEL 0
95 /* Early POSIX */
96 #endif
97
98 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
99 #undef PTW32_LEVEL
100 #define PTW32_LEVEL 1
101 /* Include 1b, 1c and 1d */
102 #endif
103
104 #if defined(INCLUDE_NP)
105 #undef PTW32_LEVEL
106 #define PTW32_LEVEL 2
107 /* Include Non-Portable extensions */
108 #endif
109
110 #define PTW32_LEVEL_MAX 3
111
112 #if !defined(PTW32_LEVEL)
113 #define PTW32_LEVEL PTW32_LEVEL_MAX
114 /* Include everything */
115 #endif
116
117 #ifdef _UWIN
118 #   define HAVE_STRUCT_TIMESPEC 1
119 #   define HAVE_SIGNAL_H        1
120 #   undef HAVE_CONFIG_H
121 #   pragma comment(lib, "pthread")
122 #endif
123
124 /*
125  * -------------------------------------------------------------
126  *
127  *
128  * Module: pthread.h
129  *
130  * Purpose:
131  *      Provides an implementation of PThreads based upon the
132  *      standard:
133  *
134  *              POSIX 1003.1-2001
135  *  and
136  *    The Single Unix Specification version 3
137  *
138  *    (these two are equivalent)
139  *
140  *      in order to enhance code portability between Windows,
141  *  various commercial Unix implementations, and Linux.
142  *
143  *      See the ANNOUNCE file for a full list of conforming
144  *      routines and defined constants, and a list of missing
145  *      routines and constants not defined in this implementation.
146  *
147  * Authors:
148  *      There have been many contributors to this library.
149  *      The initial implementation was contributed by
150  *      John Bossom, and several others have provided major
151  *      sections or revisions of parts of the implementation.
152  *      Often significant effort has been contributed to
153  *      find and fix important bugs and other problems to
154  *      improve the reliability of the library, which sometimes
155  *      is not reflected in the amount of code which changed as
156  *      result.
157  *      As much as possible, the contributors are acknowledged
158  *      in the ChangeLog file in the source code distribution
159  *      where their changes are noted in detail.
160  *
161  *      Contributors are listed in the CONTRIBUTORS file.
162  *
163  *      As usual, all bouquets go to the contributors, and all
164  *      brickbats go to the project maintainer.
165  *
166  * Maintainer:
167  *      The code base for this project is coordinated and
168  *      eventually pre-tested, packaged, and made available by
169  *
170  *              Ross Johnson <rpj@callisto.canberra.edu.au>
171  *
172  * QA Testers:
173  *      Ultimately, the library is tested in the real world by
174  *      a host of competent and demanding scientists and
175  *      engineers who report bugs and/or provide solutions
176  *      which are then fixed or incorporated into subsequent
177  *      versions of the library. Each time a bug is fixed, a
178  *      test case is written to prove the fix and ensure
179  *      that later changes to the code don't reintroduce the
180  *      same error. The number of test cases is slowly growing
181  *      and therefore so is the code reliability.
182  *
183  * Compliance:
184  *      See the file ANNOUNCE for the list of implemented
185  *      and not-implemented routines and defined options.
186  *      Of course, these are all defined is this file as well.
187  *
188  * Web site:
189  *      The source code and other information about this library
190  *      are available from
191  *
192  *              http://sources.redhat.com/pthreads-win32/
193  *
194  * -------------------------------------------------------------
195  */
196
197 /* Try to avoid including windows.h */
198 #if defined(__MINGW32__) && defined(__cplusplus)
199 #define PTW32_INCLUDE_WINDOWS_H
200 #endif
201
202 #ifdef PTW32_INCLUDE_WINDOWS_H
203 #include <windows.h>
204 #endif
205
206 #if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__)
207 /*
208  * VC++6.0 or early compiler's header has no DWORD_PTR type.
209  */
210 typedef unsigned long DWORD_PTR;
211 #endif
212 /*
213  * -----------------
214  * autoconf switches
215  * -----------------
216  */
217
218 #if HAVE_CONFIG_H
219 #include "config.h"
220 #endif /* HAVE_CONFIG_H */
221
222 #ifndef NEED_FTIME
223 #include <time.h>
224 #else /* NEED_FTIME */
225 /* use native WIN32 time API */
226 #endif /* NEED_FTIME */
227
228 #if HAVE_SIGNAL_H
229 #include <signal.h>
230 #endif /* HAVE_SIGNAL_H */
231
232 #include <setjmp.h>
233 #include <limits.h>
234
235 /*
236  * Boolean values to make us independent of system includes.
237  */
238 enum {
239   PTW32_FALSE = 0,
240   PTW32_TRUE = (! PTW32_FALSE)
241 };
242
243 /*
244  * This is a duplicate of what is in the autoconf config.h,
245  * which is only used when building the pthread-win32 libraries.
246  */
247
248 #ifndef PTW32_CONFIG_H
249 #  if defined(WINCE)
250 #    define NEED_ERRNO
251 #    define NEED_SEM
252 #  endif
253 #  if defined(_UWIN) || defined(__MINGW32__)
254 #    define HAVE_MODE_T
255 #  endif
256 #endif
257
258 /*
259  *
260  */
261
262 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
263 #ifdef NEED_ERRNO
264 #include "need_errno.h"
265 #else
266 #include <errno.h>
267 #endif
268 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
269
270 /*
271  * Several systems don't define some error numbers.
272  */
273 #ifndef ENOTSUP
274 #  define ENOTSUP 48   /* This is the value in Solaris. */
275 #endif
276
277 #ifndef ETIMEDOUT
278 #  define ETIMEDOUT 10060     /* This is the value in winsock.h. */
279 #endif
280
281 #ifndef ENOSYS
282 #  define ENOSYS 140     /* Semi-arbitrary value */
283 #endif
284
285 #ifndef EDEADLK
286 #  ifdef EDEADLOCK
287 #    define EDEADLK EDEADLOCK
288 #  else
289 #    define EDEADLK 36     /* This is the value in MSVC. */
290 #  endif
291 #endif
292
293 #include <ardourext/sched.h>
294
295 /*
296  * To avoid including windows.h we define only those things that we
297  * actually need from it.
298  */
299 #ifndef PTW32_INCLUDE_WINDOWS_H
300 #ifndef HANDLE
301 # define PTW32__HANDLE_DEF
302 # define HANDLE void *
303 #endif
304 #ifndef DWORD
305 # define PTW32__DWORD_DEF
306 # define DWORD unsigned long
307 #endif
308 #endif
309
310 #ifndef HAVE_STRUCT_TIMESPEC
311 #define HAVE_STRUCT_TIMESPEC 1
312 struct timespec {
313         long tv_sec;
314         long tv_nsec;
315 };
316 #endif /* HAVE_STRUCT_TIMESPEC */
317
318 #ifndef SIG_BLOCK
319 #define SIG_BLOCK 0
320 #endif /* SIG_BLOCK */
321
322 #ifndef SIG_UNBLOCK 
323 #define SIG_UNBLOCK 1
324 #endif /* SIG_UNBLOCK */
325
326 #ifndef SIG_SETMASK
327 #define SIG_SETMASK 2
328 #endif /* SIG_SETMASK */
329
330 #ifdef __cplusplus
331 extern "C"
332 {
333 #endif                          /* __cplusplus */
334
335 /*
336  * -------------------------------------------------------------
337  *
338  * POSIX 1003.1-2001 Options
339  * =========================
340  *
341  * Options are normally set in <unistd.h>, which is not provided
342  * with pthreads-win32.
343  *
344  * For conformance with the Single Unix Specification (version 3), all of the
345  * options below are defined, and have a value of either -1 (not supported)
346  * or 200112L (supported).
347  *
348  * These options can neither be left undefined nor have a value of 0, because
349  * either indicates that sysconf(), which is not implemented, may be used at
350  * runtime to check the status of the option.
351  *
352  * _POSIX_THREADS (== 200112L)
353  *                      If == 200112L, you can use threads
354  *
355  * _POSIX_THREAD_ATTR_STACKSIZE (== 200112L)
356  *                      If == 200112L, you can control the size of a thread's
357  *                      stack
358  *                              pthread_attr_getstacksize
359  *                              pthread_attr_setstacksize
360  *
361  * _POSIX_THREAD_ATTR_STACKADDR (== -1)
362  *                      If == 200112L, you can allocate and control a thread's
363  *                      stack. If not supported, the following functions
364  *                      will return ENOSYS, indicating they are not
365  *                      supported:
366  *                              pthread_attr_getstackaddr
367  *                              pthread_attr_setstackaddr
368  *
369  * _POSIX_THREAD_PRIORITY_SCHEDULING (== -1)
370  *                      If == 200112L, you can use realtime scheduling.
371  *                      This option indicates that the behaviour of some
372  *                      implemented functions conforms to the additional TPS
373  *                      requirements in the standard. E.g. rwlocks favour
374  *                      writers over readers when threads have equal priority.
375  *
376  * _POSIX_THREAD_PRIO_INHERIT (== -1)
377  *                      If == 200112L, you can create priority inheritance
378  *                      mutexes.
379  *                              pthread_mutexattr_getprotocol +
380  *                              pthread_mutexattr_setprotocol +
381  *
382  * _POSIX_THREAD_PRIO_PROTECT (== -1)
383  *                      If == 200112L, you can create priority ceiling mutexes
384  *                      Indicates the availability of:
385  *                              pthread_mutex_getprioceiling
386  *                              pthread_mutex_setprioceiling
387  *                              pthread_mutexattr_getprioceiling
388  *                              pthread_mutexattr_getprotocol     +
389  *                              pthread_mutexattr_setprioceiling
390  *                              pthread_mutexattr_setprotocol     +
391  *
392  * _POSIX_THREAD_PROCESS_SHARED (== -1)
393  *                      If set, you can create mutexes and condition
394  *                      variables that can be shared with another
395  *                      process.If set, indicates the availability
396  *                      of:
397  *                              pthread_mutexattr_getpshared
398  *                              pthread_mutexattr_setpshared
399  *                              pthread_condattr_getpshared
400  *                              pthread_condattr_setpshared
401  *
402  * _POSIX_THREAD_SAFE_FUNCTIONS (== 200112L)
403  *                      If == 200112L you can use the special *_r library
404  *                      functions that provide thread-safe behaviour
405  *
406  * _POSIX_READER_WRITER_LOCKS (== 200112L)
407  *                      If == 200112L, you can use read/write locks
408  *
409  * _POSIX_SPIN_LOCKS (== 200112L)
410  *                      If == 200112L, you can use spin locks
411  *
412  * _POSIX_BARRIERS (== 200112L)
413  *                      If == 200112L, you can use barriers
414  *
415  *      + These functions provide both 'inherit' and/or
416  *        'protect' protocol, based upon these macro
417  *        settings.
418  *
419  * -------------------------------------------------------------
420  */
421
422 /*
423  * POSIX Options
424  */
425 #undef _POSIX_THREADS
426 #define _POSIX_THREADS 200112L
427
428 #undef _POSIX_READER_WRITER_LOCKS
429 #define _POSIX_READER_WRITER_LOCKS 200112L
430
431 #undef _POSIX_SPIN_LOCKS
432 #define _POSIX_SPIN_LOCKS 200112L
433
434 #undef _POSIX_BARRIERS
435 #define _POSIX_BARRIERS 200112L
436
437 #undef _POSIX_THREAD_SAFE_FUNCTIONS
438 #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
439
440 #undef _POSIX_THREAD_ATTR_STACKSIZE
441 #define _POSIX_THREAD_ATTR_STACKSIZE 200112L
442
443 /*
444  * The following options are not supported
445  */
446 #undef _POSIX_THREAD_ATTR_STACKADDR
447 #define _POSIX_THREAD_ATTR_STACKADDR -1
448
449 #undef _POSIX_THREAD_PRIO_INHERIT
450 #define _POSIX_THREAD_PRIO_INHERIT -1
451
452 #undef _POSIX_THREAD_PRIO_PROTECT
453 #define _POSIX_THREAD_PRIO_PROTECT -1
454
455 /* TPS is not fully supported.  */
456 #undef _POSIX_THREAD_PRIORITY_SCHEDULING
457 #define _POSIX_THREAD_PRIORITY_SCHEDULING -1
458
459 #undef _POSIX_THREAD_PROCESS_SHARED
460 #define _POSIX_THREAD_PROCESS_SHARED -1
461
462
463 /*
464  * POSIX 1003.1-2001 Limits
465  * ===========================
466  *
467  * These limits are normally set in <limits.h>, which is not provided with
468  * pthreads-win32.
469  *
470  * PTHREAD_DESTRUCTOR_ITERATIONS
471  *                      Maximum number of attempts to destroy
472  *                      a thread's thread-specific data on
473  *                      termination (must be at least 4)
474  *
475  * PTHREAD_KEYS_MAX
476  *                      Maximum number of thread-specific data keys
477  *                      available per process (must be at least 128)
478  *
479  * PTHREAD_STACK_MIN
480  *                      Minimum supported stack size for a thread
481  *
482  * PTHREAD_THREADS_MAX
483  *                      Maximum number of threads supported per
484  *                      process (must be at least 64).
485  *
486  * SEM_NSEMS_MAX
487  *                      The maximum number of semaphores a process can have.
488  *                      (must be at least 256)
489  *
490  * SEM_VALUE_MAX
491  *                      The maximum value a semaphore can have.
492  *                      (must be at least 32767)
493  *
494  */
495 #undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
496 #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS     4
497
498 #undef PTHREAD_DESTRUCTOR_ITERATIONS
499 #define PTHREAD_DESTRUCTOR_ITERATIONS           _POSIX_THREAD_DESTRUCTOR_ITERATIONS
500
501 #undef _POSIX_THREAD_KEYS_MAX
502 #define _POSIX_THREAD_KEYS_MAX                  128
503
504 #undef PTHREAD_KEYS_MAX
505 #define PTHREAD_KEYS_MAX                        _POSIX_THREAD_KEYS_MAX
506
507 #undef PTHREAD_STACK_MIN
508 #define PTHREAD_STACK_MIN                       0
509
510 #undef _POSIX_THREAD_THREADS_MAX
511 #define _POSIX_THREAD_THREADS_MAX               64
512
513   /* Arbitrary value */
514 #undef PTHREAD_THREADS_MAX
515 #define PTHREAD_THREADS_MAX                     2019
516
517 #undef _POSIX_SEM_NSEMS_MAX
518 #define _POSIX_SEM_NSEMS_MAX                    256
519
520   /* Arbitrary value */
521 #undef SEM_NSEMS_MAX
522 #define SEM_NSEMS_MAX                           1024
523
524 #undef _POSIX_SEM_VALUE_MAX
525 #define _POSIX_SEM_VALUE_MAX                    32767
526
527 #undef SEM_VALUE_MAX
528 #define SEM_VALUE_MAX                           INT_MAX
529
530
531 #if __GNUC__ && ! defined (__declspec)
532 # error Please upgrade your GNU compiler to one that supports __declspec.
533 #endif
534
535 /*
536  * When building the DLL code, you should define PTW32_BUILD so that
537  * the variables/functions are exported correctly. When using the DLL,
538  * do NOT define PTW32_BUILD, and then the variables/functions will
539  * be imported correctly.
540  */
541 #ifndef PTW32_STATIC_LIB
542 #  ifdef PTW32_BUILD
543 #    define PTW32_DLLPORT __declspec (dllexport)
544 #  else
545 #    define PTW32_DLLPORT __declspec (dllimport)
546 #  endif
547 #else
548 #  define PTW32_DLLPORT
549 #endif
550
551 /*
552  * The Open Watcom C/C++ compiler uses a non-standard calling convention
553  * that passes function args in registers unless __cdecl is explicitly specified
554  * in exposed function prototypes.
555  *
556  * We force all calls to cdecl even though this could slow Watcom code down
557  * slightly. If you know that the Watcom compiler will be used to build both
558  * the DLL and application, then you can probably define this as a null string.
559  * Remember that pthread.h (this file) is used for both the DLL and application builds.
560  */
561 #define PTW32_CDECL __cdecl
562
563 #if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX
564 #   include     <sys/types.h>
565 #else
566 /*
567  * Generic handle type - intended to extend uniqueness beyond
568  * that available with a simple pointer. It should scale for either
569  * IA-32 or IA-64.
570  */
571 typedef struct {
572     void * p;                   /* Pointer to actual object */
573     unsigned int x;             /* Extra information - reuse count etc */
574 } ptw32_handle_t;
575
576 typedef ptw32_handle_t pthread_t;
577 typedef struct pthread_attr_t_ * pthread_attr_t;
578 typedef struct pthread_once_t_ pthread_once_t;
579 typedef struct pthread_key_t_ * pthread_key_t;
580 typedef struct pthread_mutex_t_ * pthread_mutex_t;
581 typedef struct pthread_mutexattr_t_ * pthread_mutexattr_t;
582 typedef struct pthread_cond_t_ * pthread_cond_t;
583 typedef struct pthread_condattr_t_ * pthread_condattr_t;
584 #endif
585 typedef struct pthread_rwlock_t_ * pthread_rwlock_t;
586 typedef struct pthread_rwlockattr_t_ * pthread_rwlockattr_t;
587 typedef struct pthread_spinlock_t_ * pthread_spinlock_t;
588 typedef struct pthread_barrier_t_ * pthread_barrier_t;
589 typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t;
590
591 /*
592  * ====================
593  * ====================
594  * POSIX Threads
595  * ====================
596  * ====================
597  */
598
599 enum {
600 /*
601  * pthread_attr_{get,set}detachstate
602  */
603   PTHREAD_CREATE_JOINABLE       = 0,  /* Default */
604   PTHREAD_CREATE_DETACHED       = 1,
605
606 /*
607  * pthread_attr_{get,set}inheritsched
608  */
609   PTHREAD_INHERIT_SCHED         = 0,
610   PTHREAD_EXPLICIT_SCHED        = 1,  /* Default */
611
612 /*
613  * pthread_{get,set}scope
614  */
615   PTHREAD_SCOPE_PROCESS         = 0,
616   PTHREAD_SCOPE_SYSTEM          = 1,  /* Default */
617
618 /*
619  * pthread_setcancelstate paramters
620  */
621   PTHREAD_CANCEL_ENABLE         = 0,  /* Default */
622   PTHREAD_CANCEL_DISABLE        = 1,
623
624 /*
625  * pthread_setcanceltype parameters
626  */
627   PTHREAD_CANCEL_ASYNCHRONOUS   = 0,
628   PTHREAD_CANCEL_DEFERRED       = 1,  /* Default */
629
630 /*
631  * pthread_mutexattr_{get,set}pshared
632  * pthread_condattr_{get,set}pshared
633  */
634   PTHREAD_PROCESS_PRIVATE       = 0,
635   PTHREAD_PROCESS_SHARED        = 1,
636
637 /*
638  * pthread_barrier_wait
639  */
640   PTHREAD_BARRIER_SERIAL_THREAD = -1
641 };
642
643 /*
644  * ====================
645  * ====================
646  * Cancelation
647  * ====================
648  * ====================
649  */
650 #define PTHREAD_CANCELED       ((void *) -1)
651
652
653 /*
654  * ====================
655  * ====================
656  * Once Key
657  * ====================
658  * ====================
659  */
660 #define PTHREAD_ONCE_INIT       { PTW32_FALSE, 0, 0, 0}
661
662 struct pthread_once_t_
663 {
664   int          done;        /* indicates if user function has been executed */
665   void *       lock;
666   int          reserved1;
667   int          reserved2;
668 };
669
670
671 /*
672  * ====================
673  * ====================
674  * Object initialisers
675  * ====================
676  * ====================
677  */
678 #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
679 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2)
680 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3)
681
682 /*
683  * Compatibility with LinuxThreads
684  */
685 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
686 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER
687
688 #define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
689
690 #define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1)
691
692 #define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t) -1)
693
694
695 /*
696  * Mutex types.
697  */
698 enum
699 {
700   /* Compatibility with LinuxThreads */
701   PTHREAD_MUTEX_FAST_NP,
702   PTHREAD_MUTEX_RECURSIVE_NP,
703   PTHREAD_MUTEX_ERRORCHECK_NP,
704   PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP,
705   PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP,
706   /* For compatibility with POSIX */
707   PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP,
708   PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
709   PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
710   PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
711 };
712
713
714 typedef struct ptw32_cleanup_t ptw32_cleanup_t;
715
716 #if defined(_MSC_VER)
717 /* Disable MSVC 'anachronism used' warning */
718 #pragma warning( disable : 4229 )
719 #endif
720
721 typedef void (* PTW32_CDECL ptw32_cleanup_callback_t)(void *);
722
723 #if defined(_MSC_VER)
724 #pragma warning( default : 4229 )
725 #endif
726
727 struct ptw32_cleanup_t
728 {
729   ptw32_cleanup_callback_t routine;
730   void *arg;
731   struct ptw32_cleanup_t *prev;
732 };
733
734 #ifdef __CLEANUP_SEH
735         /*
736          * WIN32 SEH version of cancel cleanup.
737          */
738
739 #define pthread_cleanup_push( _rout, _arg ) \
740         { \
741             ptw32_cleanup_t     _cleanup; \
742             \
743         _cleanup.routine        = (ptw32_cleanup_callback_t)(_rout); \
744             _cleanup.arg        = (_arg); \
745             __try \
746               { \
747
748 #define pthread_cleanup_pop( _execute ) \
749               } \
750             __finally \
751                 { \
752                     if( _execute || AbnormalTermination()) \
753                       { \
754                           (*(_cleanup.routine))( _cleanup.arg ); \
755                       } \
756                 } \
757         }
758
759 #else /* __CLEANUP_SEH */
760
761 #ifdef __CLEANUP_C
762
763         /*
764          * C implementation of PThreads cancel cleanup
765          */
766
767 #define pthread_cleanup_push( _rout, _arg ) \
768         { \
769             ptw32_cleanup_t     _cleanup; \
770             \
771             ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \
772
773 #define pthread_cleanup_pop( _execute ) \
774             (void) ptw32_pop_cleanup( _execute ); \
775         }
776
777 #else /* __CLEANUP_C */
778
779 #ifdef __CLEANUP_CXX
780
781         /*
782          * C++ version of cancel cleanup.
783          * - John E. Bossom.
784          */
785
786         class PThreadCleanup {
787           /*
788            * PThreadCleanup
789            *
790            * Purpose
791            *      This class is a C++ helper class that is
792            *      used to implement pthread_cleanup_push/
793            *      pthread_cleanup_pop.
794            *      The destructor of this class automatically
795            *      pops the pushed cleanup routine regardless
796            *      of how the code exits the scope
797            *      (i.e. such as by an exception)
798            */
799       ptw32_cleanup_callback_t cleanUpRout;
800           void    *       obj;
801           int             executeIt;
802
803         public:
804           PThreadCleanup() :
805             cleanUpRout( 0 ),
806             obj( 0 ),
807             executeIt( 0 )
808             /*
809              * No cleanup performed
810              */
811             {
812             }
813
814           PThreadCleanup(
815              ptw32_cleanup_callback_t routine,
816                          void    *       arg ) :
817             cleanUpRout( routine ),
818             obj( arg ),
819             executeIt( 1 )
820             /*
821              * Registers a cleanup routine for 'arg'
822              */
823             {
824             }
825
826           ~PThreadCleanup()
827             {
828               if ( executeIt && ((void *) cleanUpRout != (void *) 0) )
829                 {
830                   (void) (*cleanUpRout)( obj );
831                 }
832             }
833
834           void execute( int exec )
835             {
836               executeIt = exec;
837             }
838         };
839
840         /*
841          * C++ implementation of PThreads cancel cleanup;
842          * This implementation takes advantage of a helper
843          * class who's destructor automatically calls the
844          * cleanup routine if we exit our scope weirdly
845          */
846 #define pthread_cleanup_push( _rout, _arg ) \
847         { \
848             PThreadCleanup  cleanup((ptw32_cleanup_callback_t)(_rout), \
849                                     (void *) (_arg) );
850
851 #define pthread_cleanup_pop( _execute ) \
852             cleanup.execute( _execute ); \
853         }
854
855 #else
856
857 #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
858
859 #endif /* __CLEANUP_CXX */
860
861 #endif /* __CLEANUP_C */
862
863 #endif /* __CLEANUP_SEH */
864
865 /*
866  * ===============
867  * ===============
868  * Methods
869  * ===============
870  * ===============
871  */
872
873 /*
874  * PThread Attribute Functions
875  */
876 PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr);
877
878 PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr);
879
880 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr,
881                                          int *detachstate);
882
883 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr,
884                                        void **stackaddr);
885
886 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr,
887                                        size_t * stacksize);
888
889 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr,
890                                          int detachstate);
891
892 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr,
893                                        void *stackaddr);
894
895 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr,
896                                        size_t stacksize);
897
898 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr,
899                                         struct sched_param *param);
900
901 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr,
902                                         const struct sched_param *param);
903
904 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *,
905                                          int);
906
907 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (pthread_attr_t *,
908                                          int *);
909
910 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr,
911                                          int inheritsched);
912
913 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(pthread_attr_t * attr,
914                                          int * inheritsched);
915
916 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *,
917                                    int);
918
919 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *,
920                                    int *);
921
922 /*
923  * PThread Functions
924  */
925 PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid,
926                             const pthread_attr_t * attr,
927                             void *(*start) (void *),
928                             void *arg);
929
930 PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid);
931
932 PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1,
933                            pthread_t t2);
934
935 PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr);
936
937 PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread,
938                           void **value_ptr);
939
940 PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void);
941
942 PTW32_DLLPORT int PTW32_CDECL pthread_cancel (pthread_t thread);
943
944 PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state,
945                                     int *oldstate);
946
947 PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type,
948                                    int *oldtype);
949
950 PTW32_DLLPORT void PTW32_CDECL pthread_testcancel (void);
951
952 PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control,
953                           void (*init_routine) (void));
954
955 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
956 PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute);
957
958 PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup,
959                                  void (*routine) (void *),
960                                  void *arg);
961 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
962
963 /*
964  * Thread Specific Data Functions
965  */
966 PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key,
967                                 void (*destructor) (void *));
968
969 PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key);
970
971 PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key,
972                                  const void *value);
973
974 PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key);
975
976
977 /*
978  * Mutex Attribute Functions
979  */
980 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr);
981
982 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr);
983
984 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t
985                                           * attr,
986                                           int *pshared);
987
988 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr,
989                                           int pshared);
990
991 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind);
992 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *kind);
993
994 /*
995  * Barrier Attribute Functions
996  */
997 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr);
998
999 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr);
1000
1001 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t
1002                                             * attr,
1003                                             int *pshared);
1004
1005 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
1006                                             int pshared);
1007
1008 /*
1009  * Mutex Functions
1010  */
1011 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex,
1012                                 const pthread_mutexattr_t * attr);
1013
1014 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex);
1015
1016 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock (pthread_mutex_t * mutex);
1017
1018 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t *mutex,
1019                                     const struct timespec *abstime);
1020
1021 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock (pthread_mutex_t * mutex);
1022
1023 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock (pthread_mutex_t * mutex);
1024
1025 /*
1026  * Spinlock Functions
1027  */
1028 PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared);
1029
1030 PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock);
1031
1032 PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock);
1033
1034 PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock);
1035
1036 PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock);
1037
1038 /*
1039  * Barrier Functions
1040  */
1041 PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier,
1042                                   const pthread_barrierattr_t * attr,
1043                                   unsigned int count);
1044
1045 PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier);
1046
1047 PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier);
1048
1049 /*
1050  * Condition Variable Attribute Functions
1051  */
1052 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr);
1053
1054 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr);
1055
1056 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr,
1057                                          int *pshared);
1058
1059 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr,
1060                                          int pshared);
1061
1062 /*
1063  * Condition Variable Functions
1064  */
1065 PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond,
1066                                const pthread_condattr_t * attr);
1067
1068 PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond);
1069
1070 PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond,
1071                                pthread_mutex_t * mutex);
1072
1073 PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond,
1074                                     pthread_mutex_t * mutex,
1075                                     const struct timespec *abstime);
1076
1077 PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond);
1078
1079 PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond);
1080
1081 /*
1082  * Scheduling
1083  */
1084 PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread,
1085                                    int policy,
1086                                    const struct sched_param *param);
1087
1088 PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread,
1089                                    int *policy,
1090                                    struct sched_param *param);
1091
1092 PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int);
1093  
1094 PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void);
1095
1096 /*
1097  * Read-Write Lock Functions
1098  */
1099 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock,
1100                                 const pthread_rwlockattr_t *attr);
1101
1102 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock);
1103
1104 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *);
1105
1106 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *);
1107
1108 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock);
1109
1110 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock,
1111                                        const struct timespec *abstime);
1112
1113 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock);
1114
1115 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock,
1116                                        const struct timespec *abstime);
1117
1118 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock);
1119
1120 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr);
1121
1122 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr);
1123
1124 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr,
1125                                            int *pshared);
1126
1127 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
1128                                            int pshared);
1129
1130 #if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1
1131
1132 /*
1133  * Signal Functions. Should be defined in <signal.h> but MSVC and MinGW32
1134  * already have signal.h that don't define these.
1135  */
1136 PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig);
1137
1138 /*
1139  * Non-portable functions
1140  */
1141
1142 /*
1143  * Compatibility with Linux.
1144  */
1145 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr,
1146                                          int kind);
1147 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr,
1148                                          int *kind);
1149
1150 /*
1151  * Possibly supported by other POSIX threads implementations
1152  */
1153 PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval);
1154 PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void);
1155
1156 /*
1157  * Useful if an application wants to statically link
1158  * the lib rather than load the DLL at run-time.
1159  */
1160 PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void);
1161 PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void);
1162 PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void);
1163 PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void);
1164
1165 /*
1166  * Features that are auto-detected at load/run time.
1167  */
1168 PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int);
1169 enum ptw32_features {
1170   PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */
1171   PTW32_ALERTABLE_ASYNC_CANCEL              = 0x0002  /* Can cancel blocked threads. */
1172 };
1173
1174 /*
1175  * Register a system time change with the library.
1176  * Causes the library to perform various functions
1177  * in response to the change. Should be called whenever
1178  * the application's top level window receives a
1179  * WM_TIMECHANGE message. It can be passed directly to
1180  * pthread_create() as a new thread if desired.
1181  */
1182 PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *);
1183
1184 #endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */
1185
1186 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
1187
1188 /*
1189  * Returns the Win32 HANDLE for the POSIX thread.
1190  */
1191 PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread);
1192
1193
1194 /*
1195  * Protected Methods
1196  *
1197  * This function blocks until the given WIN32 handle
1198  * is signaled or pthread_cancel had been called.
1199  * This function allows the caller to hook into the
1200  * PThreads cancel mechanism. It is implemented using
1201  *
1202  *              WaitForMultipleObjects
1203  *
1204  * on 'waitHandle' and a manually reset WIN32 Event
1205  * used to implement pthread_cancel. The 'timeout'
1206  * argument to TimedWait is simply passed to
1207  * WaitForMultipleObjects.
1208  */
1209 PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle);
1210 PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle,
1211                                         DWORD timeout);
1212
1213 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
1214
1215 /*
1216  * Thread-Safe C Runtime Library Mappings.
1217  */
1218 #ifndef _UWIN
1219 #  if defined(NEED_ERRNO)
1220      PTW32_DLLPORT int * PTW32_CDECL _errno( void );
1221 #  else
1222 #    ifndef errno
1223 #      if (defined(_MT) || defined(_DLL))
1224          __declspec(dllimport) extern int * __cdecl _errno(void);
1225 #        define errno   (*_errno())
1226 #      endif
1227 #    endif
1228 #  endif
1229 #endif
1230
1231 /*
1232  * WIN32 C runtime library had been made thread-safe
1233  * without affecting the user interface. Provide
1234  * mappings from the UNIX thread-safe versions to
1235  * the standard C runtime library calls.
1236  * Only provide function mappings for functions that
1237  * actually exist on WIN32.
1238  */
1239
1240 #if !defined(__MINGW32__)
1241 #define strtok_r( _s, _sep, _lasts ) \
1242         ( *(_lasts) = strtok( (_s), (_sep) ) )
1243 #endif /* !__MINGW32__ */
1244
1245 #define asctime_r( _tm, _buf ) \
1246         ( strcpy( (_buf), asctime( (_tm) ) ), \
1247           (_buf) )
1248
1249 #define ctime_r( _clock, _buf ) \
1250         ( strcpy( (_buf), ctime( (_clock) ) ),  \
1251           (_buf) )
1252
1253 #define gmtime_r( _clock, _result ) \
1254         ( *(_result) = *gmtime( (_clock) ), \
1255           (_result) )
1256
1257 #define localtime_r( _clock, _result ) \
1258         ( *(_result) = *localtime( (_clock) ), \
1259           (_result) )
1260
1261 #define rand_r( _seed ) \
1262         ( _seed == _seed? rand() : rand() )
1263
1264
1265 /*
1266  * Some compiler environments don't define some things.
1267  */
1268 #if defined(__BORLANDC__)
1269 #  define _ftime ftime
1270 #  define _timeb timeb
1271 #endif
1272
1273 #ifdef __cplusplus
1274
1275 /*
1276  * Internal exceptions
1277  */
1278 class ptw32_exception {};
1279 class ptw32_exception_cancel : public ptw32_exception {};
1280 class ptw32_exception_exit   : public ptw32_exception {};
1281
1282 #endif
1283
1284 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
1285
1286 /* FIXME: This is only required if the library was built using SEH */
1287 /*
1288  * Get internal SEH tag
1289  */
1290 PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);
1291
1292 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
1293
1294 #ifndef PTW32_BUILD
1295
1296 #ifdef __CLEANUP_SEH
1297
1298 /*
1299  * Redefine the SEH __except keyword to ensure that applications
1300  * propagate our internal exceptions up to the library's internal handlers.
1301  */
1302 #define __except( E ) \
1303         __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \
1304                  ? EXCEPTION_CONTINUE_SEARCH : ( E ) )
1305
1306 #endif /* __CLEANUP_SEH */
1307
1308 #ifdef __CLEANUP_CXX
1309
1310 /*
1311  * Redefine the C++ catch keyword to ensure that applications
1312  * propagate our internal exceptions up to the library's internal handlers.
1313  */
1314 #ifdef _MSC_VER
1315         /*
1316          * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll'
1317          * if you want Pthread-Win32 cancelation and pthread_exit to work.
1318          */
1319
1320 #ifndef PtW32NoCatchWarn
1321
1322 #pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.")
1323 #pragma message("------------------------------------------------------------------")
1324 #pragma message("When compiling applications with MSVC++ and C++ exception handling:")
1325 #pragma message("  Replace any 'catch( ... )' in routines called from POSIX threads")
1326 #pragma message("  with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread")
1327 #pragma message("  cancelation and pthread_exit to work. For example:")
1328 #pragma message("")
1329 #pragma message("    #ifdef PtW32CatchAll")
1330 #pragma message("      PtW32CatchAll")
1331 #pragma message("    #else")
1332 #pragma message("      catch(...)")
1333 #pragma message("    #endif")
1334 #pragma message("        {")
1335 #pragma message("          /* Catchall block processing */")
1336 #pragma message("        }")
1337 #pragma message("------------------------------------------------------------------")
1338
1339 #endif
1340
1341 #define PtW32CatchAll \
1342         catch( ptw32_exception & ) { throw; } \
1343         catch( ... )
1344
1345 #else /* _MSC_VER */
1346
1347 #define catch( E ) \
1348         catch( ptw32_exception & ) { throw; } \
1349         catch( E )
1350
1351 #endif /* _MSC_VER */
1352
1353 #endif /* __CLEANUP_CXX */
1354
1355 #endif /* ! PTW32_BUILD */
1356
1357 #ifdef __cplusplus
1358 }                               /* End of extern "C" */
1359 #endif                          /* __cplusplus */
1360
1361 #ifdef PTW32__HANDLE_DEF
1362 # undef HANDLE
1363 #endif
1364 #ifdef PTW32__DWORD_DEF
1365 # undef DWORD
1366 #endif
1367
1368 #undef PTW32_LEVEL
1369 #undef PTW32_LEVEL_MAX
1370
1371 #endif /* ! RC_INVOKED */
1372
1373 #endif /* PTHREAD_H */