/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/ramdump-lateset/pcsx2/gui/pxEventThread.h
ViewVC logotype

Diff of /branch/debug/0.X/0.9.X/0.9.7/ramdump-lateset/pcsx2/gui/pxEventThread.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 329 by william, Sun Dec 26 08:32:43 2010 UTC revision 330 by william, Tue Dec 28 04:24:23 2010 UTC
# Line 22  Line 22 
22  // TODO!!  Make the system defined in this header system a bit more generic, and then move  // TODO!!  Make the system defined in this header system a bit more generic, and then move
23  // it to the Utilities library.  // it to the Utilities library.
24    
25  class pxEvtHandler;  class pxEvtQueue;
26  class SysExecEvent;  class SysExecEvent;
27    
28  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
# Line 38  public: Line 38  public:
38    
39          ConsoleLogSource_Event();          ConsoleLogSource_Event();
40    
41          bool Write( const pxEvtHandler* evtHandler, const SysExecEvent* evt, const wxChar* msg );          bool Write( const pxEvtQueue* evtHandler, const SysExecEvent* evt, const wxChar* msg );
42          bool Warn( const pxEvtHandler* evtHandler, const SysExecEvent* evt, const wxChar* msg );          bool Warn( const pxEvtQueue* evtHandler, const SysExecEvent* evt, const wxChar* msg );
43          bool Error( const pxEvtHandler* evtHandler, const SysExecEvent* evt, const wxChar* msg );          bool Error( const pxEvtQueue* evtHandler, const SysExecEvent* evt, const wxChar* msg );
44  };  };
45    
46  extern ConsoleLogSource_Event pxConLog_Event;  extern ConsoleLogSource_Event pxConLog_Event;
# Line 51  extern ConsoleLogSource_Event pxConLog_E Line 51  extern ConsoleLogSource_Event pxConLog_E
51  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
52  //  SysExecEvent  //  SysExecEvent
53  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
54  // Base class for all pxEvtHandler processable events.  // Base class for all pxEvtQueue processable events.
55  //  //
56  // Rules for deriving:  // Rules for deriving:
57  //  * Override InvokeEvent(), *NOT* _DoInvokeEvent().  _DoInvokeEvent() performs setup and  //  * Override InvokeEvent(), *NOT* _DoInvokeEvent().  _DoInvokeEvent() performs setup and
# Line 67  extern ConsoleLogSource_Event pxConLog_E Line 67  extern ConsoleLogSource_Event pxConLog_E
67  //    awaking the invoking thread as soon as the queue has caught up to and processed  //    awaking the invoking thread as soon as the queue has caught up to and processed
68  //    the event.  //    the event.
69  //  //
70  //  * Avoid using virtual class inheritence.  It's unreliable at best.  //  * Avoid using virtual class inheritence to 'cleverly' bind a SysExecEvent to another
71    //    existing class.  Multiple inheritence is unreliable at best, and virtual inheritence
72    //    is even worse.  Create a SysExecEvent wrapper class instead, and embed an instance of
73    //    the other class you want to turn into an event within it.  It might feel like more work
74    //    but it *will* be less work in the long run.
75  //  //
76  class SysExecEvent : public ICloneable  class SysExecEvent : public ICloneable
77  {  {
# Line 174  protected: Line 178  protected:
178  #endif  #endif
179    
180  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
181  //  pxEvtHandler  //  pxEvtQueue
182  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
183  // Purpose: To provide a safe environment for queuing tasks that must be executed in  // Thread-safe platform-independent message queue, intended to act as a proxy between
184  // sequential order (in blocking fashion).  Unlike the wxWidgets event handlers, instances  // control threads (such as the Main/UI thread) and worker threads.
185  // of this handler can be stalled for extended periods of time without affecting the  //
186  // responsiveness of the GUI or frame updates of the DirectX output windows.  This class  // Proxy message queues provide a safe environment for queuing tasks that must be executed
187  // is mostly intended to be used from the context of an ExecutorThread.  // in sequential order (in blocking fashion) on one or more worker threads.  The queue is
188    // deadlock-free, which means the Main/UI thread can queue events into this EventQueue without
189    // fear of causing unresponsiveness within the user interface.
190  //  //
191  // Rationales:  // Rationales:
192  //  * Using the main event handler of wxWidgets is dangerous because it must call itself  //  * Using the main event handler of wxWidgets is dangerous because it must call itself
# Line 189  protected: Line 195  protected:
195  //    running events that expect the suspend to be complete while the suspend was still  //    running events that expect the suspend to be complete while the suspend was still
196  //    pending.  //    pending.
197  //  //
198  //  * wxWidgets Event Queue (wxEvtHandler) isn't thread-safe and isn't even  //  * wxWidgets Event Queue (wxEvtHandler) isn't thread-safe and isn't even intended for
199  //    intended for use for anything other than wxWindow events (it uses static vars  //    use for anything other than wxWindow events (it uses static vars and checks/modifies
200  //    and checks/modifies wxApp globals while processing), so it's useless to us.  //    wxApp globals while processing), so it's useless to us.  Have to roll our own. -_-
 //    Have to roll our own. -_-  
201  //  //
202  class pxEvtHandler  class pxEvtQueue
203  {  {
204  protected:  protected:
205          pxEvtList                                       m_pendingEvents;          pxEvtList                                       m_pendingEvents;
# Line 210  protected: Line 215  protected:
215          volatile u64                            m_qpc_Start;          volatile u64                            m_qpc_Start;
216    
217  public:  public:
218          pxEvtHandler();          pxEvtQueue();
219          virtual ~pxEvtHandler() throw() {}          virtual ~pxEvtQueue() throw() {}
220    
221          virtual wxString GetEventHandlerName() const { return L"pxEvtHandler"; }          virtual wxString GetEventHandlerName() const { return L"pxEvtQueue"; }
222    
223          virtual void ShutdownQueue();          virtual void ShutdownQueue();
224          bool IsShuttingDown() const { return !!m_Quitting; }          bool IsShuttingDown() const { return !!m_Quitting; }
# Line 243  protected: Line 248  protected:
248  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
249  //  ExecutorThread  //  ExecutorThread
250  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
251  // Threaded wrapper class for implementing pxEvtHandler.  Simply create the desired  // Threaded wrapper class for implementing a pxEvtQueue on its own thread, to serve as a
252  // EvtHandler, start the thread, and enjoy queued event execution in fully blocking fashion.  // proxy between worker threads and response threads (which cannot be allowed to stall or
253    // deadlock).  Simply create the desired EvtHandler, start the thread, and enjoy queued
254    // event execution in fully blocking fashion.
255    //
256    // Deadlock Protection Notes:
257    //  The ExecutorThread utilizes an underlying pxEventQueue, which only locks the queue for
258    //  adding and removing items only.  Events are processed during an unlocked queue state,
259    //  which allows other threads to add events with a guarantee that the add operation will
260    //  take very little time.
261    //
262    // Implementation Notes:
263    //  We use object encapsulation instead of multiple inheritance in order to avoid the many
264    //  unavoidable catastrophes and pitfalls involved in multi-inheritance that would ruin our
265    //  will to live.  The alternative requires manually exposing the interface of the underlying
266    //  instance of pxEventQueue; and that's ok really when you consider the alternative. --air
267  //  //
268  class ExecutorThread : public Threading::pxThread  class ExecutorThread : public Threading::pxThread
269  {  {
# Line 252  class ExecutorThread : public Threading: Line 271  class ExecutorThread : public Threading:
271    
272  protected:  protected:
273          ScopedPtr<wxTimer>              m_ExecutorTimer;          ScopedPtr<wxTimer>              m_ExecutorTimer;
274          ScopedPtr<pxEvtHandler> m_EvtHandler;          ScopedPtr<pxEvtQueue>   m_EvtHandler;
275    
276  public:  public:
277          ExecutorThread( pxEvtHandler* evtandler = NULL );          ExecutorThread( pxEvtQueue* evtandler = NULL );
278          virtual ~ExecutorThread() throw() { }          virtual ~ExecutorThread() throw() { }
279    
280          virtual void ShutdownQueue();          virtual void ShutdownQueue();

Legend:
Removed from v.329  
changed lines
  Added in v.330

  ViewVC Help
Powered by ViewVC 1.1.22