From 15fe5a1d41acc50dd2111309a352575a1edacf1c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Fri, 14 Dec 2012 22:36:12 +0000 Subject: Fixed cCriticalSection's debugging functions git-svn-id: http://mc-server.googlecode.com/svn/trunk@1072 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/OSSupport/CriticalSection.cpp | 13 +++++++++---- source/OSSupport/CriticalSection.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source/OSSupport/CriticalSection.cpp b/source/OSSupport/CriticalSection.cpp index d83d7af02..bda97e3a1 100644 --- a/source/OSSupport/CriticalSection.cpp +++ b/source/OSSupport/CriticalSection.cpp @@ -22,6 +22,10 @@ cCriticalSection::cCriticalSection() LOGERROR("Could not initialize Critical Section!"); } #endif + + #ifdef _DEBUG + m_IsLocked = 0; + #endif // _DEBUG } @@ -54,7 +58,7 @@ void cCriticalSection::Lock() #endif #ifdef _DEBUG - m_IsLocked = true; + m_IsLocked += 1; m_OwningThreadID = cIsThread::GetCurrentID(); #endif // _DEBUG } @@ -66,7 +70,8 @@ void cCriticalSection::Lock() void cCriticalSection::Unlock() { #ifdef _DEBUG - m_IsLocked = false; + ASSERT(m_IsLocked > 0); + m_IsLocked -= 1; #endif // _DEBUG #ifdef _WIN32 @@ -83,7 +88,7 @@ void cCriticalSection::Unlock() #ifdef _DEBUG bool cCriticalSection::IsLocked(void) { - return m_IsLocked; + return (m_IsLocked > 0); } @@ -92,7 +97,7 @@ bool cCriticalSection::IsLocked(void) bool cCriticalSection::IsLockedByCurrentThread(void) { - return (m_IsLocked && (m_OwningThreadID == cIsThread::GetCurrentID())); + return ((m_IsLocked > 0) && (m_OwningThreadID == cIsThread::GetCurrentID())); } #endif // _DEBUG diff --git a/source/OSSupport/CriticalSection.h b/source/OSSupport/CriticalSection.h index c7607ee70..1bfe81439 100644 --- a/source/OSSupport/CriticalSection.h +++ b/source/OSSupport/CriticalSection.h @@ -21,7 +21,7 @@ public: private: #ifdef _DEBUG - bool m_IsLocked; + int m_IsLocked; // Number of times this CS is locked unsigned long m_OwningThreadID; #endif // _DEBUG -- cgit v1.2.3