diff options
author | Mattes D <github@xoft.cz> | 2014-12-07 15:01:36 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-12-07 15:01:36 +0100 |
commit | d00ebd7ee700fcd7f30ea27d238ba1f0d56dfe21 (patch) | |
tree | b0dbd8a8396ad22cf77cb4b367295d25ad3055a7 /src/OSSupport/CriticalSection.cpp | |
parent | Reduced river height (diff) | |
parent | Merge remote-tracking branch 'origin/master' into c++11 (diff) | |
download | cuberite-d00ebd7ee700fcd7f30ea27d238ba1f0d56dfe21.tar cuberite-d00ebd7ee700fcd7f30ea27d238ba1f0d56dfe21.tar.gz cuberite-d00ebd7ee700fcd7f30ea27d238ba1f0d56dfe21.tar.bz2 cuberite-d00ebd7ee700fcd7f30ea27d238ba1f0d56dfe21.tar.lz cuberite-d00ebd7ee700fcd7f30ea27d238ba1f0d56dfe21.tar.xz cuberite-d00ebd7ee700fcd7f30ea27d238ba1f0d56dfe21.tar.zst cuberite-d00ebd7ee700fcd7f30ea27d238ba1f0d56dfe21.zip |
Diffstat (limited to 'src/OSSupport/CriticalSection.cpp')
-rw-r--r-- | src/OSSupport/CriticalSection.cpp | 52 |
1 files changed, 7 insertions, 45 deletions
diff --git a/src/OSSupport/CriticalSection.cpp b/src/OSSupport/CriticalSection.cpp index 5dfc8b5f9..13a3e4d9f 100644 --- a/src/OSSupport/CriticalSection.cpp +++ b/src/OSSupport/CriticalSection.cpp @@ -1,6 +1,5 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules -#include "IsThread.h" @@ -9,41 +8,12 @@ //////////////////////////////////////////////////////////////////////////////// // cCriticalSection: +#ifdef _DEBUG cCriticalSection::cCriticalSection() { - #ifdef _WIN32 - InitializeCriticalSection(&m_CriticalSection); - #else - pthread_mutexattr_init(&m_Attributes); - pthread_mutexattr_settype(&m_Attributes, PTHREAD_MUTEX_RECURSIVE); - - if (pthread_mutex_init(&m_CriticalSection, &m_Attributes) != 0) - { - LOGERROR("Could not initialize Critical Section!"); - } - #endif - - #ifdef _DEBUG - m_IsLocked = 0; - #endif // _DEBUG -} - - - - - -cCriticalSection::~cCriticalSection() -{ - #ifdef _WIN32 - DeleteCriticalSection(&m_CriticalSection); - #else - if (pthread_mutex_destroy(&m_CriticalSection) != 0) - { - LOGWARNING("Could not destroy Critical Section!"); - } - pthread_mutexattr_destroy(&m_Attributes); - #endif + m_IsLocked = 0; } +#endif // _DEBUG @@ -51,15 +21,11 @@ cCriticalSection::~cCriticalSection() void cCriticalSection::Lock() { - #ifdef _WIN32 - EnterCriticalSection(&m_CriticalSection); - #else - pthread_mutex_lock(&m_CriticalSection); - #endif + m_Mutex.lock(); #ifdef _DEBUG m_IsLocked += 1; - m_OwningThreadID = cIsThread::GetCurrentID(); + m_OwningThreadID = std::this_thread::get_id(); #endif // _DEBUG } @@ -74,11 +40,7 @@ void cCriticalSection::Unlock() m_IsLocked -= 1; #endif // _DEBUG - #ifdef _WIN32 - LeaveCriticalSection(&m_CriticalSection); - #else - pthread_mutex_unlock(&m_CriticalSection); - #endif + m_Mutex.unlock(); } @@ -97,7 +59,7 @@ bool cCriticalSection::IsLocked(void) bool cCriticalSection::IsLockedByCurrentThread(void) { - return ((m_IsLocked > 0) && (m_OwningThreadID == cIsThread::GetCurrentID())); + return ((m_IsLocked > 0) && (m_OwningThreadID == std::this_thread::get_id())); } #endif // _DEBUG |