From 7c00edfc074491f1788d10a9e54c66b4228ae0a1 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Mon, 16 Mar 2009 18:32:18 +0000 Subject: [PATCH] Disabled global optimization properly, and enabled Incremental Link, on devel builds. Minor code changes compile fairly instantly now. ;) I'll make some property sheets for enabled/disabled LTCG/WPO in the future. Added a new Threading class: ScopedLock. Used as an automatic unlocking mutex (safe for use with C++ exceptions, and cleaner/simpler code too). It works like C#'s "using" and "lock" directives, for those familiar with that. Optimized the AtomicExchange implementations for MSVC. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@798 96395faa-99c1-11dd-bbfe-3dabce05a288 --- 3rdparty/bzip2/bzip2.vcproj | 3 +- 3rdparty/w32pthreads/pthreads_2008.vcproj | 3 +- .../ptw32_InterlockedCompareExchange.c | 37 +++++++------- 3rdparty/zlib/zlib.vcproj | 3 +- pcsx2/Linux/LnxThreads.cpp | 1 - pcsx2/RDebug/deci2.h | 2 - pcsx2/RDebug/deci2_dbgp.cpp | 1 - pcsx2/System.cpp | 14 +++-- pcsx2/System.h | 1 + pcsx2/ThreadTools.cpp | 1 + pcsx2/Threading.h | 51 +++++++++++++++++-- pcsx2/windows/VCprojects/pcsx2_2008.vcproj | 5 +- pcsx2/windows/WinThreads.cpp | 19 +++---- .../CDVDiso/src/Windows/CDVDiso_vs2008.vcproj | 9 ++-- 14 files changed, 95 insertions(+), 55 deletions(-) diff --git a/3rdparty/bzip2/bzip2.vcproj b/3rdparty/bzip2/bzip2.vcproj index 37821de9b7..5d36273f2a 100644 --- a/3rdparty/bzip2/bzip2.vcproj +++ b/3rdparty/bzip2/bzip2.vcproj @@ -142,7 +142,7 @@ ConfigurationType="4" InheritedPropertySheets="..\3rdparty.vsprops" CharacterSet="2" - WholeProgramOptimization="1" + WholeProgramOptimization="0" > Execute() block without // bad things happening (recompilers will slow down for a brief moment since rec code blocks diff --git a/pcsx2/System.h b/pcsx2/System.h index 5d64ad0040..1c51e8352b 100644 --- a/pcsx2/System.h +++ b/pcsx2/System.h @@ -26,6 +26,7 @@ #include "MemcpyFast.h" #include "SafeArray.h" #include "Misc.h" +#include "Threading.h" // to use threading stuff, include the Threading namespace in your file. enum PageProtectionMode diff --git a/pcsx2/ThreadTools.cpp b/pcsx2/ThreadTools.cpp index 47e1665faf..665ad569bc 100644 --- a/pcsx2/ThreadTools.cpp +++ b/pcsx2/ThreadTools.cpp @@ -44,6 +44,7 @@ namespace Threading void Thread::Close() { + if( m_terminated ) return; pthread_cancel( m_thread ); pthread_join( m_thread, NULL ); } diff --git a/pcsx2/Threading.h b/pcsx2/Threading.h index d0ed296574..eef45fe0bf 100644 --- a/pcsx2/Threading.h +++ b/pcsx2/Threading.h @@ -67,8 +67,7 @@ namespace Threading void Unlock(); }; - // Returns the number of available logical CPUs (cores plus - // hyperthreaded cpus) + // Returns the number of available logical CPUs (cores plus hyperthreaded cpus) extern void CountLogicalCores( int LogicalCoresPerPhysicalCPU, int PhysicalCoresPerPhysicalCPU ); // Releases a timeslice to other threads. @@ -80,6 +79,24 @@ namespace Threading // sleeps the current thread for the given number of milliseconds. extern void Sleep( int ms ); + ////////////////////////////////////////////////////////////////////////////////////////// + // Thread - Helper class for the basics of starting/managing simple threads. + // + // Use this as a base class for your threaded procedure, and implement the 'int Callback()' + // method. Use Start() and Close() to start and shutdown the thread, and use m_post_event + // internally to post/receive events for the thread (make a public accessor for it in your + // derived class if your thread utilizes the post). + // + // Notes: + // * To ensure thread safety against C++'s bizarre and not-thread-friendly object + // constructors and destructors, you *must* use Start() and Close(). There is a built- + // in Close() called on destruction, which should work for very simple threads (that + // do not have any special shutdown code of their own), but + // + // * Constructing threads as static vars isn't recommended since it can potentially con- + // fuse w32pthreads, if the static initializers are executed out-of-order (C++ offers + // no dependency options for ensuring correct static var initializations). + // class Thread : NoncopyableObject { protected: @@ -106,12 +123,36 @@ namespace Threading // on linux). static void* _internal_callback( void* func ); - // Implemented by derrived class to handle threading actions! + // Implemented by derived class to handle threading actions! virtual int Callback()=0; }; - // Our fundamental interlocking functions. All other useful interlocks can - // be derrived from these little beasties! + ////////////////////////////////////////////////////////////////////////////////////////// + // ScopedLock: Helper class for using Mutexes. + // Using this class provides an exception-safe (and generally clean) method of locking + // code inside a mutex. + class ScopedLock : NoncopyableObject + { + protected: + MutexLock& m_lock; + + public: + virtual ~ScopedLock() + { + m_lock.Unlock(); + } + + ScopedLock( MutexLock& locker ) : + m_lock( locker ) + { + m_lock.Lock(); + } + }; + + + ////////////////////////////////////////////////////////////////////////////////////////// + // Our fundamental interlocking functions. All other useful interlocks can be derived + // from these little beasties! extern long pcsx2_InterlockedExchange(volatile long* Target, long srcval); extern long pcsx2_InterlockedCompareExchange( volatile long* target, long srcval, long comp ); diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj index ce25ff64eb..a88aca38bb 100644 --- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj +++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj @@ -106,7 +106,7 @@ UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="false" CharacterSet="2" - WholeProgramOptimization="1" + WholeProgramOptimization="0" >