/[pcsx2_0.9.7]/trunk/pcsx2/gui/AppCoreThread.h
ViewVC logotype

Contents of /trunk/pcsx2/gui/AppCoreThread.h

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: 8006 byte(s)
re-commit (had local access denied errors when committing)
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #pragma once
17
18 #include "System/SysThreads.h"
19 #include "pxEventThread.h"
20
21 #include "AppCommon.h"
22 #include "AppCorePlugins.h"
23 #include "SaveState.h"
24
25 #define AffinityAssert_AllowFrom_CoreThread() \
26 pxAssertMsg( GetCoreThread().IsSelf(), "Thread affinity violation: Call allowed from SysCoreThread only." )
27
28 #define AffinityAssert_DisallowFrom_CoreThread() \
29 pxAssertMsg( !GetCoreThread().IsSelf(), "Thread affinity violation: Call is *not* allowed from SysCoreThread." )
30
31 class IScopedCoreThread;
32 class BaseScopedCoreThread;
33
34 enum ScopedCoreResumeType
35 {
36 ScopedCore_BlockingResume
37 , ScopedCore_NonblockingResume
38 , ScopedCore_SkipResume
39 };
40
41
42 // --------------------------------------------------------------------------------------
43 // BaseSysExecEvent_ScopedCore
44 // --------------------------------------------------------------------------------------
45 class BaseSysExecEvent_ScopedCore : public SysExecEvent
46 {
47 protected:
48 SynchronousActionState* m_resume;
49 Threading::Mutex* m_mtx_resume;
50
51 public:
52 virtual ~BaseSysExecEvent_ScopedCore() throw() {}
53
54 BaseSysExecEvent_ScopedCore& SetResumeStates( SynchronousActionState* sync, Threading::Mutex* mutex )
55 {
56 m_resume = sync;
57 m_mtx_resume = mutex;
58 return *this;
59 }
60
61 BaseSysExecEvent_ScopedCore& SetResumeStates( SynchronousActionState& sync, Threading::Mutex& mutex )
62 {
63 m_resume = &sync;
64 m_mtx_resume = &mutex;
65 return *this;
66 }
67
68 protected:
69 BaseSysExecEvent_ScopedCore( SynchronousActionState* sync=NULL, SynchronousActionState* resume_sync=NULL, Threading::Mutex* mtx_resume=NULL )
70 : SysExecEvent( sync )
71 {
72 m_resume = resume_sync;
73 m_mtx_resume = mtx_resume;
74 }
75
76 void _post_and_wait( IScopedCoreThread& core );
77
78 virtual void DoScopedTask() {}
79 };
80
81
82 // --------------------------------------------------------------------------------------
83 // SysExecEvent_CoreThreadClose
84 // --------------------------------------------------------------------------------------
85 class SysExecEvent_CoreThreadClose : public BaseSysExecEvent_ScopedCore
86 {
87 public:
88 wxString GetEventName() const { return L"CloseCoreThread"; }
89
90 virtual ~SysExecEvent_CoreThreadClose() throw() {}
91 SysExecEvent_CoreThreadClose* Clone() const { return new SysExecEvent_CoreThreadClose( *this ); }
92
93 SysExecEvent_CoreThreadClose( SynchronousActionState* sync=NULL, SynchronousActionState* resume_sync=NULL, Threading::Mutex* mtx_resume=NULL )
94 : BaseSysExecEvent_ScopedCore( sync, resume_sync, mtx_resume ) { }
95
96 protected:
97 void InvokeEvent();
98 };
99
100 // --------------------------------------------------------------------------------------
101 // SysExecEvent_CoreThreadPause
102 // --------------------------------------------------------------------------------------
103 class SysExecEvent_CoreThreadPause : public BaseSysExecEvent_ScopedCore
104 {
105 public:
106 wxString GetEventName() const { return L"PauseCoreThread"; }
107
108 virtual ~SysExecEvent_CoreThreadPause() throw() {}
109 SysExecEvent_CoreThreadPause* Clone() const { return new SysExecEvent_CoreThreadPause( *this ); }
110
111 SysExecEvent_CoreThreadPause( SynchronousActionState* sync=NULL, SynchronousActionState* resume_sync=NULL, Threading::Mutex* mtx_resume=NULL )
112 : BaseSysExecEvent_ScopedCore( sync, resume_sync, mtx_resume ) { }
113
114 protected:
115 void InvokeEvent();
116 };
117
118 // --------------------------------------------------------------------------------------
119 // AppCoreThread class
120 // --------------------------------------------------------------------------------------
121 class AppCoreThread : public SysCoreThread
122 {
123 typedef SysCoreThread _parent;
124
125 protected:
126 volatile bool m_resetCdvd;
127
128 public:
129 AppCoreThread();
130 virtual ~AppCoreThread() throw();
131
132 void ResetCdvd() { m_resetCdvd = true; }
133
134 virtual void Suspend( bool isBlocking=false );
135 virtual void Resume();
136 virtual void Reset();
137 virtual void ResetQuick();
138 virtual void Cancel( bool isBlocking=true );
139 virtual bool StateCheckInThread();
140 virtual void ChangeCdvdSource();
141
142 virtual void ApplySettings( const Pcsx2Config& src );
143 virtual void UploadStateCopy( const VmStateBuffer& copy );
144
145 protected:
146 virtual void DoCpuExecute();
147
148 virtual void OnResumeReady();
149 virtual void OnResumeInThread( bool IsSuspended );
150 virtual void OnSuspendInThread();
151 virtual void OnCleanupInThread();
152 virtual void VsyncInThread();
153 virtual void GameStartingInThread();
154 virtual void ExecuteTaskInThread();
155 virtual void DoCpuReset();
156 };
157
158 // --------------------------------------------------------------------------------------
159 // IScopedCoreThread / BaseScopedCoreThread
160 // --------------------------------------------------------------------------------------
161 class IScopedCoreThread
162 {
163 protected:
164 IScopedCoreThread() {}
165
166 public:
167 virtual ~IScopedCoreThread() throw() {};
168 virtual void AllowResume()=0;
169 virtual void DisallowResume()=0;
170 };
171
172 class BaseScopedCoreThread : public IScopedCoreThread
173 {
174 DeclareNoncopyableObject( BaseScopedCoreThread );
175
176 protected:
177 bool m_allowResume;
178 bool m_alreadyStopped;
179 bool m_alreadyScoped;
180 SynchronousActionState m_sync;
181 SynchronousActionState m_sync_resume;
182 Threading::Mutex m_mtx_resume;
183
184 BaseScopedCoreThread();
185
186 public:
187 virtual ~BaseScopedCoreThread() throw()=0;
188 virtual void AllowResume();
189 virtual void DisallowResume();
190
191 virtual bool PostToSysExec( BaseSysExecEvent_ScopedCore* msg );
192
193 protected:
194 // Called from destructors -- do not make virtual!!
195 void DoResume();
196 };
197
198 // --------------------------------------------------------------------------------------
199 // ScopedCoreThreadClose / ScopedCoreThreadPause / ScopedCoreThreadPopup
200 // --------------------------------------------------------------------------------------
201 // This class behaves a bit differently from other scoped classes due to the "standard"
202 // assumption that we actually do *not* want to resume CoreThread operations when an
203 // exception occurs. Because of this, the destructor of this class does *not* unroll the
204 // suspend operation. Instead you must manually instruct the class to resume using a call
205 // to the provisioned AllowResume() method.
206 //
207 // If the class leaves scope without having been resumed, a log is written to the console.
208 // This can be useful for troubleshooting, and also allows the log a second line of info
209 // indicating the status of CoreThread execution at the time of the exception.
210 //
211 // ScopedCoreThreadPopup is intended for use where message boxes are popped up to the user.
212 // The old style GUI (without GSopen2) must use a full close of the CoreThread, in order to
213 // ensure that the GS window isn't blocking the popup, and to avoid crashes if the GS window
214 // is maximized or fullscreen.
215 //
216 class ScopedCoreThreadClose : public BaseScopedCoreThread
217 {
218 typedef BaseScopedCoreThread _parent;
219
220 public:
221 ScopedCoreThreadClose();
222 virtual ~ScopedCoreThreadClose() throw();
223
224 void LoadPlugins();
225 };
226
227 struct ScopedCoreThreadPause : public BaseScopedCoreThread
228 {
229 typedef BaseScopedCoreThread _parent;
230
231 public:
232 ScopedCoreThreadPause( BaseSysExecEvent_ScopedCore* abuse_me=NULL );
233 virtual ~ScopedCoreThreadPause() throw();
234 };
235
236 struct ScopedCoreThreadPopup : public IScopedCoreThread
237 {
238 protected:
239 ScopedPtr<BaseScopedCoreThread> m_scoped_core;
240
241 public:
242 ScopedCoreThreadPopup();
243 virtual ~ScopedCoreThreadPopup() throw() {}
244
245 virtual void AllowResume();
246 virtual void DisallowResume();
247 };

  ViewVC Help
Powered by ViewVC 1.1.22