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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 2 months ago) by william
File MIME type: text/plain
File size: 3469 byte(s)
re-commit (had local access denied errors when committing)
1 /*
2 * ptw32_new.c
3 *
4 * Description:
5 * This translation unit provides platform-specific cancelation functionality.
6 *
7 * --------------------------------------------------------------------------
8 *
9 * Pthreads-win32 - POSIX Threads Library for Win32
10 * Copyright(C) 1998 John E. Bossom
11 * Copyright(C) 1999,2005 Pthreads-win32 contributors
12 *
13 * Contact Email: rpj@callisto.canberra.edu.au
14 *
15 * The current list of contributors is contained
16 * in the file CONTRIBUTORS included with the source
17 * code distribution. The list can also be seen at the
18 * following World Wide Web location:
19 * http://sources.redhat.com/pthreads-win32/contributors.html
20 *
21 * This library is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public
23 * License as published by the Free Software Foundation; either
24 * version 2 of the License, or (at your option) any later version.
25 *
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library in the file COPYING.LIB;
33 * if not, write to the Free Software Foundation, Inc.,
34 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
35 */
36
37 #include "ptw32pch.h"
38
39 #if defined(_M_IX86) || defined(_X86_)
40 #define PTW32_PROGCTR(Context) ((Context).Eip)
41 #endif
42
43 #if defined (_M_IA64)
44 #define PTW32_PROGCTR(Context) ((Context).StIIP)
45 #endif
46
47 #if defined(_MIPS_)
48 #define PTW32_PROGCTR(Context) ((Context).Fir)
49 #endif
50
51 #if defined(_ALPHA_)
52 #define PTW32_PROGCTR(Context) ((Context).Fir)
53 #endif
54
55 #if defined(_PPC_)
56 #define PTW32_PROGCTR(Context) ((Context).Iar)
57 #endif
58
59 #if defined(_AMD64_)
60 #define PTW32_PROGCTR(Context) ((Context).Rip)
61 #endif
62
63 #if !defined(PTW32_PROGCTR)
64 #error Module contains CPU-specific code; modify and recompile.
65 #endif
66
67 static void
68 ptw32_cancel_self (void)
69 {
70 ptw32_throw (PTW32_EPS_CANCEL);
71
72 /* Never reached */
73 }
74
75 static void CALLBACK
76 ptw32_cancel_callback (DWORD_PTR unused)
77 {
78 ptw32_throw (PTW32_EPS_CANCEL);
79
80 /* Never reached */
81 }
82
83 /*
84 * ptw32_RegisterCancelation() -
85 * Must have args of same type as QueueUserAPCEx because this function
86 * is a substitute for QueueUserAPCEx if it's not available.
87 */
88 DWORD
89 ptw32_RegisterCancelation (PAPCFUNC unused1, HANDLE threadH, DWORD unused2)
90 {
91 CONTEXT context;
92
93 context.ContextFlags = CONTEXT_CONTROL;
94 GetThreadContext (threadH, &context);
95 PTW32_PROGCTR (context) = (DWORD_PTR) ptw32_cancel_self;
96 SetThreadContext (threadH, &context);
97 return 0;
98 }
99
100 void ptw32_PrepCancel( ptw32_thread_t* tp )
101 {
102 HANDLE threadH = tp->threadH;
103
104 SuspendThread (threadH);
105
106 if (WaitForSingleObject (threadH, 0) == WAIT_TIMEOUT)
107 {
108 tp->state = PThreadStateCanceling;
109 tp->cancelState = PTHREAD_CANCEL_DISABLE;
110 /*
111 * If alertdrv and QueueUserAPCEx is available then the following
112 * will result in a call to QueueUserAPCEx with the args given, otherwise
113 * this will result in a call to ptw32_RegisterCancelation and only
114 * the threadH arg will be used.
115 */
116 ptw32_register_cancelation (ptw32_cancel_callback, threadH, 0);
117 (void) pthread_mutex_unlock (&tp->cancelLock);
118 ResumeThread (threadH);
119 }
120 }

  ViewVC Help
Powered by ViewVC 1.1.22