/[pcsx2_0.9.7]/trunk/common/include/Utilities/Threading.h
ViewVC logotype

Diff of /trunk/common/include/Utilities/Threading.h

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

revision 61 by william, Tue Sep 7 03:24:11 2010 UTC revision 62 by william, Tue Sep 7 11:08:22 2010 UTC
# Line 21  Line 21 
21    
22  #include "Pcsx2Defs.h"  #include "Pcsx2Defs.h"
23  #include "ScopedPtr.h"  #include "ScopedPtr.h"
24    #include "TraceLog.h"
25    
26  #undef Yield            // release the burden of windows.h global namespace spam.  #undef Yield            // release the burden of windows.h global namespace spam.
27    
# Line 28  Line 29 
29          pxAssertMsg( wxThread::IsMain(), "Thread affinity violation: Call allowed from main thread only." )          pxAssertMsg( wxThread::IsMain(), "Thread affinity violation: Call allowed from main thread only." )
30    
31  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
32    //  pxThreadLog / ConsoleLogSource_Threading
33    // --------------------------------------------------------------------------------------
34    
35    class ConsoleLogSource_Threading : ConsoleLogSource
36    {
37            typedef ConsoleLogSource _parent;
38    
39    public:
40            using _parent::IsActive;
41    
42            ConsoleLogSource_Threading();
43    
44            bool Write( const wxString& thrname, const wxChar* msg ) {
45                    return _parent::Write( wxsFormat(L"(thread:%s) ", thrname.c_str()) + msg );
46            }
47            bool Warn( const wxString& thrname, const wxChar* msg ) {
48                    return _parent::Warn( wxsFormat(L"(thread:%s) ", thrname.c_str()) + msg );
49            }
50            bool Error( const wxString& thrname, const wxChar* msg ) {
51                    return _parent::Error( wxsFormat(L"(thread:%s) ", thrname.c_str()) + msg );
52            }
53    };
54    
55    extern ConsoleLogSource_Threading pxConLog_Thread;
56    
57    #define pxThreadLog pxConLog_Thread.IsActive() && pxConLog_Thread
58    
59    
60    // --------------------------------------------------------------------------------------
61  //  PCSX2_THREAD_LOCAL - Defines platform/operating system support for Thread Local Storage  //  PCSX2_THREAD_LOCAL - Defines platform/operating system support for Thread Local Storage
62  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
63  // For complimentary support for TLS, include Utilities/TlsVariable.inl, and use the  // For complimentary support for TLS, include Utilities/TlsVariable.inl, and use the
# Line 47  class wxTimeSpan; Line 77  class wxTimeSpan;
77    
78  namespace Threading  namespace Threading
79  {  {
80          class PersistentThread;          class pxThread;
81          class RwMutex;          class RwMutex;
82    
83          extern void pxTestCancel();          extern void pxTestCancel();
84          extern PersistentThread* pxGetCurrentThread();          extern pxThread* pxGetCurrentThread();
85          extern wxString pxGetCurrentThreadName();          extern wxString pxGetCurrentThreadName();
86          extern u64 GetThreadCpuTime();          extern u64 GetThreadCpuTime();
87          extern u64 GetThreadTicksPerSecond();          extern u64 GetThreadTicksPerSecond();
88    
89          // Yields the current thread and provides cancellation points if the thread is managed by          // Yields the current thread and provides cancellation points if the thread is managed by
90          // PersistentThread.  Unmanaged threads use standard Sleep.          // pxThread.  Unmanaged threads use standard Sleep.
91          extern void pxYield( int ms );          extern void pxYield( int ms );
92  }  }
93    
94  namespace Exception  namespace Exception
95  {  {
96          class BaseThreadError : public virtual RuntimeError          class BaseThreadError : public RuntimeError
97          {          {
98                    DEFINE_EXCEPTION_COPYTORS( BaseThreadError, RuntimeError )
99                    DEFINE_EXCEPTION_MESSAGES( BaseThreadError )
100    
101          public:          public:
102                  Threading::PersistentThread*    m_thread;                  Threading::pxThread*    m_thread;
103    
104                  DEFINE_EXCEPTION_COPYTORS( BaseThreadError )          protected:
105                    BaseThreadError() {
106                            m_thread = NULL;
107                    }
108    
109                  explicit BaseThreadError( Threading::PersistentThread* _thread=NULL )          public:
110                    explicit BaseThreadError( Threading::pxThread* _thread )
111                  {                  {
112                          m_thread = _thread;                          m_thread = _thread;
113                          BaseException::InitBaseEx( "Unspecified thread error" );                          m_message_diag = L"An unspecified thread-related error occurred (thread=%s)";
114                  }                  }
115    
116                  BaseThreadError( Threading::PersistentThread& _thread )                  explicit BaseThreadError( Threading::pxThread& _thread )
117                  {                  {
118                          m_thread = &_thread;                          m_thread = &_thread;
119                          BaseException::InitBaseEx( "Unspecified thread error" );                          m_message_diag = L"An unspecified thread-related error occurred (thread=%s)";
120                  }                  }
121    
122                  virtual wxString FormatDiagnosticMessage() const;                  virtual wxString FormatDiagnosticMessage() const;
123                  virtual wxString FormatDisplayMessage() const;                  virtual wxString FormatDisplayMessage() const;
124    
125                  Threading::PersistentThread& Thread();                  Threading::pxThread& Thread();
126                  const Threading::PersistentThread& Thread() const;                  const Threading::pxThread& Thread() const;
127          };          };
128    
129          class ThreadCreationError : public virtual BaseThreadError          class ThreadCreationError : public BaseThreadError
130          {          {
131          public:                  DEFINE_EXCEPTION_COPYTORS( ThreadCreationError, BaseThreadError )
                 DEFINE_EXCEPTION_COPYTORS( ThreadCreationError )  
132    
133                  explicit ThreadCreationError( Threading::PersistentThread* _thread=NULL, const char* msg="Creation of thread '%s' failed." )          public:
134                    explicit ThreadCreationError( Threading::pxThread* _thread )
135                  {                  {
136                          m_thread = _thread;                          m_thread = _thread;
137                          BaseException::InitBaseEx( msg );                          SetBothMsgs( L"Thread creation failure.  An unspecified error occurred while trying to create the %s thread." );
                 }  
   
                 ThreadCreationError( Threading::PersistentThread& _thread, const char* msg="Creation of thread '%s' failed." )  
                 {  
                         m_thread = &_thread;  
                         BaseException::InitBaseEx( msg );  
138                  }                  }
139    
140                  ThreadCreationError( Threading::PersistentThread& _thread, const wxString& msg_diag, const wxString& msg_user )                  explicit ThreadCreationError( Threading::pxThread& _thread )
141                  {                  {
142                          m_thread = &_thread;                          m_thread = &_thread;
143                          BaseException::InitBaseEx( msg_diag, msg_user );                          SetBothMsgs( L"Thread creation failure.  An unspecified error occurred while trying to create the %s thread." );
144                  }                  }
145          };          };
146  }  }
# Line 128  namespace Threading Line 159  namespace Threading
159    
160          // For use in spin/wait loops.          // For use in spin/wait loops.
161          extern void SpinWait();          extern void SpinWait();
162            
163            // Use prior to committing data to another thread (internal memcpy_qwc does not use fencing,
164            // so that many memcpys can be issued in a row more efficiently)
165            extern void StoreFence();
166    
167          // Optional implementation to enable hires thread/process scheduler for the operating system.          // Optional implementation to enable hires thread/process scheduler for the operating system.
168          // Needed by Windows, but might not be relevant to other platforms.          // Needed by Windows, but might not be relevant to other platforms.

Legend:
Removed from v.61  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.22