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:
parent
65cc040971
commit
b229560132
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,8 +14,17 @@ public:
|
||||
void Lock(void);
|
||||
void Unlock(void);
|
||||
|
||||
#ifdef _DEBUG
|
||||
bool IsLocked(void);
|
||||
bool IsLockedByCurrentThread(void);
|
||||
#endif // _DEBUG
|
||||
|
||||
private:
|
||||
|
||||
#ifdef _DEBUG
|
||||
bool m_IsLocked;
|
||||
unsigned long m_OwningThreadID;
|
||||
#endif // _DEBUG
|
||||
|
||||
#ifdef _WIN32
|
||||
CRITICAL_SECTION m_CriticalSection;
|
||||
#else // _WIN32
|
||||
|
Loading…
Reference in New Issue
Block a user