diff --git a/Source/Common/Common.vcproj b/Source/Common/Common.vcproj index c4174fc46..ecce01f61 100644 --- a/Source/Common/Common.vcproj +++ b/Source/Common/Common.vcproj @@ -125,6 +125,10 @@ Name="Source Files" Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" > + + diff --git a/Source/Common/Common.vcxproj b/Source/Common/Common.vcxproj index 34227364a..caa307a36 100644 --- a/Source/Common/Common.vcxproj +++ b/Source/Common/Common.vcxproj @@ -32,6 +32,7 @@ + @@ -55,6 +56,7 @@ + diff --git a/Source/Common/Common.vcxproj.filters b/Source/Common/Common.vcxproj.filters index 436f33cd1..852dc95bd 100644 --- a/Source/Common/Common.vcxproj.filters +++ b/Source/Common/Common.vcxproj.filters @@ -38,6 +38,9 @@ Source Files + + Source Files + @@ -76,5 +79,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Source/Common/CriticalSection.h b/Source/Common/CriticalSection.h index f057c9e3c..db22b0c73 100644 --- a/Source/Common/CriticalSection.h +++ b/Source/Common/CriticalSection.h @@ -1,104 +1,33 @@ -/** - * @file - */ #pragma once -#include -#include -#include -/** - * Encapsulates a Win32 critical section. - * Provides control over creation and clean destruction of native win32 critical sections. Also - * allows the object to be used directly in place of a CRITICAL_SECTION handle via the void* overload - * - * @author Peter Hancock - * - */ + class CriticalSection { public: - /** - * Create the critical section. - */ - CriticalSection() - { - ::InitializeCriticalSection(&cs); - } - /** - * Cleans up the critical section. - */ - ~CriticalSection(void) - { - ::DeleteCriticalSection(&cs); - } - /** - * Enters a critical section of code. - * Prevents other threads from accessing the section between the enter and leave sections simultaneously. - * @note It is good practice to try and keep the critical section code as little as possible, so that - * other threads are not locked waiting for it. - */ - void enter(void) - { - ::EnterCriticalSection(&cs); - } - /** - * Leaves the critical section. - * Allows threads access to the critical code section again. - * @warning Note that an exception occurring with a critical section may not result in the expected leave being - * called. To ensure that your critical section is exception safe, ensure that you wrap the critical - * section in a try catch, and the catch calls the leave method. - */ - void leave(void) - { - ::LeaveCriticalSection(&cs); - } - /** - * Provides conversion to the native WIN32 CRITICAL_SECTION object - * Allows the client to use the CriticalSection object as a native handle also. - * @return CRITICAL_SECTION handle - */ - operator CRITICAL_SECTION&() - { - return cs; - } + CriticalSection(); + ~CriticalSection(void); + + void enter(void); + void leave(void); private: CriticalSection(const CriticalSection&); // Disable copy constructor CriticalSection& operator=(const CriticalSection&); // Disable assignment - CRITICAL_SECTION cs; + void * m_cs; }; -/** - * CGuard class provides exception safety for critical sections - * A helper class that enters a critical section on construction, and leaves - * the critical section on destruction. - * - * @code - int i; - { - CGuard loopGuard(moduleCS); // enters the critical section - for(int i=0 ; i < 10 ; i++) - { - // Do stuff here // If an exception is thrown here, loopGuard goes out of scope - calling leave() - } - } // Guard goes out of scope here, destructor calls leave() - * @endcode - * - * @author Peter Hancock - * - */ class CGuard { public: - CGuard(CriticalSection& sectionName) : cs(sectionName) + CGuard(CriticalSection& sectionName) : m_cs(sectionName) { - cs.enter(); + m_cs.enter(); } ~CGuard() { - cs.leave(); + m_cs.leave(); } private: - CriticalSection& cs; + CriticalSection& m_cs; CGuard(const CGuard& copy); CGuard &operator=(const CGuard& rhs); }; diff --git a/Source/Common/stdafx.h b/Source/Common/stdafx.h index e601c4074..eb4efd627 100644 --- a/Source/Common/stdafx.h +++ b/Source/Common/stdafx.h @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/Source/Project64/stdafx.h b/Source/Project64/stdafx.h index 858d6f457..2c0f1950b 100644 --- a/Source/Project64/stdafx.h +++ b/Source/Project64/stdafx.h @@ -15,6 +15,8 @@ #include #include +#include +#include #include #include "Multilanguage.h" #include "User Interface.h"