summaryrefslogtreecommitdiffstats
path: root/source/cCriticalSection.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-02 00:32:11 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-02 00:32:11 +0200
commitb22956013294264121aa9a8a175c299b694d396e (patch)
treea952d37a63fe653a239812799ea0e75f5bd36056 /source/cCriticalSection.cpp
parentFix for Rev 814, the correct cPlayer object is actually sent into the callbacks. (diff)
downloadcuberite-b22956013294264121aa9a8a175c299b694d396e.tar
cuberite-b22956013294264121aa9a8a175c299b694d396e.tar.gz
cuberite-b22956013294264121aa9a8a175c299b694d396e.tar.bz2
cuberite-b22956013294264121aa9a8a175c299b694d396e.tar.lz
cuberite-b22956013294264121aa9a8a175c299b694d396e.tar.xz
cuberite-b22956013294264121aa9a8a175c299b694d396e.tar.zst
cuberite-b22956013294264121aa9a8a175c299b694d396e.zip
Diffstat (limited to '')
-rw-r--r--source/cCriticalSection.cpp48
1 files changed, 38 insertions, 10 deletions
diff --git a/source/cCriticalSection.cpp b/source/cCriticalSection.cpp
index e8d719a45..3da12ebf4 100644
--- a/source/cCriticalSection.cpp
+++ b/source/cCriticalSection.cpp
@@ -1,5 +1,6 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "cIsThread.h"
@@ -50,11 +51,16 @@ cCriticalSection::~cCriticalSection()
void cCriticalSection::Lock()
{
-#ifdef _WIN32
- EnterCriticalSection( &m_CriticalSection );
-#else
- pthread_mutex_lock( (pthread_mutex_t*)m_CriticalSectionPtr );
-#endif
+ #ifdef _WIN32
+ EnterCriticalSection( &m_CriticalSection );
+ #else
+ pthread_mutex_lock( (pthread_mutex_t*)m_CriticalSectionPtr );
+ #endif
+
+ #ifdef _DEBUG
+ m_IsLocked = true;
+ m_OwningThreadID = cIsThread::GetCurrentID();
+ #endif // _DEBUG
}
@@ -63,11 +69,33 @@ void cCriticalSection::Lock()
void cCriticalSection::Unlock()
{
-#ifdef _WIN32
- LeaveCriticalSection( &m_CriticalSection );
-#else
- pthread_mutex_unlock( (pthread_mutex_t*)m_CriticalSectionPtr );
-#endif
+ #ifdef _DEBUG
+ m_IsLocked = false;
+ #endif // _DEBUG
+
+ #ifdef _WIN32
+ LeaveCriticalSection( &m_CriticalSection );
+ #else
+ pthread_mutex_unlock( (pthread_mutex_t*)m_CriticalSectionPtr );
+ #endif
+}
+
+
+
+
+
+bool cCriticalSection::IsLocked(void)
+{
+ return m_IsLocked;
+}
+
+
+
+
+
+bool cCriticalSection::IsLockedByCurrentThread(void)
+{
+ return m_IsLocked && (m_OwningThreadID == cIsThread::GetCurrentID());
}