summaryrefslogtreecommitdiffstats
path: root/source/cCriticalSection.cpp
diff options
context:
space:
mode:
authorcedeel@gmail.com <cedeel@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-14 15:06:06 +0200
committercedeel@gmail.com <cedeel@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-14 15:06:06 +0200
commit92c59963f82f81aa3202657e7fdbb2592924ede3 (patch)
treeb7eb2474528a4998fa102e3ec9119b908cee08b4 /source/cCriticalSection.cpp
parentAdded HOOK_WEATHER_CHANGE. (diff)
downloadcuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.gz
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.bz2
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.lz
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.xz
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.tar.zst
cuberite-92c59963f82f81aa3202657e7fdbb2592924ede3.zip
Diffstat (limited to '')
-rw-r--r--source/cCriticalSection.cpp314
1 files changed, 157 insertions, 157 deletions
diff --git a/source/cCriticalSection.cpp b/source/cCriticalSection.cpp
index f66e6b878..e8d719a45 100644
--- a/source/cCriticalSection.cpp
+++ b/source/cCriticalSection.cpp
@@ -1,157 +1,157 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// cCriticalSection:
-
-cCriticalSection::cCriticalSection()
-{
-#ifdef _WIN32
- InitializeCriticalSection( &m_CriticalSection );
-#else
- m_Attributes = new pthread_mutexattr_t;
- pthread_mutexattr_init((pthread_mutexattr_t*)m_Attributes);
- pthread_mutexattr_settype((pthread_mutexattr_t*)m_Attributes, PTHREAD_MUTEX_RECURSIVE);
-
- m_CriticalSectionPtr = new pthread_mutex_t;
- if( pthread_mutex_init( (pthread_mutex_t*)m_CriticalSectionPtr, (pthread_mutexattr_t*)m_Attributes ) != 0 )
- {
- LOG("ERROR: Could not initialize Critical Section!");
- }
-#endif
-}
-
-
-
-
-
-cCriticalSection::~cCriticalSection()
-{
-#ifdef _WIN32
- DeleteCriticalSection( &m_CriticalSection );
-#else
- if( pthread_mutex_destroy( (pthread_mutex_t*)m_CriticalSectionPtr ) != 0 )
- {
- LOG("ERROR: Could not destroy Critical Section!");
- }
- delete (pthread_mutex_t*)m_CriticalSectionPtr;
- pthread_mutexattr_destroy( (pthread_mutexattr_t*)m_Attributes );
- delete (pthread_mutexattr_t*)m_Attributes;
-#endif
-}
-
-
-
-
-
-void cCriticalSection::Lock()
-{
-#ifdef _WIN32
- EnterCriticalSection( &m_CriticalSection );
-#else
- pthread_mutex_lock( (pthread_mutex_t*)m_CriticalSectionPtr );
-#endif
-}
-
-
-
-
-
-void cCriticalSection::Unlock()
-{
-#ifdef _WIN32
- LeaveCriticalSection( &m_CriticalSection );
-#else
- 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(cCriticalSection & a_CS)
- : m_CS(&a_CS)
- , m_IsLocked(false)
-{
- Lock();
-}
-
-
-
-
-
-cCSLock::~cCSLock()
-{
- if (!m_IsLocked)
- {
- return;
- }
- Unlock();
-}
-
-
-
-
-
-void cCSLock::Lock(void)
-{
- ASSERT(!m_IsLocked);
- m_IsLocked = true;
- m_CS->Lock();
-}
-
-
-
-
-
-void cCSLock::Unlock(void)
-{
- ASSERT(m_IsLocked);
- m_IsLocked = false;
- m_CS->Unlock();
-}
-
-
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// cCSUnlock:
-
-cCSUnlock::cCSUnlock(cCSLock & a_Lock) :
- m_Lock(a_Lock)
-{
- m_Lock.Unlock();
-}
-
-
-
-
-
-cCSUnlock::~cCSUnlock()
-{
- m_Lock.Lock();
-}
-
-
-
-
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cCriticalSection:
+
+cCriticalSection::cCriticalSection()
+{
+#ifdef _WIN32
+ InitializeCriticalSection( &m_CriticalSection );
+#else
+ m_Attributes = new pthread_mutexattr_t;
+ pthread_mutexattr_init((pthread_mutexattr_t*)m_Attributes);
+ pthread_mutexattr_settype((pthread_mutexattr_t*)m_Attributes, PTHREAD_MUTEX_RECURSIVE);
+
+ m_CriticalSectionPtr = new pthread_mutex_t;
+ if( pthread_mutex_init( (pthread_mutex_t*)m_CriticalSectionPtr, (pthread_mutexattr_t*)m_Attributes ) != 0 )
+ {
+ LOG("ERROR: Could not initialize Critical Section!");
+ }
+#endif
+}
+
+
+
+
+
+cCriticalSection::~cCriticalSection()
+{
+#ifdef _WIN32
+ DeleteCriticalSection( &m_CriticalSection );
+#else
+ if( pthread_mutex_destroy( (pthread_mutex_t*)m_CriticalSectionPtr ) != 0 )
+ {
+ LOG("ERROR: Could not destroy Critical Section!");
+ }
+ delete (pthread_mutex_t*)m_CriticalSectionPtr;
+ pthread_mutexattr_destroy( (pthread_mutexattr_t*)m_Attributes );
+ delete (pthread_mutexattr_t*)m_Attributes;
+#endif
+}
+
+
+
+
+
+void cCriticalSection::Lock()
+{
+#ifdef _WIN32
+ EnterCriticalSection( &m_CriticalSection );
+#else
+ pthread_mutex_lock( (pthread_mutex_t*)m_CriticalSectionPtr );
+#endif
+}
+
+
+
+
+
+void cCriticalSection::Unlock()
+{
+#ifdef _WIN32
+ LeaveCriticalSection( &m_CriticalSection );
+#else
+ 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(cCriticalSection & a_CS)
+ : m_CS(&a_CS)
+ , m_IsLocked(false)
+{
+ Lock();
+}
+
+
+
+
+
+cCSLock::~cCSLock()
+{
+ if (!m_IsLocked)
+ {
+ return;
+ }
+ Unlock();
+}
+
+
+
+
+
+void cCSLock::Lock(void)
+{
+ ASSERT(!m_IsLocked);
+ m_IsLocked = true;
+ m_CS->Lock();
+}
+
+
+
+
+
+void cCSLock::Unlock(void)
+{
+ ASSERT(m_IsLocked);
+ m_IsLocked = false;
+ m_CS->Unlock();
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cCSUnlock:
+
+cCSUnlock::cCSUnlock(cCSLock & a_Lock) :
+ m_Lock(a_Lock)
+{
+ m_Lock.Unlock();
+}
+
+
+
+
+
+cCSUnlock::~cCSUnlock()
+{
+ m_Lock.Lock();
+}
+
+
+
+