/[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

--- trunk/common/include/Utilities/Threading.h	2010/09/07 03:24:11	31
+++ trunk/common/include/Utilities/Threading.h	2010/09/07 11:08:22	62
@@ -21,6 +21,7 @@
 
 #include "Pcsx2Defs.h"
 #include "ScopedPtr.h"
+#include "TraceLog.h"
 
 #undef Yield		// release the burden of windows.h global namespace spam.
 
@@ -28,6 +29,35 @@
 	pxAssertMsg( wxThread::IsMain(), "Thread affinity violation: Call allowed from main thread only." )
 
 // --------------------------------------------------------------------------------------
+//  pxThreadLog / ConsoleLogSource_Threading
+// --------------------------------------------------------------------------------------
+
+class ConsoleLogSource_Threading : ConsoleLogSource
+{
+	typedef ConsoleLogSource _parent;
+
+public:
+	using _parent::IsActive;
+
+	ConsoleLogSource_Threading();
+
+	bool Write( const wxString& thrname, const wxChar* msg ) {
+		return _parent::Write( wxsFormat(L"(thread:%s) ", thrname.c_str()) + msg );
+	}
+	bool Warn( const wxString& thrname, const wxChar* msg )	{
+		return _parent::Warn( wxsFormat(L"(thread:%s) ", thrname.c_str()) + msg );
+	}
+	bool Error( const wxString& thrname, const wxChar* msg ) {
+		return _parent::Error( wxsFormat(L"(thread:%s) ", thrname.c_str()) + msg );
+	}
+};
+
+extern ConsoleLogSource_Threading pxConLog_Thread;
+
+#define pxThreadLog pxConLog_Thread.IsActive() && pxConLog_Thread
+
+
+// --------------------------------------------------------------------------------------
 //  PCSX2_THREAD_LOCAL - Defines platform/operating system support for Thread Local Storage
 // --------------------------------------------------------------------------------------
 // For complimentary support for TLS, include Utilities/TlsVariable.inl, and use the
@@ -47,69 +77,70 @@
 
 namespace Threading
 {
-	class PersistentThread;
+	class pxThread;
 	class RwMutex;
 
 	extern void pxTestCancel();
-	extern PersistentThread* pxGetCurrentThread();
+	extern pxThread* pxGetCurrentThread();
 	extern wxString pxGetCurrentThreadName();
 	extern u64 GetThreadCpuTime();
 	extern u64 GetThreadTicksPerSecond();
 
 	// Yields the current thread and provides cancellation points if the thread is managed by
-	// PersistentThread.  Unmanaged threads use standard Sleep.
+	// pxThread.  Unmanaged threads use standard Sleep.
 	extern void pxYield( int ms );
 }
 
 namespace Exception
 {
-	class BaseThreadError : public virtual RuntimeError
+	class BaseThreadError : public RuntimeError
 	{
+		DEFINE_EXCEPTION_COPYTORS( BaseThreadError, RuntimeError )
+		DEFINE_EXCEPTION_MESSAGES( BaseThreadError )
+
 	public:
-		Threading::PersistentThread*	m_thread;
+		Threading::pxThread*	m_thread;
 
-		DEFINE_EXCEPTION_COPYTORS( BaseThreadError )
+	protected:
+		BaseThreadError() {
+			m_thread = NULL;
+		}
 
-		explicit BaseThreadError( Threading::PersistentThread* _thread=NULL )
+	public:
+		explicit BaseThreadError( Threading::pxThread* _thread )
 		{
 			m_thread = _thread;
-			BaseException::InitBaseEx( "Unspecified thread error" );
+			m_message_diag = L"An unspecified thread-related error occurred (thread=%s)";
 		}
 
-		BaseThreadError( Threading::PersistentThread& _thread )
+		explicit BaseThreadError( Threading::pxThread& _thread )
 		{
 			m_thread = &_thread;
-			BaseException::InitBaseEx( "Unspecified thread error" );
+			m_message_diag = L"An unspecified thread-related error occurred (thread=%s)";
 		}
 
 		virtual wxString FormatDiagnosticMessage() const;
 		virtual wxString FormatDisplayMessage() const;
 
-		Threading::PersistentThread& Thread();
-		const Threading::PersistentThread& Thread() const;
+		Threading::pxThread& Thread();
+		const Threading::pxThread& Thread() const;
 	};
 
-	class ThreadCreationError : public virtual BaseThreadError
+	class ThreadCreationError : public BaseThreadError
 	{
-	public:
-		DEFINE_EXCEPTION_COPYTORS( ThreadCreationError )
+		DEFINE_EXCEPTION_COPYTORS( ThreadCreationError, BaseThreadError )
 
-		explicit ThreadCreationError( Threading::PersistentThread* _thread=NULL, const char* msg="Creation of thread '%s' failed." )
+	public:
+		explicit ThreadCreationError( Threading::pxThread* _thread )
 		{
 			m_thread = _thread;
-			BaseException::InitBaseEx( msg );
-		}
-
-		ThreadCreationError( Threading::PersistentThread& _thread, const char* msg="Creation of thread '%s' failed." )
-		{
-			m_thread = &_thread;
-			BaseException::InitBaseEx( msg );
+			SetBothMsgs( L"Thread creation failure.  An unspecified error occurred while trying to create the %s thread." );
 		}
 
-		ThreadCreationError( Threading::PersistentThread& _thread, const wxString& msg_diag, const wxString& msg_user )
+		explicit ThreadCreationError( Threading::pxThread& _thread )
 		{
 			m_thread = &_thread;
-			BaseException::InitBaseEx( msg_diag, msg_user );
+			SetBothMsgs( L"Thread creation failure.  An unspecified error occurred while trying to create the %s thread." );
 		}
 	};
 }
@@ -128,6 +159,10 @@
 
 	// For use in spin/wait loops.
 	extern void SpinWait();
+	
+	// Use prior to committing data to another thread (internal memcpy_qwc does not use fencing,
+	// so that many memcpys can be issued in a row more efficiently)
+	extern void StoreFence();
 
 	// Optional implementation to enable hires thread/process scheduler for the operating system.
 	// Needed by Windows, but might not be relevant to other platforms.

 

  ViewVC Help
Powered by ViewVC 1.1.22