Index: ext/libicpf/src/mutex.cpp =================================================================== diff -u -N -r338a33bbdb8c82416f0351408eea3243520784e5 -re794066b77a356d36056bf2541bc7076c4f1887c --- ext/libicpf/src/mutex.cpp (.../mutex.cpp) (revision 338a33bbdb8c82416f0351408eea3243520784e5) +++ ext/libicpf/src/mutex.cpp (.../mutex.cpp) (revision e794066b77a356d36056bf2541bc7076c4f1887c) @@ -1,111 +1,75 @@ #include "mutex.h" -#ifdef _WIN32 - #include -#else - #include -#endif BEGIN_ICPF_NAMESPACE -#ifdef _WIN32 - #define m_pcsLock ((CRITICAL_SECTION*)m_pLock) -#else - #define m_pmLock ((pthread_mutex_t*)m_pLock) -#endif - -/** Standard constructor. - */ -mutex::mutex() : - m_pLock(NULL) +mutex::mutex() { - construct(); -} - -/** Compatibility layer constructor (with d_mutex). Can take a fake dumpctx pointer and a fake mutex name, - * although does nothing with it. Effectively it is almost the same as standard constructor. - */ -mutex::mutex(const char_t* /*pszStr*/) : - m_pLock(NULL) -{ - construct(); -} - -/** Destructs the mutex. - */ -mutex::~mutex() -{ #ifdef _WIN32 - ::DeleteCriticalSection(m_pcsLock); - delete m_pcsLock; + ::InitializeCriticalSection(&m_cs); #else - pthread_mutex_destroy(m_pmLock); - delete m_pmLock; + pthread_mutexattr_t mta; + pthread_mutexattr_init(&mta); +//#warning Recursive mutexes are disabled; Make sure you use them the right way. + pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutex_init(&m_mutex, &mta); + + pthread_mutexattr_destroy(&mta); #endif } -/** Performs a construction of this mutex. Used by every constructor to alloc the internal members - * and initialize it. - */ -void mutex::construct() +mutex::mutex(const char_t* /*pszStr*/) { #ifdef _WIN32 - m_pLock=(void*)new CRITICAL_SECTION; - ::InitializeCriticalSection(m_pcsLock); + ::InitializeCriticalSection(&m_cs); #else - m_pLock=(void*)new pthread_mutex_t; - pthread_mutexattr_t mta; pthread_mutexattr_init(&mta); +//#warning Recursive mutexes are disabled; Make sure you use them the right way. pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE_NP); - pthread_mutex_init(m_pmLock, &mta); + pthread_mutex_init(&m_mutex, &mta); pthread_mutexattr_destroy(&mta); #endif } -/** Locks this mutex using an underlying, system-dependent locking mechanism. - */ +mutex::~mutex() +{ +#ifdef _WIN32 + ::DeleteCriticalSection(&m_cs); +#else + pthread_mutex_destroy(&m_mutex); +#endif +} + +// standard locking void mutex::lock() { #ifdef _WIN32 - ::EnterCriticalSection(m_pcsLock); + ::EnterCriticalSection(&m_cs); #else - pthread_mutex_lock(m_pmLock); + pthread_mutex_lock(&m_mutex) == 0; #endif } -/** Unlocks this mutex using an underlying, system-dependent locking mechanism. - */ void mutex::unlock() { #ifdef _WIN32 - ::LeaveCriticalSection(m_pcsLock); + ::LeaveCriticalSection(&m_cs); #else - pthread_mutex_unlock(m_pmLock); + pthread_mutex_unlock(&m_mutex) == 0; // return 0 on success #endif } #ifdef ENABLE_MUTEX_DEBUGGING -/** Locks this mutex using an underlying, system-dependent locking mechanism. - * This is a compatibility layer over d_mutex. This class does not use any of the - * parameters given - they are only to allow seamless migration to/from the d_mutex. - * \see MLOCK and MUNLOCK macros. - */ -void mutex::lock(const char_t* /*pszFile*/, ulong_t /*ulLine*/, const char_t* /*pszFunction*/) +void mutex::lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) { lock(); } -/** Unlocks this mutex using an underlying, system-dependent locking mechanism. - * This is a compatibility layer over d_mutex. This class does not use any of the - * parameters given - they are only to allow seamless migration to/from the d_mutex. - * \see MLOCK and MUNLOCK macros. - */ -void mutex::unlock(const char_t* /*pszFile*/, ulong_t /*ulLine*/, const char_t* /*pszFunction*/) +void mutex::unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) { unlock(); } - #endif END_ICPF_NAMESPACE