1
0

Critical sectino now allows debug info - is it locked? / is it locked by current thread?

Useful for ASSERTs

git-svn-id: http://mc-server.googlecode.com/svn/trunk@817 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-09-01 22:32:11 +00:00
parent 65cc040971
commit b229560132
2 changed files with 48 additions and 11 deletions

View File

@ -1,5 +1,6 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cIsThread.h"
@ -55,6 +56,11 @@ void cCriticalSection::Lock()
#else #else
pthread_mutex_lock( (pthread_mutex_t*)m_CriticalSectionPtr ); pthread_mutex_lock( (pthread_mutex_t*)m_CriticalSectionPtr );
#endif #endif
#ifdef _DEBUG
m_IsLocked = true;
m_OwningThreadID = cIsThread::GetCurrentID();
#endif // _DEBUG
} }
@ -63,6 +69,10 @@ void cCriticalSection::Lock()
void cCriticalSection::Unlock() void cCriticalSection::Unlock()
{ {
#ifdef _DEBUG
m_IsLocked = false;
#endif // _DEBUG
#ifdef _WIN32 #ifdef _WIN32
LeaveCriticalSection( &m_CriticalSection ); LeaveCriticalSection( &m_CriticalSection );
#else #else
@ -74,6 +84,24 @@ void cCriticalSection::Unlock()
bool cCriticalSection::IsLocked(void)
{
return m_IsLocked;
}
bool cCriticalSection::IsLockedByCurrentThread(void)
{
return m_IsLocked && (m_OwningThreadID == cIsThread::GetCurrentID());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cCSLock // cCSLock

View File

@ -14,7 +14,16 @@ public:
void Lock(void); void Lock(void);
void Unlock(void); void Unlock(void);
#ifdef _DEBUG
bool IsLocked(void);
bool IsLockedByCurrentThread(void);
#endif // _DEBUG
private: private:
#ifdef _DEBUG
bool m_IsLocked;
unsigned long m_OwningThreadID;
#endif // _DEBUG
#ifdef _WIN32 #ifdef _WIN32
CRITICAL_SECTION m_CriticalSection; CRITICAL_SECTION m_CriticalSection;