diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-01-29 15:29:26 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-01-29 15:29:26 +0100 |
commit | e2ad02f50ac69f3789b7e475dbce469eeec29468 (patch) | |
tree | 69ceb5f7ee9b5219ef2f7058b5c84647e212f6ee /source/cCriticalSection.cpp | |
parent | now it will compile on linux (diff) | |
download | cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.gz cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.bz2 cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.lz cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.xz cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.zst cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.zip |
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();
+}
+
+
+
+
|