Index: ext/libicpf/src/dmutex.cpp =================================================================== diff -u --- ext/libicpf/src/dmutex.cpp (revision 0) +++ ext/libicpf/src/dmutex.cpp (revision e39a4610720bbf5b718bac51c635248ca0054844) @@ -0,0 +1,73 @@ +#include "dmutex.h" +#include +#include + +BEGIN_ICPF_NAMESPACE + +/////////////////////////////////////////////////////////////// +// debuggable mutex + +d_mutex::d_mutex(dumpctx* pctx) + : mutex() +{ + const char_t* psz="Unnamed"; + m_pszName=new char_t[strlen(psz)+1]; + strcpy(m_pszName, psz); + + m_pContext=pctx; + + m_ulLockCount=0; +} + +d_mutex::d_mutex(const char_t* pszStr, dumpctx* pctx) : + mutex(pszStr) +{ + m_pszName=new char_t[strlen(pszStr)+1]; + strcpy(m_pszName, pszStr); + + m_pContext=pctx; +} + +d_mutex::~d_mutex() +{ + delete [] m_pszName; +} + +bool d_mutex::lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) +{ + assert(m_pContext); + + ((mutex*)this)->lock(); + + m_ulLockCount++; + + // log the attempt and lock it + char_t sz[512]; + sprintf(sz, "%s: Lock (lock count after operation: %lu) in (%s-%lu: %s)", m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + + m_pContext->open(sz); + m_pContext->close(); + + return true; +} + +bool d_mutex::unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) +{ + assert(m_pContext); + + // log the attempt and lock it + m_ulLockCount--; + + // log the attempt and lock it + char_t sz[512]; + sprintf(sz, "%s: Unlock (lock count after operation: %lu) in (%s-%lu: %s)", m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + + m_pContext->open(sz); + m_pContext->close(); + + ((mutex*)this)->unlock(); + + return true; +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/dmutex.h =================================================================== diff -u --- ext/libicpf/src/dmutex.h (revision 0) +++ ext/libicpf/src/dmutex.h (revision e39a4610720bbf5b718bac51c635248ca0054844) @@ -0,0 +1,36 @@ +#ifndef __DMUTEX_H__ +#define __DMUTEX_H__ + +#include "libicpf.h" +#include "gen_types.h" +#include "dumpctx.h" +#include "mutex.h" + +BEGIN_ICPF_NAMESPACE + +class LIBICPF_API d_mutex : public mutex +{ +public: +/** \name Construction/destruction */ +/**@{*/ + d_mutex(dumpctx* pctx); + d_mutex(const char_t* pszStr, dumpctx* pctx); + ~d_mutex(); +/**@}*/ + + // standard locking +/** \name Locking/unlocking */ +/**@{*/ + bool lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); + bool unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); +/**@}*/ + +private: + char* m_pszName; + dumpctx* m_pContext; + ulong_t m_ulLockCount; +}; + +END_ICPF_NAMESPACE + +#endif