diff options
Diffstat (limited to '')
-rw-r--r-- | source/cCriticalSection.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/source/cCriticalSection.cpp b/source/cCriticalSection.cpp index 85f89c195..bf84b7c2f 100644 --- a/source/cCriticalSection.cpp +++ b/source/cCriticalSection.cpp @@ -1,5 +1,6 @@ #include "cCriticalSection.h"
#include "cMCLogger.h"
+#include <assert.h>
#ifdef _WIN32
#include <Windows.h>
@@ -7,6 +8,13 @@ #include <pthread.h>
#endif
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cCriticalSection:
+
cCriticalSection::cCriticalSection()
{
#ifdef _WIN32
@@ -25,6 +33,10 @@ cCriticalSection::cCriticalSection() #endif
}
+
+
+
+
cCriticalSection::~cCriticalSection()
{
#ifdef _WIN32
@@ -41,6 +53,10 @@ cCriticalSection::~cCriticalSection() #endif
}
+
+
+
+
void cCriticalSection::Lock()
{
#ifdef _WIN32
@@ -50,6 +66,10 @@ void cCriticalSection::Lock() #endif
}
+
+
+
+
void cCriticalSection::Unlock()
{
#ifdef _WIN32
@@ -58,3 +78,80 @@ void cCriticalSection::Unlock() pthread_mutex_unlock( (pthread_mutex_t*)m_CriticalSectionPtr );
#endif
}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cCSLock
+
+cCSLock::cCSLock(cCriticalSection * a_CS) :
+ m_CS(a_CS),
+ m_IsLocked(false)
+{
+ Lock();
+}
+
+
+
+
+
+cCSLock::~cCSLock()
+{
+ Unlock();
+}
+
+
+
+
+
+void cCSLock::Lock(void)
+{
+ #ifdef _DEBUG
+ assert(!m_IsLocked);
+ m_IsLocked = true;
+ #endif // _DEBUG
+
+ m_CS->Lock();
+}
+
+
+
+
+
+void cCSLock::Unlock(void)
+{
+ #ifdef _DEBUG
+ assert(m_IsLocked);
+ m_IsLocked = false;
+ #endif // _DEBUG
+
+ m_CS->Unlock();
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cCSUnlock:
+
+cCSUnlock::cCSUnlock(cCSLock & a_Lock) :
+ m_Lock(a_Lock)
+{
+ m_Lock.Unlock();
+}
+
+
+
+
+
+cCSUnlock::~cCSUnlock()
+{
+ m_Lock.Lock();
+}
+
+
+
+
|