/[pcsx2_0.9.7]/trunk/3rdparty/w32pthreads/ptw32_throw.c
ViewVC logotype

Contents of /trunk/3rdparty/w32pthreads/ptw32_throw.c

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: 4044 byte(s)
re-commit (had local access denied errors when committing)
1 /*
2 * ptw32_throw.c
3 *
4 * Description:
5 * This translation unit implements routines which are private to
6 * the implementation and may be used throughout it.
7 *
8 * --------------------------------------------------------------------------
9 *
10 * Pthreads-win32 - POSIX Threads Library for Win32
11 * Copyright(C) 1998 John E. Bossom
12 * Copyright(C) 1999,2005 Pthreads-win32 contributors
13 *
14 * Contact Email: rpj@callisto.canberra.edu.au
15 *
16 * The current list of contributors is contained
17 * in the file CONTRIBUTORS included with the source
18 * code distribution. The list can also be seen at the
19 * following World Wide Web location:
20 * http://sources.redhat.com/pthreads-win32/contributors.html
21 *
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License as published by the Free Software Foundation; either
25 * version 2 of the License, or (at your option) any later version.
26 *
27 * This library is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 * Lesser General Public License for more details.
31 *
32 * You should have received a copy of the GNU Lesser General Public
33 * License along with this library in the file COPYING.LIB;
34 * if not, write to the Free Software Foundation, Inc.,
35 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
36 */
37
38 #include "ptw32pch.h"
39
40 /*
41 * ptw32_throw
42 *
43 * All canceled and explicitly exited POSIX threads go through
44 * here. This routine knows how to exit both POSIX initiated threads and
45 * 'implicit' POSIX threads for each of the possible language modes (C,
46 * C++, and SEH).
47 */
48 void
49 ptw32_throw (DWORD exception)
50 {
51 /*
52 * Don't use pthread_self() to avoid creating an implicit POSIX thread handle
53 * unnecessarily.
54 */
55 ptw32_thread_t * sp = (ptw32_thread_t *) pthread_getspecific (ptw32_selfThreadKey);
56
57 #ifdef __CLEANUP_SEH
58 DWORD exceptionInformation[3];
59 #endif
60
61 if (exception != PTW32_EPS_CANCEL && exception != PTW32_EPS_EXIT)
62 {
63 /* Should never enter here */
64 exit (1);
65 }
66
67 if (NULL == sp || sp->implicit)
68 {
69 /*
70 * We're inside a non-POSIX initialised Win32 thread
71 * so there is no point to jump or throw back to. Just do an
72 * explicit thread exit here after cleaning up POSIX
73 * residue (i.e. cleanup handlers, POSIX thread handle etc).
74 */
75 void* exitCode = 0;
76
77 switch (exception)
78 {
79 case PTW32_EPS_CANCEL:
80 exitCode = PTHREAD_CANCELED;
81 break;
82 case PTW32_EPS_EXIT:
83 exitCode = sp->exitStatus;
84 break;
85 }
86
87 #if defined(PTW32_STATIC_LIB)
88
89 pthread_win32_thread_detach_np ();
90
91 #endif
92
93 #if ! defined (__MINGW32__) || defined (__MSVCRT__) || defined (__DMC__)
94 _endthreadex ((unsigned)exitCode);
95 #else
96 _endthread ();
97 #endif
98
99 }
100
101 #ifdef __CLEANUP_SEH
102
103
104 exceptionInformation[0] = (DWORD) (exception);
105 exceptionInformation[1] = (DWORD) (0);
106 exceptionInformation[2] = (DWORD) (0);
107
108 RaiseException (EXCEPTION_PTW32_SERVICES, 0, 3, exceptionInformation);
109
110 #else /* __CLEANUP_SEH */
111
112 #ifdef __CLEANUP_C
113
114 ptw32_pop_cleanup_all (1);
115 longjmp (sp->start_mark, exception);
116
117 #else /* __CLEANUP_C */
118
119 #ifdef __CLEANUP_CXX
120
121 switch (exception)
122 {
123 case PTW32_EPS_CANCEL:
124 throw ptw32_exception_cancel ();
125 break;
126 case PTW32_EPS_EXIT:
127 throw ptw32_exception_exit ();
128 break;
129 }
130
131 #else
132
133 #error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
134
135 #endif /* __CLEANUP_CXX */
136
137 #endif /* __CLEANUP_C */
138
139 #endif /* __CLEANUP_SEH */
140
141 /* Never reached */
142 }
143
144
145 #ifdef __CLEANUP_C
146 void
147 ptw32_pop_cleanup_all (int execute)
148 {
149 while (NULL != ptw32_pop_cleanup (execute))
150 {
151 }
152 }
153 #endif
154
155 DWORD
156 ptw32_get_exception_services_code (void)
157 {
158 #ifdef __CLEANUP_SEH
159
160 return EXCEPTION_PTW32_SERVICES;
161
162 #else
163
164 return (DWORD) NULL;
165
166 #endif
167 }

  ViewVC Help
Powered by ViewVC 1.1.22