Index: ext/libicpf/src/mutex.cpp =================================================================== diff -u -N -r2b72d8a437d5843db8c14f68c8aa8484614d2f5b -r12de61bfcf4d1ffef0339bee2e4c4a152209fd30 --- ext/libicpf/src/mutex.cpp (.../mutex.cpp) (revision 2b72d8a437d5843db8c14f68c8aa8484614d2f5b) +++ ext/libicpf/src/mutex.cpp (.../mutex.cpp) (revision 12de61bfcf4d1ffef0339bee2e4c4a152209fd30) @@ -1,75 +1,111 @@ #include "mutex.h" +#ifdef _WIN32 + #include +#else + #include +#endif BEGIN_ICPF_NAMESPACE +#define m_pcsLock ((CRITICAL_SECTION*)m_pLock) +#define m_pmLock ((pthread_mutex_t*)m_pLock) + +/** Standard constructor. + */ mutex::mutex() { + construct(); +} + +/** Compatibility layer constructor (with d_mutex). Can take a fake dumpctx pointer, although + * does nothing with it. Effectively it is almost the same as standard constructor. + */ +mutex::mutex(void* /*pUnused*/) +{ + 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*/, void* /*pUnused*/) +{ + construct(); +} + +/** Destructs the mutex. + */ +mutex::~mutex() +{ #ifdef _WIN32 - ::InitializeCriticalSection(&m_cs); + ::DeleteCriticalSection(m_pcsLock); + delete m_pcsLock; #else - 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); + pthread_mutex_destroy(m_pmLock); + delete m_pmLock; #endif } -mutex::mutex(const char_t* /*pszStr*/) +/** Performs a construction of this mutex. Used by every constructor to alloc the internal members + * and initialize it. + */ +void mutex::construct() { #ifdef _WIN32 - ::InitializeCriticalSection(&m_cs); + m_pLock=(void*)new CRITICAL_SECTION; + ::InitializeCriticalSection(m_pcsLock); #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_mutex, &mta); + pthread_mutex_init(m_pmLock, &mta); pthread_mutexattr_destroy(&mta); #endif } -mutex::~mutex() +/** Locks this mutex using an underlying, system-dependent locking mechanism. + */ +void mutex::lock() { #ifdef _WIN32 - ::DeleteCriticalSection(&m_cs); + ::EnterCriticalSection(m_pcsLock); #else - pthread_mutex_destroy(&m_mutex); + pthread_mutex_lock(m_pmLock); #endif } - -// standard locking -bool mutex::lock() -{ -#ifdef _WIN32 - ::EnterCriticalSection(&m_cs); - return true; -#else - return pthread_mutex_lock(&m_mutex) == 0; -#endif -} -bool mutex::unlock() +/** Unlocks this mutex using an underlying, system-dependent locking mechanism. + */ +void mutex::unlock() { #ifdef _WIN32 - ::LeaveCriticalSection(&m_cs); - return true; + ::LeaveCriticalSection(m_pcsLock); #else - return pthread_mutex_unlock(&m_mutex) == 0; // return 0 on success + pthread_mutex_unlock(m_pmLock); #endif } -bool mutex::lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) +/** 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*/) { - return lock(); + lock(); } -bool mutex::unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) +/** 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*/) { - return unlock(); + unlock(); } END_ICPF_NAMESPACE