/[pcsx2_0.9.7]/trunk/3rdparty/w32pthreads/include/pthread.h
ViewVC logotype

Contents of /trunk/3rdparty/w32pthreads/include/pthread.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 1 month ago) by william
File MIME type: text/plain
File size: 43044 byte(s)
re-commit (had local access denied errors when committing)
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 #define PTHREAD_H
35
36 /*
37 * See the README file for an explanation of the pthreads-win32 version
38 * numbering scheme and how the DLL is named etc.
39 */
40 #define PTW32_VERSION 2,8,0,4
41 #define PTW32_VERSION_STRING "2, 8, 0, 4\0"
42
43 #define PTW32_ALLOW_COND
44
45 /* There are three implementations of cancel cleanup.
46 * Note that pthread.h is included in both application
47 * compilation units and also internally for the library.
48 * The code here and within the library aims to work
49 * for all reasonable combinations of environments.
50 *
51 * The three implementations are:
52 *
53 * WIN32 SEH
54 * C
55 * C++
56 *
57 * Please note that exiting a push/pop block via
58 * "return", "exit", "break", or "continue" will
59 * lead to different behaviour amongst applications
60 * depending upon whether the library was built
61 * using SEH, C++, or C. For example, a library built
62 * with SEH will call the cleanup routine, while both
63 * C++ and C built versions will not.
64 */
65
66 /*
67 * Define defaults for cleanup code.
68 * Note: Unless the build explicitly defines one of the following, then
69 * we default to standard C style cleanup. This style uses setjmp/longjmp
70 * in the cancellation and thread exit implementations and therefore won't
71 * do stack unwinding if linked to applications that have it (e.g.
72 * C++ apps). This is currently consistent with most/all commercial Unix
73 * POSIX threads implementations.
74 */
75 #if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C )
76 # define __CLEANUP_C
77 #endif
78
79 #if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC))
80 #error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler.
81 #endif
82
83 /*
84 * Stop here if we are being included by the resource compiler.
85 */
86 #ifndef RC_INVOKED
87
88 #undef PTW32_LEVEL
89
90 #if defined(_POSIX_SOURCE)
91 #define PTW32_LEVEL 0
92 /* Early POSIX */
93 #endif
94
95 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
96 #undef PTW32_LEVEL
97 #define PTW32_LEVEL 1
98 /* Include 1b, 1c and 1d */
99 #endif
100
101 #if defined(INCLUDE_NP)
102 #undef PTW32_LEVEL
103 #define PTW32_LEVEL 2
104 /* Include Non-Portable extensions */
105 #endif
106
107 #define PTW32_LEVEL_MAX 3
108
109 #if !defined(PTW32_LEVEL)
110 #define PTW32_LEVEL PTW32_LEVEL_MAX
111 /* Include everything */
112 #endif
113
114 #ifdef _UWIN
115 # define HAVE_STRUCT_TIMESPEC 1
116 # define HAVE_SIGNAL_H 1
117 # undef HAVE_CONFIG_H
118 # pragma comment(lib, "pthread")
119 #endif
120
121 /*
122 * -------------------------------------------------------------
123 *
124 *
125 * Module: pthread.h
126 *
127 * Purpose:
128 * Provides an implementation of PThreads based upon the
129 * standard:
130 *
131 * POSIX 1003.1-2001
132 * and
133 * The Single Unix Specification version 3
134 *
135 * (these two are equivalent)
136 *
137 * in order to enhance code portability between Windows,
138 * various commercial Unix implementations, and Linux.
139 *
140 * See the ANNOUNCE file for a full list of conforming
141 * routines and defined constants, and a list of missing
142 * routines and constants not defined in this implementation.
143 *
144 * Authors:
145 * There have been many contributors to this library.
146 * The initial implementation was contributed by
147 * John Bossom, and several others have provided major
148 * sections or revisions of parts of the implementation.
149 * Often significant effort has been contributed to
150 * find and fix important bugs and other problems to
151 * improve the reliability of the library, which sometimes
152 * is not reflected in the amount of code which changed as
153 * result.
154 * As much as possible, the contributors are acknowledged
155 * in the ChangeLog file in the source code distribution
156 * where their changes are noted in detail.
157 *
158 * Contributors are listed in the CONTRIBUTORS file.
159 *
160 * As usual, all bouquets go to the contributors, and all
161 * brickbats go to the project maintainer.
162 *
163 * Maintainer:
164 * The code base for this project is coordinated and
165 * eventually pre-tested, packaged, and made available by
166 *
167 * Ross Johnson <rpj@callisto.canberra.edu.au>
168 *
169 * QA Testers:
170 * Ultimately, the library is tested in the real world by
171 * a host of competent and demanding scientists and
172 * engineers who report bugs and/or provide solutions
173 * which are then fixed or incorporated into subsequent
174 * versions of the library. Each time a bug is fixed, a
175 * test case is written to prove the fix and ensure
176 * that later changes to the code don't reintroduce the
177 * same error. The number of test cases is slowly growing
178 * and therefore so is the code reliability.
179 *
180 * Compliance:
181 * See the file ANNOUNCE for the list of implemented
182 * and not-implemented routines and defined options.
183 * Of course, these are all defined is this file as well.
184 *
185 * Web site:
186 * The source code and other information about this library
187 * are available from
188 *
189 * http://sources.redhat.com/pthreads-win32/
190 *
191 * -------------------------------------------------------------
192 */
193
194 /* Try to avoid including windows.h */
195 #if defined(__MINGW32__) && defined(__cplusplus)
196 #define PTW32_INCLUDE_WINDOWS_H
197 #endif
198
199 #ifdef PTW32_INCLUDE_WINDOWS_H
200 #include <windows.h>
201 #endif
202
203 #if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__)
204 /*
205 * VC++6.0 or early compiler's header has no DWORD_PTR type.
206 */
207 typedef unsigned long DWORD_PTR;
208 #endif
209 /*
210 * -----------------
211 * autoconf switches
212 * -----------------
213 */
214
215 #if HAVE_CONFIG_H
216 #include "config.h"
217 #endif /* HAVE_CONFIG_H */
218
219 #ifndef NEED_FTIME
220 #include <time.h>
221 #else /* NEED_FTIME */
222 /* use native WIN32 time API */
223 #endif /* NEED_FTIME */
224
225 #if HAVE_SIGNAL_H
226 #include <signal.h>
227 #endif /* HAVE_SIGNAL_H */
228
229 #ifdef __CLEANUP_C
230 #include <setjmp.h>
231 #endif
232 #include <limits.h>
233
234 /*
235 * Boolean values to make us independent of system includes.
236 */
237 enum {
238 PTW32_FALSE = 0,
239 PTW32_TRUE = (! PTW32_FALSE)
240 };
241
242 /*
243 * This is a duplicate of what is in the autoconf config.h,
244 * which is only used when building the pthread-win32 libraries.
245 */
246
247 #ifndef PTW32_CONFIG_H
248 # if defined(WINCE)
249 # define NEED_ERRNO
250 # define NEED_SEM
251 # endif
252 # if defined(_UWIN) || defined(__MINGW32__)
253 # define HAVE_MODE_T
254 # endif
255 #endif
256
257 /*
258 *
259 */
260
261 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
262 #ifdef NEED_ERRNO
263 #include "need_errno.h"
264 #else
265 #include <errno.h>
266 #endif
267 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
268
269 /*
270 * Several systems don't define some error numbers.
271 */
272 #ifndef ENOTSUP
273 # define ENOTSUP 48 /* This is the value in Solaris. */
274 #endif
275
276 #ifndef ETIMEDOUT
277 # define ETIMEDOUT 10060 /* This is the value in winsock.h. */
278 #endif
279
280 #ifndef ENOSYS
281 # define ENOSYS 140 /* Semi-arbitrary value */
282 #endif
283
284 #ifndef EDEADLK
285 # ifdef EDEADLOCK
286 # define EDEADLK EDEADLOCK
287 # else
288 # define EDEADLK 36 /* This is the value in MSVC. */
289 # endif
290 #endif
291
292 #include <sched.h>
293
294 /*
295 * To avoid including windows.h we define only those things that we
296 * actually need from it.
297 */
298 #ifndef PTW32_INCLUDE_WINDOWS_H
299 #ifndef HANDLE
300 # define PTW32__HANDLE_DEF
301 # define HANDLE void *
302 #endif
303 #ifndef DWORD
304 # define PTW32__DWORD_DEF
305 # define DWORD unsigned long
306 #endif
307 #endif
308
309 #if !defined( HAVE_STRUCT_TIMESPEC ) && !defined( _TIMESPEC_DEFINED )
310 #define HAVE_STRUCT_TIMESPEC 1
311 #define _TIMESPEC_DEFINED 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 _ptw32_handle_t {
572 void * p; /* Pointer to actual object */
573 unsigned int x; /* Extra information - reuse count etc */
574
575 #ifdef __cplusplus
576 // Added support for various operators so that the struct is
577 // more pthreads-compliant in behavior. (air)
578 const bool operator ==( const struct _ptw32_handle_t rightside ) const
579 {
580 return p == rightside.p;
581 }
582
583 const bool operator !=( const struct _ptw32_handle_t rightside ) const
584 {
585 return p != rightside.p;
586 }
587 #endif
588
589 } ptw32_handle_t;
590
591 typedef ptw32_handle_t pthread_t;
592 typedef struct pthread_attr_t_ * pthread_attr_t;
593 typedef struct pthread_once_t_ pthread_once_t;
594 typedef struct pthread_key_t_ * pthread_key_t;
595 typedef struct pthread_mutex_t_ * pthread_mutex_t;
596 typedef struct pthread_mutexattr_t_ * pthread_mutexattr_t;
597 typedef struct pthread_cond_t_ * pthread_cond_t;
598 typedef struct pthread_condattr_t_ * pthread_condattr_t;
599 #endif
600 typedef struct pthread_rwlock_t_ * pthread_rwlock_t;
601 typedef struct pthread_rwlockattr_t_ * pthread_rwlockattr_t;
602 typedef struct pthread_spinlock_t_ * pthread_spinlock_t;
603 typedef struct pthread_barrier_t_ * pthread_barrier_t;
604 typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t;
605
606 /*
607 * ====================
608 * ====================
609 * POSIX Threads
610 * ====================
611 * ====================
612 */
613
614 enum {
615 /*
616 * pthread_attr_{get,set}detachstate
617 */
618 PTHREAD_CREATE_JOINABLE = 0, /* Default */
619 PTHREAD_CREATE_DETACHED = 1,
620
621 /*
622 * pthread_attr_{get,set}inheritsched
623 */
624 PTHREAD_INHERIT_SCHED = 0,
625 PTHREAD_EXPLICIT_SCHED = 1, /* Default */
626
627 /*
628 * pthread_{get,set}scope
629 */
630 PTHREAD_SCOPE_PROCESS = 0,
631 PTHREAD_SCOPE_SYSTEM = 1, /* Default */
632
633 /*
634 * pthread_setcancelstate paramters
635 */
636 PTHREAD_CANCEL_ENABLE = 0, /* Default */
637 PTHREAD_CANCEL_DISABLE = 1,
638
639 /*
640 * pthread_setcanceltype parameters
641 */
642 PTHREAD_CANCEL_ASYNCHRONOUS = 0,
643 PTHREAD_CANCEL_DEFERRED = 1, /* Default */
644
645 /*
646 * pthread_mutexattr_{get,set}pshared
647 * pthread_condattr_{get,set}pshared
648 */
649 PTHREAD_PROCESS_PRIVATE = 0,
650 PTHREAD_PROCESS_SHARED = 1,
651
652 /*
653 * pthread_barrier_wait
654 */
655 PTHREAD_BARRIER_SERIAL_THREAD = -1
656 };
657
658 /*
659 * ====================
660 * ====================
661 * Cancelation
662 * ====================
663 * ====================
664 */
665 #define PTHREAD_CANCELED ((void *) -1)
666
667
668 /*
669 * ====================
670 * ====================
671 * Once Key
672 * ====================
673 * ====================
674 */
675 #define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0}
676
677 struct pthread_once_t_
678 {
679 int done; /* indicates if user function has been executed */
680 void * lock;
681 int reserved1;
682 int reserved2;
683 };
684
685
686 /*
687 * ====================
688 * ====================
689 * Object initialisers
690 * ====================
691 * ====================
692 */
693
694 // Note: Static mutexes are useful in C but a bad idea in C++, and add overhead to all
695 // mutex lockers (bad!), so C++ code should idisable them and use C++ initializers instead.
696
697 #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
698 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2)
699 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3)
700
701 /*
702 * Compatibility with LinuxThreads
703 */
704 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
705 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER
706
707 #define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
708
709 #define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1)
710
711 #define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t) -1)
712
713
714 /*
715 * Mutex types.
716 */
717 enum
718 {
719 /* Compatibility with LinuxThreads */
720 PTHREAD_MUTEX_FAST_NP,
721 PTHREAD_MUTEX_RECURSIVE_NP,
722 PTHREAD_MUTEX_ERRORCHECK_NP,
723 PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP,
724 PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP,
725 /* For compatibility with POSIX */
726 PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP,
727 PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
728 PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
729 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
730 };
731
732
733 typedef struct ptw32_cleanup_t ptw32_cleanup_t;
734
735 #if defined(_MSC_VER)
736 /* Disable MSVC 'anachronism used' warning */
737 #pragma warning( disable : 4229 )
738 #endif
739
740 typedef void (* PTW32_CDECL ptw32_cleanup_callback_t)(void *);
741
742 #if defined(_MSC_VER)
743 #pragma warning( default : 4229 )
744 #endif
745
746 struct ptw32_cleanup_t
747 {
748 ptw32_cleanup_callback_t routine;
749 void *arg;
750 struct ptw32_cleanup_t *prev;
751 };
752
753 #ifdef __CLEANUP_SEH
754 #include <excpt.h> // PCSX2: excpt.h is needed for AbnormalTermination() -- air
755
756 /*
757 * WIN32 SEH version of cancel cleanup.
758 */
759
760 #define pthread_cleanup_push( _rout, _arg ) \
761 { \
762 ptw32_cleanup_t _cleanup; \
763 \
764 _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \
765 _cleanup.arg = (_arg); \
766 __try \
767 { \
768
769 #define pthread_cleanup_pop( _execute ) \
770 } \
771 __finally \
772 { \
773 if( _execute || AbnormalTermination()) \
774 { \
775 (*(_cleanup.routine))( _cleanup.arg ); \
776 } \
777 } \
778 }
779
780 #else /* __CLEANUP_SEH */
781
782 #ifdef __CLEANUP_C
783
784 /*
785 * C implementation of PThreads cancel cleanup
786 */
787
788 #define pthread_cleanup_push( _rout, _arg ) \
789 { \
790 ptw32_cleanup_t _cleanup; \
791 \
792 ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \
793
794 #define pthread_cleanup_pop( _execute ) \
795 (void) ptw32_pop_cleanup( _execute ); \
796 }
797
798 #else /* __CLEANUP_C */
799
800 #ifdef __CLEANUP_CXX
801
802 /*
803 * C++ version of cancel cleanup.
804 * - John E. Bossom.
805 */
806
807 class PThreadCleanup {
808 /*
809 * PThreadCleanup
810 *
811 * Purpose
812 * This class is a C++ helper class that is
813 * used to implement pthread_cleanup_push/
814 * pthread_cleanup_pop.
815 * The destructor of this class automatically
816 * pops the pushed cleanup routine regardless
817 * of how the code exits the scope
818 * (i.e. such as by an exception)
819 */
820 ptw32_cleanup_callback_t cleanUpRout;
821 void * obj;
822 int executeIt;
823
824 public:
825 PThreadCleanup() :
826 cleanUpRout( 0 ),
827 obj( 0 ),
828 executeIt( 0 )
829 /*
830 * No cleanup performed
831 */
832 {
833 }
834
835 PThreadCleanup(
836 ptw32_cleanup_callback_t routine,
837 void * arg ) :
838 cleanUpRout( routine ),
839 obj( arg ),
840 executeIt( 1 )
841 /*
842 * Registers a cleanup routine for 'arg'
843 */
844 {
845 }
846
847 ~PThreadCleanup()
848 {
849 if ( executeIt && ((void *) cleanUpRout != (void *) 0) )
850 {
851 (void) (*cleanUpRout)( obj );
852 }
853 }
854
855 void execute( int exec )
856 {
857 executeIt = exec;
858 }
859 };
860
861 /*
862 * C++ implementation of PThreads cancel cleanup;
863 * This implementation takes advantage of a helper
864 * class who's destructor automatically calls the
865 * cleanup routine if we exit our scope weirdly
866 */
867 #define pthread_cleanup_push( _rout, _arg ) \
868 { \
869 PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \
870 (void *) (_arg) );
871
872 #define pthread_cleanup_pop( _execute ) \
873 cleanup.execute( _execute ); \
874 }
875
876 #else
877
878 #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
879
880 #endif /* __CLEANUP_CXX */
881
882 #endif /* __CLEANUP_C */
883
884 #endif /* __CLEANUP_SEH */
885
886 /*
887 * ===============
888 * ===============
889 * Methods
890 * ===============
891 * ===============
892 */
893
894 /*
895 * PThread Attribute Functions
896 */
897 PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr);
898
899 PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr);
900
901 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr,
902 int *detachstate);
903
904 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr,
905 void **stackaddr);
906
907 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr,
908 size_t * stacksize);
909
910 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr,
911 int detachstate);
912
913 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr,
914 void *stackaddr);
915
916 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr,
917 size_t stacksize);
918
919 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr,
920 struct sched_param *param);
921
922 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr,
923 const struct sched_param *param);
924
925 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *,
926 int);
927
928 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (pthread_attr_t *,
929 int *);
930
931 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr,
932 int inheritsched);
933
934 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(pthread_attr_t * attr,
935 int * inheritsched);
936
937 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *,
938 int);
939
940 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *,
941 int *);
942
943 /*
944 * PThread Functions
945 */
946 PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid,
947 const pthread_attr_t * attr,
948 void *(*start) (void *),
949 void *arg);
950
951 PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid);
952
953 PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1,
954 pthread_t t2);
955
956 PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr);
957
958 PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread,
959 void **value_ptr);
960
961 PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void);
962
963 extern int pthread_cancel (pthread_t thread);
964
965 PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state,
966 int *oldstate);
967
968 PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type,
969 int *oldtype);
970
971 extern void pthread_testcancel (void);
972
973 PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control,
974 void (*init_routine) (void));
975
976 #if PTW32_LEVEL >= PTW32_LEVEL_MAX && defined(__CLEANUP_C)
977 PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute);
978
979 PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup,
980 void (*routine) (void *),
981 void *arg);
982 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
983
984 /*
985 * Thread Specific Data Functions
986 */
987 PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key,
988 void (*destructor) (void *));
989
990 PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key);
991
992 PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key,
993 const void *value);
994
995 PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key);
996
997
998 /*
999 * Mutex Attribute Functions
1000 */
1001 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr);
1002
1003 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr);
1004
1005 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t
1006 * attr,
1007 int *pshared);
1008
1009 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr,
1010 int pshared);
1011
1012 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind);
1013 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *kind);
1014
1015 /*
1016 * Barrier Attribute Functions
1017 */
1018 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr);
1019
1020 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr);
1021
1022 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t
1023 * attr,
1024 int *pshared);
1025
1026 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
1027 int pshared);
1028
1029 /*
1030 * Mutex Functions
1031 */
1032 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex,
1033 const pthread_mutexattr_t * attr);
1034
1035 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex);
1036
1037 extern int pthread_mutex_lock (pthread_mutex_t * mutex);
1038
1039 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t *mutex,
1040 const struct timespec *abstime);
1041
1042 extern int pthread_mutex_trylock (pthread_mutex_t * mutex);
1043
1044 extern int pthread_mutex_unlock (pthread_mutex_t * mutex);
1045
1046 #ifdef PTW32_ALLOW_SPIN
1047 /*
1048 * Spinlock Functions
1049 *
1050 * These are disabled by default; they are not part of the "required" portion of pthreads
1051 * implementations, and they are generally a bad idea for anything except the most controlled
1052 * of threaded environments (which hardly exist in modern computing).
1053 */
1054 PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared);
1055
1056 PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock);
1057
1058 PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock);
1059
1060 PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock);
1061
1062 PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock);
1063 #endif
1064
1065 /*
1066 * Barrier Functions
1067 */
1068 PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier,
1069 const pthread_barrierattr_t * attr,
1070 unsigned int count);
1071
1072 PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier);
1073
1074 PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier);
1075
1076 #ifdef PTW32_ALLOW_COND
1077 /*
1078 * Condition Variable Attribute Functions
1079 */
1080 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr);
1081
1082 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr);
1083
1084 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr,
1085 int *pshared);
1086
1087 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr,
1088 int pshared);
1089
1090 /*
1091 * Condition Variable Functions
1092 */
1093 PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond,
1094 const pthread_condattr_t * attr);
1095
1096 PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond);
1097
1098 PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond,
1099 pthread_mutex_t * mutex);
1100
1101 PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond,
1102 pthread_mutex_t * mutex,
1103 const struct timespec *abstime);
1104
1105 PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond);
1106
1107 PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond);
1108 #endif
1109
1110 /*
1111 * Scheduling
1112 */
1113 PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread,
1114 int policy,
1115 const struct sched_param *param);
1116
1117 PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread,
1118 int *policy,
1119 struct sched_param *param);
1120
1121 PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int);
1122
1123 PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void);
1124
1125 /*
1126 * Read-Write Lock Functions
1127 */
1128 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock,
1129 const pthread_rwlockattr_t *attr);
1130
1131 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock);
1132
1133 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *);
1134
1135 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *);
1136
1137 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock);
1138
1139 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock,
1140 const struct timespec *abstime);
1141
1142 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock);
1143
1144 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock,
1145 const struct timespec *abstime);
1146
1147 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock);
1148
1149 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr);
1150
1151 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr);
1152
1153 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr,
1154 int *pshared);
1155
1156 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
1157 int pshared);
1158
1159 #if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1
1160
1161 /*
1162 * Signal Functions. Should be defined in <signal.h> but MSVC and MinGW32
1163 * already have signal.h that don't define these.
1164 */
1165 PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig);
1166
1167 /*
1168 * Non-portable functions
1169 */
1170
1171 /*
1172 * Compatibility with Linux.
1173 */
1174 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr,
1175 int kind);
1176 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr,
1177 int *kind);
1178
1179 /*
1180 * Possibly supported by other POSIX threads implementations
1181 */
1182 PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval);
1183 PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void);
1184
1185 /*
1186 * Useful if an application wants to statically link
1187 * the lib rather than load the DLL at run-time.
1188 */
1189 PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void);
1190 PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void);
1191 PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void);
1192 PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void);
1193
1194 /*
1195 * Features that are auto-detected at load/run time.
1196 */
1197 PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int);
1198 enum ptw32_features {
1199 PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */
1200 PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002 /* Can cancel blocked threads. */
1201 };
1202
1203 /*
1204 * Register a system time change with the library.
1205 * Causes the library to perform various functions
1206 * in response to the change. Should be called whenever
1207 * the application's top level window receives a
1208 * WM_TIMECHANGE message. It can be passed directly to
1209 * pthread_create() as a new thread if desired.
1210 */
1211 PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *);
1212
1213 #endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */
1214
1215 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
1216
1217 /*
1218 * Returns the Win32 HANDLE for the POSIX thread.
1219 */
1220 PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread);
1221
1222
1223 /*
1224 * Protected Methods
1225 *
1226 * This function blocks until the given WIN32 handle
1227 * is signaled or pthread_cancel had been called.
1228 * This function allows the caller to hook into the
1229 * PThreads cancel mechanism. It is implemented using
1230 *
1231 * WaitForMultipleObjects
1232 *
1233 * on 'waitHandle' and a manually reset WIN32 Event
1234 * used to implement pthread_cancel. The 'timeout'
1235 * argument to TimedWait is simply passed to
1236 * WaitForMultipleObjects.
1237 */
1238 PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle);
1239 PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle,
1240 DWORD timeout);
1241
1242 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
1243
1244 /*
1245 * Thread-Safe C Runtime Library Mappings.
1246 */
1247 #ifndef _UWIN
1248 # if defined(NEED_ERRNO)
1249 PTW32_DLLPORT int * PTW32_CDECL _errno( void );
1250 # else
1251 # ifndef errno
1252 # if (defined(_MT) || defined(_DLL))
1253 __declspec(dllimport) extern int * __cdecl _errno(void);
1254 # define errno (*_errno())
1255 # endif
1256 # endif
1257 # endif
1258 #endif
1259
1260 /*
1261 * WIN32 C runtime library had been made thread-safe
1262 * without affecting the user interface. Provide
1263 * mappings from the UNIX thread-safe versions to
1264 * the standard C runtime library calls.
1265 * Only provide function mappings for functions that
1266 * actually exist on WIN32.
1267 */
1268
1269 #if !defined(__MINGW32__)
1270 #define strtok_r( _s, _sep, _lasts ) \
1271 ( *(_lasts) = strtok( (_s), (_sep) ) )
1272 #endif /* !__MINGW32__ */
1273
1274 #define asctime_r( _tm, _buf ) \
1275 ( strcpy( (_buf), asctime( (_tm) ) ), \
1276 (_buf) )
1277
1278 #define ctime_r( _clock, _buf ) \
1279 ( strcpy( (_buf), ctime( (_clock) ) ), \
1280 (_buf) )
1281
1282 #define gmtime_r( _clock, _result ) \
1283 ( *(_result) = *gmtime( (_clock) ), \
1284 (_result) )
1285
1286 #define localtime_r( _clock, _result ) \
1287 ( *(_result) = *localtime( (_clock) ), \
1288 (_result) )
1289
1290 #define rand_r( _seed ) \
1291 ( _seed == _seed? rand() : rand() )
1292
1293
1294 /*
1295 * Some compiler environments don't define some things.
1296 */
1297 #if defined(__BORLANDC__)
1298 # define _ftime ftime
1299 # define _timeb timeb
1300 #endif
1301
1302 #ifdef __cplusplus
1303
1304 /*
1305 * Internal exceptions
1306 */
1307 class ptw32_exception {};
1308 class ptw32_exception_cancel : public ptw32_exception {};
1309 class ptw32_exception_exit : public ptw32_exception {};
1310
1311 #endif
1312
1313 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
1314
1315 /* FIXME: This is only required if the library was built using SEH */
1316 /*
1317 * Get internal SEH tag
1318 */
1319 PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);
1320
1321 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
1322
1323 #ifndef PTW32_BUILD
1324
1325 #ifdef __CLEANUP_SEH
1326
1327 /*
1328 * Redefine the SEH __except keyword to ensure that applications
1329 * propagate our internal exceptions up to the library's internal handlers.
1330 */
1331
1332 // PCSX2: Holy crap, what?! No. Let's not force code conformity on stupid coders. If they can't write
1333 // a proper exception handler that does EXCEPTION_CONTINUE_SEARCH on unhandled exceptions, they deserve
1334 // whatever bad karma befalls them. --air
1335
1336 //#define __except( E ) \
1337 // __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \
1338 // ? EXCEPTION_CONTINUE_SEARCH : ( E ) )
1339
1340 #endif /* __CLEANUP_SEH */
1341
1342 #ifdef __CLEANUP_CXX
1343
1344 /*
1345 * Redefine the C++ catch keyword to ensure that applications
1346 * propagate our internal exceptions up to the library's internal handlers.
1347 */
1348 #ifdef _MSC_VER
1349 /*
1350 * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll'
1351 * if you want Pthread-Win32 cancelation and pthread_exit to work.
1352 */
1353
1354 #ifndef PtW32NoCatchWarn
1355
1356 #pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.")
1357 #pragma message("------------------------------------------------------------------")
1358 #pragma message("When compiling applications with MSVC++ and C++ exception handling:")
1359 #pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads")
1360 #pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread")
1361 #pragma message(" cancelation and pthread_exit to work. For example:")
1362 #pragma message("")
1363 #pragma message(" #ifdef PtW32CatchAll")
1364 #pragma message(" PtW32CatchAll")
1365 #pragma message(" #else")
1366 #pragma message(" catch(...)")
1367 #pragma message(" #endif")
1368 #pragma message(" {")
1369 #pragma message(" /* Catchall block processing */")
1370 #pragma message(" }")
1371 #pragma message("------------------------------------------------------------------")
1372
1373 #endif
1374
1375 #define PtW32CatchAll \
1376 catch( ptw32_exception & ) { throw; } \
1377 catch( ... )
1378
1379 #else /* _MSC_VER */
1380
1381 #define catch( E ) \
1382 catch( ptw32_exception & ) { throw; } \
1383 catch( E )
1384
1385 #endif /* _MSC_VER */
1386
1387 #endif /* __CLEANUP_CXX */
1388
1389 #endif /* ! PTW32_BUILD */
1390
1391 #ifdef __cplusplus
1392 } /* End of extern "C" */
1393 #endif /* __cplusplus */
1394
1395 #ifdef PTW32__HANDLE_DEF
1396 # undef HANDLE
1397 #endif
1398 #ifdef PTW32__DWORD_DEF
1399 # undef DWORD
1400 #endif
1401
1402 #undef PTW32_LEVEL
1403 #undef PTW32_LEVEL_MAX
1404
1405 #endif /* ! RC_INVOKED */
1406
1407 #endif /* PTHREAD_H */

  ViewVC Help
Powered by ViewVC 1.1.22