summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/CriticalSection.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2017-01-17 22:38:04 +0100
committerMattes D <github@xoft.cz>2017-01-18 09:03:05 +0100
commit7cc3fb098df221f083da1d81d2327a0a5f22edf5 (patch)
treede9232cbf239800ea1e7a71cf52086509a9472ea /src/OSSupport/CriticalSection.cpp
parentDebuggers: Added a deadlock simulation command. (diff)
downloadcuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.gz
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.bz2
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.lz
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.xz
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.tar.zst
cuberite-7cc3fb098df221f083da1d81d2327a0a5f22edf5.zip
Diffstat (limited to '')
-rw-r--r--src/OSSupport/CriticalSection.cpp24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/OSSupport/CriticalSection.cpp b/src/OSSupport/CriticalSection.cpp
index 2e533676d..27284acb0 100644
--- a/src/OSSupport/CriticalSection.cpp
+++ b/src/OSSupport/CriticalSection.cpp
@@ -9,12 +9,10 @@
////////////////////////////////////////////////////////////////////////////////
// cCriticalSection:
-#ifdef _DEBUG
-cCriticalSection::cCriticalSection()
+cCriticalSection::cCriticalSection():
+ m_RecursionCount(0)
{
- m_IsLocked = 0;
}
-#endif // _DEBUG
@@ -24,10 +22,8 @@ void cCriticalSection::Lock()
{
m_Mutex.lock();
- #ifdef _DEBUG
- m_IsLocked += 1;
- m_OwningThreadID = std::this_thread::get_id();
- #endif // _DEBUG
+ m_RecursionCount += 1;
+ m_OwningThreadID = std::this_thread::get_id();
}
@@ -36,10 +32,8 @@ void cCriticalSection::Lock()
void cCriticalSection::Unlock()
{
- #ifdef _DEBUG
- ASSERT(m_IsLocked > 0);
- m_IsLocked -= 1;
- #endif // _DEBUG
+ ASSERT(IsLockedByCurrentThread());
+ m_RecursionCount -= 1;
m_Mutex.unlock();
}
@@ -48,10 +42,9 @@ void cCriticalSection::Unlock()
-#ifdef _DEBUG
bool cCriticalSection::IsLocked(void)
{
- return (m_IsLocked > 0);
+ return (m_RecursionCount > 0);
}
@@ -60,9 +53,8 @@ bool cCriticalSection::IsLocked(void)
bool cCriticalSection::IsLockedByCurrentThread(void)
{
- return ((m_IsLocked > 0) && (m_OwningThreadID == std::this_thread::get_id()));
+ return ((m_RecursionCount > 0) && (m_OwningThreadID == std::this_thread::get_id()));
}
-#endif // _DEBUG