summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-26 17:03:44 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-26 17:03:44 +0200
commit31a326382a1184f18cfea28515cd6496b25c72de (patch)
tree5694b6dbc16111e5bae5bc5be02e0a2bf4cf090d
parentFixed a valgrind warning in BlockDirt. (diff)
downloadcuberite-31a326382a1184f18cfea28515cd6496b25c72de.tar
cuberite-31a326382a1184f18cfea28515cd6496b25c72de.tar.gz
cuberite-31a326382a1184f18cfea28515cd6496b25c72de.tar.bz2
cuberite-31a326382a1184f18cfea28515cd6496b25c72de.tar.lz
cuberite-31a326382a1184f18cfea28515cd6496b25c72de.tar.xz
cuberite-31a326382a1184f18cfea28515cd6496b25c72de.tar.zst
cuberite-31a326382a1184f18cfea28515cd6496b25c72de.zip
-rw-r--r--source/OSSupport/CriticalSection.cpp54
-rw-r--r--source/OSSupport/CriticalSection.h4
2 files changed, 27 insertions, 31 deletions
diff --git a/source/OSSupport/CriticalSection.cpp b/source/OSSupport/CriticalSection.cpp
index f87a2b3ba..d83d7af02 100644
--- a/source/OSSupport/CriticalSection.cpp
+++ b/source/OSSupport/CriticalSection.cpp
@@ -11,19 +11,17 @@
cCriticalSection::cCriticalSection()
{
-#ifdef _WIN32
- InitializeCriticalSection( &m_CriticalSection );
-#else
- m_Attributes = new pthread_mutexattr_t;
- pthread_mutexattr_init((pthread_mutexattr_t*)m_Attributes);
- pthread_mutexattr_settype((pthread_mutexattr_t*)m_Attributes, PTHREAD_MUTEX_RECURSIVE);
-
- m_CriticalSectionPtr = new pthread_mutex_t;
- if( pthread_mutex_init( (pthread_mutex_t*)m_CriticalSectionPtr, (pthread_mutexattr_t*)m_Attributes ) != 0 )
- {
- LOG("ERROR: Could not initialize Critical Section!");
- }
-#endif
+ #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
}
@@ -32,17 +30,15 @@ cCriticalSection::cCriticalSection()
cCriticalSection::~cCriticalSection()
{
-#ifdef _WIN32
- DeleteCriticalSection( &m_CriticalSection );
-#else
- if( pthread_mutex_destroy( (pthread_mutex_t*)m_CriticalSectionPtr ) != 0 )
- {
- LOG("ERROR: Could not destroy Critical Section!");
- }
- delete (pthread_mutex_t*)m_CriticalSectionPtr;
- pthread_mutexattr_destroy( (pthread_mutexattr_t*)m_Attributes );
- delete (pthread_mutexattr_t*)m_Attributes;
-#endif
+ #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
}
@@ -52,9 +48,9 @@ cCriticalSection::~cCriticalSection()
void cCriticalSection::Lock()
{
#ifdef _WIN32
- EnterCriticalSection( &m_CriticalSection );
+ EnterCriticalSection(&m_CriticalSection);
#else
- pthread_mutex_lock( (pthread_mutex_t*)m_CriticalSectionPtr );
+ pthread_mutex_lock(&m_CriticalSection);
#endif
#ifdef _DEBUG
@@ -74,9 +70,9 @@ void cCriticalSection::Unlock()
#endif // _DEBUG
#ifdef _WIN32
- LeaveCriticalSection( &m_CriticalSection );
+ LeaveCriticalSection(&m_CriticalSection);
#else
- pthread_mutex_unlock( (pthread_mutex_t*)m_CriticalSectionPtr );
+ pthread_mutex_unlock(&m_CriticalSection);
#endif
}
@@ -96,7 +92,7 @@ bool cCriticalSection::IsLocked(void)
bool cCriticalSection::IsLockedByCurrentThread(void)
{
- return m_IsLocked && (m_OwningThreadID == cIsThread::GetCurrentID());
+ return (m_IsLocked && (m_OwningThreadID == cIsThread::GetCurrentID()));
}
#endif // _DEBUG
diff --git a/source/OSSupport/CriticalSection.h b/source/OSSupport/CriticalSection.h
index 9852a2e6c..c7607ee70 100644
--- a/source/OSSupport/CriticalSection.h
+++ b/source/OSSupport/CriticalSection.h
@@ -28,8 +28,8 @@ private:
#ifdef _WIN32
CRITICAL_SECTION m_CriticalSection;
#else // _WIN32
- void* m_CriticalSectionPtr ALIGN_8; // Pointer to a CRITICAL_SECTION object
- void* m_Attributes ALIGN_8;
+ pthread_mutex_t m_CriticalSection;
+ pthread_mutexattr_t m_Attributes;
#endif // else _WIN32
} ALIGN_8;