Index: ext/libicpf/src/mutex.h =================================================================== diff -u -re17c80d36eaa0430313e7d1058aa7a301d1510af -rd4269744a04d36c8a8146a84bc27118031fa42ac --- ext/libicpf/src/mutex.h (.../mutex.h) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/mutex.h (.../mutex.h) (revision d4269744a04d36c8a8146a84bc27118031fa42ac) @@ -19,21 +19,24 @@ ***************************************************************************/ /** \file mutex.h * \brief Contains mutex class for thread safe access. + * \see The d_mutex class. */ #ifndef __MUTEX_H__ #define __MUTEX_H__ -#ifdef _WIN32 - #include -#else - #include -#endif - #include "libicpf.h" #include "gen_types.h" BEGIN_ICPF_NAMESPACE +#ifdef _DEBUG_MUTEX + #define MLOCK(mutex) (mutex).lock(__FILE__, __LINE__, __FUNCTION__) + #define MUNLOCK(mutex) (mutex).unlock(__FILE__, __LINE__, __FUNCTION__) +#else + #define MLOCK(mutex) (mutex).lock() + #define MUNLOCK(mutex) (mutex).unlock() +#endif + /** \brief Class provides the locking and unlocking capabilities for use with threads. * * Class is a simple wrapper over the system related thread locking functions. In linux @@ -45,80 +48,32 @@ public: /** \name Construction/destruction */ /**@{*/ - /** \brief Standard constructor - */ - mutex() - { -#ifdef _WIN32 - ::InitializeCriticalSection(&m_cs); -#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); + mutex(); ///< Standard constructor + mutex(const char_t* /*pszStr*/); ///< Helper constructor, used as a compatibility layer with d_mutex - pthread_mutexattr_destroy(&mta); -#endif - }; - - /** \brief Standard destructor - */ - ~mutex() - { -#ifdef _WIN32 - ::DeleteCriticalSection(&m_cs); -#else - pthread_mutex_destroy(&m_mutex); -#endif - }; + virtual ~mutex(); ///< Standard destructor /**@}*/ - - // standard locking + /** \name Locking/unlocking */ /**@{*/ - - /** \brief Locks access to some part of code for the current thread - * - * Locks access to some code using the platform specific functions. - * \return True if succeeded or false if not. - * \note The call under windows always return true. - */ - bool lock() - { -#ifdef _WIN32 - ::EnterCriticalSection(&m_cs); - return true; -#else - return pthread_mutex_lock(&m_mutex) == 0; -#endif - }; - - /** \brief Unlock access to some locked part of code - * - * Unlocks access to some code using the platform specific functions. - * \return True if succeeded or false if not. - * \note The call under windows always return true. - */ - bool unlock() - { -#ifdef _WIN32 - ::LeaveCriticalSection(&m_cs); - return true; -#else - return pthread_mutex_unlock(&m_mutex) == 0; // return 0 on success -#endif - }; + void lock(); ///< Locks this mutex + void unlock(); ///< Unlocks this mutex + void lock(const char_t* /*pszFile*/, ulong_t /*ulLine*/, const char_t* /*pszFunction*/); ///< Locks this mutex (compatibility layer with d_mutex) + void unlock(const char_t* /*pszFile*/, ulong_t /*ulLine*/, const char_t* /*pszFunction*/); ///< Unlocks this mutex (compatibility layer with d_mutex) /**@}*/ protected: -#ifdef _WIN32 - /// Underlying windows locking structure - CRITICAL_SECTION m_cs; -#else - /// Underlying linux locking structure/handle - pthread_mutex_t m_mutex; -#endif + void construct(); ///< Helper function - initializes the internal members, used by constructors + +private: + void* m_pLock; ///< Pointer to a system-specific structure used to lock +//#ifdef _WIN32 +// /// Underlying windows locking structure +// CRITICAL_SECTION m_cs; +//#else +// /// Underlying linux locking structure/handle +// pthread_mutex_t m_mutex; +//#endif }; END_ICPF_NAMESPACE