/[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 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 5 months ago) by william
File MIME type: text/plain
File size: 42975 byte(s)
committing r3113 initial commit again...
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 #ifndef HAVE_STRUCT_TIMESPEC
310 #define HAVE_STRUCT_TIMESPEC 1
311 struct timespec {
312 long tv_sec;
313 long tv_nsec;
314 };
315 #endif /* HAVE_STRUCT_TIMESPEC */
316
317 #ifndef SIG_BLOCK
318 #define SIG_BLOCK 0
319 #endif /* SIG_BLOCK */
320
321 #ifndef SIG_UNBLOCK
322 #define SIG_UNBLOCK 1
323 #endif /* SIG_UNBLOCK */
324
325 #ifndef SIG_SETMASK
326 #define SIG_SETMASK 2
327 #endif /* SIG_SETMASK */
328
329 #ifdef __cplusplus
330 extern "C"
331 {
332 #endif /* __cplusplus */
333
334 /*
335 * -------------------------------------------------------------
336 *
337 * POSIX 1003.1-2001 Options
338 * =========================
339 *
340 * Options are normally set in <unistd.h>, which is not provided
341 * with pthreads-win32.
342 *
343 * For conformance with the Single Unix Specification (version 3), all of the
344 * options below are defined, and have a value of either -1 (not supported)
345 * or 200112L (supported).
346 *
347 * These options can neither be left undefined nor have a value of 0, because
348 * either indicates that sysconf(), which is not implemented, may be used at
349 * runtime to check the status of the option.
350 *
351 * _POSIX_THREADS (== 200112L)
352 * If == 200112L, you can use threads
353 *
354 * _POSIX_THREAD_ATTR_STACKSIZE (== 200112L)
355 * If == 200112L, you can control the size of a thread's
356 * stack
357 * pthread_attr_getstacksize
358 * pthread_attr_setstacksize
359 *
360 * _POSIX_THREAD_ATTR_STACKADDR (== -1)
361 * If == 200112L, you can allocate and control a thread's
362 * stack. If not supported, the following functions
363 * will return ENOSYS, indicating they are not
364 * supported:
365 * pthread_attr_getstackaddr
366 * pthread_attr_setstackaddr
367 *
368 * _POSIX_THREAD_PRIORITY_SCHEDULING (== -1)
369 * If == 200112L, you can use realtime scheduling.
370 * This option indicates that the behaviour of some
371 * implemented functions conforms to the additional TPS
372 * requirements in the standard. E.g. rwlocks favour
373 * writers over readers when threads have equal priority.
374 *
375 * _POSIX_THREAD_PRIO_INHERIT (== -1)
376 * If == 200112L, you can create priority inheritance
377 * mutexes.
378 * pthread_mutexattr_getprotocol +
379 * pthread_mutexattr_setprotocol +
380 *
381 * _POSIX_THREAD_PRIO_PROTECT (== -1)
382 * If == 200112L, you can create priority ceiling mutexes
383 * Indicates the availability of:
384 * pthread_mutex_getprioceiling
385 * pthread_mutex_setprioceiling
386 * pthread_mutexattr_getprioceiling
387 * pthread_mutexattr_getprotocol +
388 * pthread_mutexattr_setprioceiling
389 * pthread_mutexattr_setprotocol +
390 *
391 * _POSIX_THREAD_PROCESS_SHARED (== -1)
392 * If set, you can create mutexes and condition
393 * variables that can be shared with another
394 * process.If set, indicates the availability
395 * of:
396 * pthread_mutexattr_getpshared
397 * pthread_mutexattr_setpshared
398 * pthread_condattr_getpshared
399 * pthread_condattr_setpshared
400 *
401 * _POSIX_THREAD_SAFE_FUNCTIONS (== 200112L)
402 * If == 200112L you can use the special *_r library
403 * functions that provide thread-safe behaviour
404 *
405 * _POSIX_READER_WRITER_LOCKS (== 200112L)
406 * If == 200112L, you can use read/write locks
407 *
408 * _POSIX_SPIN_LOCKS (== 200112L)
409 * If == 200112L, you can use spin locks
410 *
411 * _POSIX_BARRIERS (== 200112L)
412 * If == 200112L, you can use barriers
413 *
414 * + These functions provide both 'inherit' and/or
415 * 'protect' protocol, based upon these macro
416 * settings.
417 *
418 * -------------------------------------------------------------
419 */
420
421 /*
422 * POSIX Options
423 */
424 #undef _POSIX_THREADS
425 #define _POSIX_THREADS 200112L
426
427 #undef _POSIX_READER_WRITER_LOCKS
428 #define _POSIX_READER_WRITER_LOCKS 200112L
429
430 #undef _POSIX_SPIN_LOCKS
431 #define _POSIX_SPIN_LOCKS 200112L
432
433 #undef _POSIX_BARRIERS
434 #define _POSIX_BARRIERS 200112L
435
436 #undef _POSIX_THREAD_SAFE_FUNCTIONS
437 #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
438
439 #undef _POSIX_THREAD_ATTR_STACKSIZE
440 #define _POSIX_THREAD_ATTR_STACKSIZE 200112L
441
442 /*
443 * The following options are not supported
444 */
445 #undef _POSIX_THREAD_ATTR_STACKADDR
446 #define _POSIX_THREAD_ATTR_STACKADDR -1
447
448 #undef _POSIX_THREAD_PRIO_INHERIT
449 #define _POSIX_THREAD_PRIO_INHERIT -1
450
451 #undef _POSIX_THREAD_PRIO_PROTECT
452 #define _POSIX_THREAD_PRIO_PROTECT -1
453
454 /* TPS is not fully supported. */
455 #undef _POSIX_THREAD_PRIORITY_SCHEDULING
456 #define _POSIX_THREAD_PRIORITY_SCHEDULING -1
457
458 #undef _POSIX_THREAD_PROCESS_SHARED
459 #define _POSIX_THREAD_PROCESS_SHARED -1
460
461
462 /*
463 * POSIX 1003.1-2001 Limits
464 * ===========================
465 *
466 * These limits are normally set in <limits.h>, which is not provided with
467 * pthreads-win32.
468 *
469 * PTHREAD_DESTRUCTOR_ITERATIONS
470 * Maximum number of attempts to destroy
471 * a thread's thread-specific data on
472 * termination (must be at least 4)
473 *
474 * PTHREAD_KEYS_MAX
475 * Maximum number of thread-specific data keys
476 * available per process (must be at least 128)
477 *
478 * PTHREAD_STACK_MIN
479 * Minimum supported stack size for a thread
480 *
481 * PTHREAD_THREADS_MAX
482 * Maximum number of threads supported per
483 * process (must be at least 64).
484 *
485 * SEM_NSEMS_MAX
486 * The maximum number of semaphores a process can have.
487 * (must be at least 256)
488 *
489 * SEM_VALUE_MAX
490 * The maximum value a semaphore can have.
491 * (must be at least 32767)
492 *
493 */
494 #undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
495 #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
496
497 #undef PTHREAD_DESTRUCTOR_ITERATIONS
498 #define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
499
500 #undef _POSIX_THREAD_KEYS_MAX
501 #define _POSIX_THREAD_KEYS_MAX 128
502
503 #undef PTHREAD_KEYS_MAX
504 #define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX
505
506 #undef PTHREAD_STACK_MIN
507 #define PTHREAD_STACK_MIN 0
508
509 #undef _POSIX_THREAD_THREADS_MAX
510 #define _POSIX_THREAD_THREADS_MAX 64
511
512 /* Arbitrary value */
513 #undef PTHREAD_THREADS_MAX
514 #define PTHREAD_THREADS_MAX 2019
515
516 #undef _POSIX_SEM_NSEMS_MAX
517 #define _POSIX_SEM_NSEMS_MAX 256
518
519 /* Arbitrary value */
520 #undef SEM_NSEMS_MAX
521 #define SEM_NSEMS_MAX 1024
522
523 #undef _POSIX_SEM_VALUE_MAX
524 #define _POSIX_SEM_VALUE_MAX 32767
525
526 #undef SEM_VALUE_MAX
527 #define SEM_VALUE_MAX INT_MAX
528
529
530 #if __GNUC__ && ! defined (__declspec)
531 # error Please upgrade your GNU compiler to one that supports __declspec.
532 #endif
533
534 /*
535 * When building the DLL code, you should define PTW32_BUILD so that
536 * the variables/functions are exported correctly. When using the DLL,
537 * do NOT define PTW32_BUILD, and then the variables/functions will
538 * be imported correctly.
539 */
540 #ifndef PTW32_STATIC_LIB
541 # ifdef PTW32_BUILD
542 # define PTW32_DLLPORT __declspec (dllexport)
543 # else
544 # define PTW32_DLLPORT __declspec (dllimport)
545 # endif
546 #else
547 # define PTW32_DLLPORT
548 #endif
549
550 /*
551 * The Open Watcom C/C++ compiler uses a non-standard calling convention
552 * that passes function args in registers unless __cdecl is explicitly specified
553 * in exposed function prototypes.
554 *
555 * We force all calls to cdecl even though this could slow Watcom code down
556 * slightly. If you know that the Watcom compiler will be used to build both
557 * the DLL and application, then you can probably define this as a null string.
558 * Remember that pthread.h (this file) is used for both the DLL and application builds.
559 */
560 #define PTW32_CDECL __cdecl
561
562 #if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX
563 # include <sys/types.h>
564 #else
565 /*
566 * Generic handle type - intended to extend uniqueness beyond
567 * that available with a simple pointer. It should scale for either
568 * IA-32 or IA-64.
569 */
570 typedef struct _ptw32_handle_t {
571 void * p; /* Pointer to actual object */
572 unsigned int x; /* Extra information - reuse count etc */
573
574 #ifdef __cplusplus
575 // Added support for various operators so that the struct is
576 // more pthreads-compliant in behavior. (air)
577 const bool operator ==( const struct _ptw32_handle_t rightside ) const
578 {
579 return p == rightside.p;
580 }
581
582 const bool operator !=( const struct _ptw32_handle_t rightside ) const
583 {
584 return p != rightside.p;
585 }
586 #endif
587
588 } ptw32_handle_t;
589
590 typedef ptw32_handle_t pthread_t;
591 typedef struct pthread_attr_t_ * pthread_attr_t;
592 typedef struct pthread_once_t_ pthread_once_t;
593 typedef struct pthread_key_t_ * pthread_key_t;
594 typedef struct pthread_mutex_t_ * pthread_mutex_t;
595 typedef struct pthread_mutexattr_t_ * pthread_mutexattr_t;
596 typedef struct pthread_cond_t_ * pthread_cond_t;
597 typedef struct pthread_condattr_t_ * pthread_condattr_t;
598 #endif
599 typedef struct pthread_rwlock_t_ * pthread_rwlock_t;
600 typedef struct pthread_rwlockattr_t_ * pthread_rwlockattr_t;
601 typedef struct pthread_spinlock_t_ * pthread_spinlock_t;
602 typedef struct pthread_barrier_t_ * pthread_barrier_t;
603 typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t;
604
605 /*
606 * ====================
607 * ====================
608 * POSIX Threads
609 * ====================
610 * ====================
611 */
612
613 enum {
614 /*
615 * pthread_attr_{get,set}detachstate
616 */
617 PTHREAD_CREATE_JOINABLE = 0, /* Default */
618 PTHREAD_CREATE_DETACHED = 1,
619
620 /*
621 * pthread_attr_{get,set}inheritsched
622 */
623 PTHREAD_INHERIT_SCHED = 0,
624 PTHREAD_EXPLICIT_SCHED = 1, /* Default */
625
626 /*
627 * pthread_{get,set}scope
628 */
629 PTHREAD_SCOPE_PROCESS = 0,
630 PTHREAD_SCOPE_SYSTEM = 1, /* Default */
631
632 /*
633 * pthread_setcancelstate paramters
634 */
635 PTHREAD_CANCEL_ENABLE = 0, /* Default */
636 PTHREAD_CANCEL_DISABLE = 1,
637
638 /*
639 * pthread_setcanceltype parameters
640 */
641 PTHREAD_CANCEL_ASYNCHRONOUS = 0,
642 PTHREAD_CANCEL_DEFERRED = 1, /* Default */
643
644 /*
645 * pthread_mutexattr_{get,set}pshared
646 * pthread_condattr_{get,set}pshared
647 */
648 PTHREAD_PROCESS_PRIVATE = 0,
649 PTHREAD_PROCESS_SHARED = 1,
650
651 /*
652 * pthread_barrier_wait
653 */
654 PTHREAD_BARRIER_SERIAL_THREAD = -1
655 };
656
657 /*
658 * ====================
659 * ====================
660 * Cancelation
661 * ====================
662 * ====================
663 */
664 #define PTHREAD_CANCELED ((void *) -1)
665
666
667 /*
668 * ====================
669 * ====================
670 * Once Key
671 * ====================
672 * ====================
673 */
674 #define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0}
675
676 struct pthread_once_t_
677 {
678 int done; /* indicates if user function has been executed */
679 void * lock;
680 int reserved1;
681 int reserved2;
682 };
683
684
685 /*
686 * ====================
687 * ====================
688 * Object initialisers
689 * ====================
690 * ====================
691 */
692
693 // Note: Static mutexes are useful in C but a bad idea in C++, and add overhead to all
694 // mutex lockers (bad!), so C++ code should idisable them and use C++ initializers instead.
695
696 #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
697 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2)
698 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3)
699
700 /*
701 * Compatibility with LinuxThreads
702 */
703 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
704 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER
705
706 #define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
707
708 #define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1)
709
710 #define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t) -1)
711
712
713 /*
714 * Mutex types.
715 */
716 enum
717 {
718 /* Compatibility with LinuxThreads */
719 PTHREAD_MUTEX_FAST_NP,
720 PTHREAD_MUTEX_RECURSIVE_NP,
721 PTHREAD_MUTEX_ERRORCHECK_NP,
722 PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP,
723 PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP,
724 /* For compatibility with POSIX */
725 PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP,
726 PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
727 PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
728 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
729 };
730
731
732 typedef struct ptw32_cleanup_t ptw32_cleanup_t;
733
734 #if defined(_MSC_VER)
735 /* Disable MSVC 'anachronism used' warning */
736 #pragma warning( disable : 4229 )
737 #endif
738
739 typedef void (* PTW32_CDECL ptw32_cleanup_callback_t)(void *);
740
741 #if defined(_MSC_VER)
742 #pragma warning( default : 4229 )
743 #endif
744
745 struct ptw32_cleanup_t
746 {
747 ptw32_cleanup_callback_t routine;
748 void *arg;
749 struct ptw32_cleanup_t *prev;
750 };
751
752 #ifdef __CLEANUP_SEH
753 #include <excpt.h> // PCSX2: excpt.h is needed for AbnormalTermination() -- air
754
755 /*
756 * WIN32 SEH version of cancel cleanup.
757 */
758
759 #define pthread_cleanup_push( _rout, _arg ) \
760 { \
761 ptw32_cleanup_t _cleanup; \
762 \
763 _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \
764 _cleanup.arg = (_arg); \
765 __try \
766 { \
767
768 #define pthread_cleanup_pop( _execute ) \
769 } \
770 __finally \
771 { \
772 if( _execute || AbnormalTermination()) \
773 { \
774 (*(_cleanup.routine))( _cleanup.arg ); \
775 } \
776 } \
777 }
778
779 #else /* __CLEANUP_SEH */
780
781 #ifdef __CLEANUP_C
782
783 /*
784 * C implementation of PThreads cancel cleanup
785 */
786
787 #define pthread_cleanup_push( _rout, _arg ) \
788 { \
789 ptw32_cleanup_t _cleanup; \
790 \
791 ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \
792
793 #define pthread_cleanup_pop( _execute ) \
794 (void) ptw32_pop_cleanup( _execute ); \
795 }
796
797 #else /* __CLEANUP_C */
798
799 #ifdef __CLEANUP_CXX
800
801 /*
802 * C++ version of cancel cleanup.
803 * - John E. Bossom.
804 */
805
806 class PThreadCleanup {
807 /*
808 * PThreadCleanup
809 *
810 * Purpose
811 * This class is a C++ helper class that is
812 * used to implement pthread_cleanup_push/
813 * pthread_cleanup_pop.
814 * The destructor of this class automatically
815 * pops the pushed cleanup routine regardless
816 * of how the code exits the scope
817 * (i.e. such as by an exception)
818 */
819 ptw32_cleanup_callback_t cleanUpRout;
820 void * obj;
821 int executeIt;
822
823 public:
824 PThreadCleanup() :
825 cleanUpRout( 0 ),
826 obj( 0 ),
827 executeIt( 0 )
828 /*
829 * No cleanup performed
830 */
831 {
832 }
833
834 PThreadCleanup(
835 ptw32_cleanup_callback_t routine,
836 void * arg ) :
837 cleanUpRout( routine ),
838 obj( arg ),
839 executeIt( 1 )
840 /*
841 * Registers a cleanup routine for 'arg'
842 */
843 {
844 }
845
846 ~PThreadCleanup()
847 {
848 if ( executeIt && ((void *) cleanUpRout != (void *) 0) )
849 {
850 (void) (*cleanUpRout)( obj );
851 }
852 }
853
854 void execute( int exec )
855 {
856 executeIt = exec;
857 }
858 };
859
860 /*
861 * C++ implementation of PThreads cancel cleanup;
862 * This implementation takes advantage of a helper
863 * class who's destructor automatically calls the
864 * cleanup routine if we exit our scope weirdly
865 */
866 #define pthread_cleanup_push( _rout, _arg ) \
867 { \
868 PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \
869 (void *) (_arg) );
870
871 #define pthread_cleanup_pop( _execute ) \
872 cleanup.execute( _execute ); \
873 }
874
875 #else
876
877 #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
878
879 #endif /* __CLEANUP_CXX */
880
881 #endif /* __CLEANUP_C */
882
883 #endif /* __CLEANUP_SEH */
884
885 /*
886 * ===============
887 * ===============
888 * Methods
889 * ===============
890 * ===============
891 */
892
893 /*
894 * PThread Attribute Functions
895 */
896 PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr);
897
898 PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr);
899
900 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr,
901 int *detachstate);
902
903 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr,
904 void **stackaddr);
905
906 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr,
907 size_t * stacksize);
908
909 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr,
910 int detachstate);
911
912 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr,
913 void *stackaddr);
914
915 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr,
916 size_t stacksize);
917
918 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr,
919 struct sched_param *param);
920
921 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr,
922 const struct sched_param *param);
923
924 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *,
925 int);
926
927 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (pthread_attr_t *,
928 int *);
929
930 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr,
931 int inheritsched);
932
933 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(pthread_attr_t * attr,
934 int * inheritsched);
935
936 PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *,
937 int);
938
939 PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *,
940 int *);
941
942 /*
943 * PThread Functions
944 */
945 PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid,
946 const pthread_attr_t * attr,
947 void *(*start) (void *),
948 void *arg);
949
950 PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid);
951
952 PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1,
953 pthread_t t2);
954
955 PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr);
956
957 PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread,
958 void **value_ptr);
959
960 PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void);
961
962 extern int pthread_cancel (pthread_t thread);
963
964 PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state,
965 int *oldstate);
966
967 PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type,
968 int *oldtype);
969
970 extern void pthread_testcancel (void);
971
972 PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control,
973 void (*init_routine) (void));
974
975 #if PTW32_LEVEL >= PTW32_LEVEL_MAX && defined(__CLEANUP_C)
976 PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute);
977
978 PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup,
979 void (*routine) (void *),
980 void *arg);
981 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
982
983 /*
984 * Thread Specific Data Functions
985 */
986 PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key,
987 void (*destructor) (void *));
988
989 PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key);
990
991 PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key,
992 const void *value);
993
994 PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key);
995
996
997 /*
998 * Mutex Attribute Functions
999 */
1000 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr);
1001
1002 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr);
1003
1004 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t
1005 * attr,
1006 int *pshared);
1007
1008 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr,
1009 int pshared);
1010
1011 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind);
1012 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *kind);
1013
1014 /*
1015 * Barrier Attribute Functions
1016 */
1017 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr);
1018
1019 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr);
1020
1021 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t
1022 * attr,
1023 int *pshared);
1024
1025 PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
1026 int pshared);
1027
1028 /*
1029 * Mutex Functions
1030 */
1031 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex,
1032 const pthread_mutexattr_t * attr);
1033
1034 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex);
1035
1036 extern int pthread_mutex_lock (pthread_mutex_t * mutex);
1037
1038 PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t *mutex,
1039 const struct timespec *abstime);
1040
1041 extern int pthread_mutex_trylock (pthread_mutex_t * mutex);
1042
1043 extern int pthread_mutex_unlock (pthread_mutex_t * mutex);
1044
1045 #ifdef PTW32_ALLOW_SPIN
1046 /*
1047 * Spinlock Functions
1048 *
1049 * These are disabled by default; they are not part of the "required" portion of pthreads
1050 * implementations, and they are generally a bad idea for anything except the most controlled
1051 * of threaded environments (which hardly exist in modern computing).
1052 */
1053 PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared);
1054
1055 PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock);
1056
1057 PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock);
1058
1059 PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock);
1060
1061 PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock);
1062 #endif
1063
1064 /*
1065 * Barrier Functions
1066 */
1067 PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier,
1068 const pthread_barrierattr_t * attr,
1069 unsigned int count);
1070
1071 PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier);
1072
1073 PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier);
1074
1075 #ifdef PTW32_ALLOW_COND
1076 /*
1077 * Condition Variable Attribute Functions
1078 */
1079 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr);
1080
1081 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr);
1082
1083 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr,
1084 int *pshared);
1085
1086 PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr,
1087 int pshared);
1088
1089 /*
1090 * Condition Variable Functions
1091 */
1092 PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond,
1093 const pthread_condattr_t * attr);
1094
1095 PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond);
1096
1097 PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond,
1098 pthread_mutex_t * mutex);
1099
1100 PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond,
1101 pthread_mutex_t * mutex,
1102 const struct timespec *abstime);
1103
1104 PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond);
1105
1106 PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond);
1107 #endif
1108
1109 /*
1110 * Scheduling
1111 */
1112 PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread,
1113 int policy,
1114 const struct sched_param *param);
1115
1116 PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread,
1117 int *policy,
1118 struct sched_param *param);
1119
1120 PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int);
1121
1122 PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void);
1123
1124 /*
1125 * Read-Write Lock Functions
1126 */
1127 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock,
1128 const pthread_rwlockattr_t *attr);
1129
1130 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock);
1131
1132 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *);
1133
1134 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *);
1135
1136 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock);
1137
1138 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock,
1139 const struct timespec *abstime);
1140
1141 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock);
1142
1143 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock,
1144 const struct timespec *abstime);
1145
1146 PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock);
1147
1148 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr);
1149
1150 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr);
1151
1152 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr,
1153 int *pshared);
1154
1155 PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
1156 int pshared);
1157
1158 #if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1
1159
1160 /*
1161 * Signal Functions. Should be defined in <signal.h> but MSVC and MinGW32
1162 * already have signal.h that don't define these.
1163 */
1164 PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig);
1165
1166 /*
1167 * Non-portable functions
1168 */
1169
1170 /*
1171 * Compatibility with Linux.
1172 */
1173 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr,
1174 int kind);
1175 PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr,
1176 int *kind);
1177
1178 /*
1179 * Possibly supported by other POSIX threads implementations
1180 */
1181 PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval);
1182 PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void);
1183
1184 /*
1185 * Useful if an application wants to statically link
1186 * the lib rather than load the DLL at run-time.
1187 */
1188 PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void);
1189 PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void);
1190 PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void);
1191 PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void);
1192
1193 /*
1194 * Features that are auto-detected at load/run time.
1195 */
1196 PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int);
1197 enum ptw32_features {
1198 PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */
1199 PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002 /* Can cancel blocked threads. */
1200 };
1201
1202 /*
1203 * Register a system time change with the library.
1204 * Causes the library to perform various functions
1205 * in response to the change. Should be called whenever
1206 * the application's top level window receives a
1207 * WM_TIMECHANGE message. It can be passed directly to
1208 * pthread_create() as a new thread if desired.
1209 */
1210 PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *);
1211
1212 #endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */
1213
1214 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
1215
1216 /*
1217 * Returns the Win32 HANDLE for the POSIX thread.
1218 */
1219 PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread);
1220
1221
1222 /*
1223 * Protected Methods
1224 *
1225 * This function blocks until the given WIN32 handle
1226 * is signaled or pthread_cancel had been called.
1227 * This function allows the caller to hook into the
1228 * PThreads cancel mechanism. It is implemented using
1229 *
1230 * WaitForMultipleObjects
1231 *
1232 * on 'waitHandle' and a manually reset WIN32 Event
1233 * used to implement pthread_cancel. The 'timeout'
1234 * argument to TimedWait is simply passed to
1235 * WaitForMultipleObjects.
1236 */
1237 PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle);
1238 PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle,
1239 DWORD timeout);
1240
1241 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
1242
1243 /*
1244 * Thread-Safe C Runtime Library Mappings.
1245 */
1246 #ifndef _UWIN
1247 # if defined(NEED_ERRNO)
1248 PTW32_DLLPORT int * PTW32_CDECL _errno( void );
1249 # else
1250 # ifndef errno
1251 # if (defined(_MT) || defined(_DLL))
1252 __declspec(dllimport) extern int * __cdecl _errno(void);
1253 # define errno (*_errno())
1254 # endif
1255 # endif
1256 # endif
1257 #endif
1258
1259 /*
1260 * WIN32 C runtime library had been made thread-safe
1261 * without affecting the user interface. Provide
1262 * mappings from the UNIX thread-safe versions to
1263 * the standard C runtime library calls.
1264 * Only provide function mappings for functions that
1265 * actually exist on WIN32.
1266 */
1267
1268 #if !defined(__MINGW32__)
1269 #define strtok_r( _s, _sep, _lasts ) \
1270 ( *(_lasts) = strtok( (_s), (_sep) ) )
1271 #endif /* !__MINGW32__ */
1272
1273 #define asctime_r( _tm, _buf ) \
1274 ( strcpy( (_buf), asctime( (_tm) ) ), \
1275 (_buf) )
1276
1277 #define ctime_r( _clock, _buf ) \
1278 ( strcpy( (_buf), ctime( (_clock) ) ), \
1279 (_buf) )
1280
1281 #define gmtime_r( _clock, _result ) \
1282 ( *(_result) = *gmtime( (_clock) ), \
1283 (_result) )
1284
1285 #define localtime_r( _clock, _result ) \
1286 ( *(_result) = *localtime( (_clock) ), \
1287 (_result) )
1288
1289 #define rand_r( _seed ) \
1290 ( _seed == _seed? rand() : rand() )
1291
1292
1293 /*
1294 * Some compiler environments don't define some things.
1295 */
1296 #if defined(__BORLANDC__)
1297 # define _ftime ftime
1298 # define _timeb timeb
1299 #endif
1300
1301 #ifdef __cplusplus
1302
1303 /*
1304 * Internal exceptions
1305 */
1306 class ptw32_exception {};
1307 class ptw32_exception_cancel : public ptw32_exception {};
1308 class ptw32_exception_exit : public ptw32_exception {};
1309
1310 #endif
1311
1312 #if PTW32_LEVEL >= PTW32_LEVEL_MAX
1313
1314 /* FIXME: This is only required if the library was built using SEH */
1315 /*
1316 * Get internal SEH tag
1317 */
1318 PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);
1319
1320 #endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
1321
1322 #ifndef PTW32_BUILD
1323
1324 #ifdef __CLEANUP_SEH
1325
1326 /*
1327 * Redefine the SEH __except keyword to ensure that applications
1328 * propagate our internal exceptions up to the library's internal handlers.
1329 */
1330
1331 // PCSX2: Holy crap, what?! No. Let's not force code conformity on stupid coders. If they can't write
1332 // a proper exception handler that does EXCEPTION_CONTINUE_SEARCH on unhandled exceptions, they deserve
1333 // whatever bad karma befalls them. --air
1334
1335 //#define __except( E ) \
1336 // __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \
1337 // ? EXCEPTION_CONTINUE_SEARCH : ( E ) )
1338
1339 #endif /* __CLEANUP_SEH */
1340
1341 #ifdef __CLEANUP_CXX
1342
1343 /*
1344 * Redefine the C++ catch keyword to ensure that applications
1345 * propagate our internal exceptions up to the library's internal handlers.
1346 */
1347 #ifdef _MSC_VER
1348 /*
1349 * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll'
1350 * if you want Pthread-Win32 cancelation and pthread_exit to work.
1351 */
1352
1353 #ifndef PtW32NoCatchWarn
1354
1355 #pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.")
1356 #pragma message("------------------------------------------------------------------")
1357 #pragma message("When compiling applications with MSVC++ and C++ exception handling:")
1358 #pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads")
1359 #pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread")
1360 #pragma message(" cancelation and pthread_exit to work. For example:")
1361 #pragma message("")
1362 #pragma message(" #ifdef PtW32CatchAll")
1363 #pragma message(" PtW32CatchAll")
1364 #pragma message(" #else")
1365 #pragma message(" catch(...)")
1366 #pragma message(" #endif")
1367 #pragma message(" {")
1368 #pragma message(" /* Catchall block processing */")
1369 #pragma message(" }")
1370 #pragma message("------------------------------------------------------------------")
1371
1372 #endif
1373
1374 #define PtW32CatchAll \
1375 catch( ptw32_exception & ) { throw; } \
1376 catch( ... )
1377
1378 #else /* _MSC_VER */
1379
1380 #define catch( E ) \
1381 catch( ptw32_exception & ) { throw; } \
1382 catch( E )
1383
1384 #endif /* _MSC_VER */
1385
1386 #endif /* __CLEANUP_CXX */
1387
1388 #endif /* ! PTW32_BUILD */
1389
1390 #ifdef __cplusplus
1391 } /* End of extern "C" */
1392 #endif /* __cplusplus */
1393
1394 #ifdef PTW32__HANDLE_DEF
1395 # undef HANDLE
1396 #endif
1397 #ifdef PTW32__DWORD_DEF
1398 # undef DWORD
1399 #endif
1400
1401 #undef PTW32_LEVEL
1402 #undef PTW32_LEVEL_MAX
1403
1404 #endif /* ! RC_INVOKED */
1405
1406 #endif /* PTHREAD_H */

  ViewVC Help
Powered by ViewVC 1.1.22