- added a very useful way to track mutex usage and performance timings of mutex locking to discover thread lock issues

This commit is contained in:
Mark Vejvoda
2011-01-31 23:01:39 +00:00
parent b8075eaf01
commit 0b4eef10c5
15 changed files with 195 additions and 172 deletions

View File

@@ -15,17 +15,22 @@
#include <SDL_thread.h>
#include <SDL_mutex.h>
#include <string>
#include "platform_common.h"
//#include "util.h"
#include "leak_dumper.h"
//#define DEBUG_MUTEXES
//#define DEBUG_PERFORMANCE_MUTEXES
// =====================================================
// class Thread
// =====================================================
using namespace std;
using namespace Shared::PlatformCommon;
namespace Shared{ namespace Platform{
namespace Shared { namespace Platform {
class Thread{
public:
@@ -75,6 +80,10 @@ class MutexSafeWrapper {
protected:
Mutex *mutex;
string ownerId;
#ifdef DEBUG_PERFORMANCE_MUTEXES
Chrono chrono;
#endif
public:
MutexSafeWrapper(Mutex *mutex,string ownerId="") {
@@ -103,8 +112,17 @@ public:
}
#endif
#ifdef DEBUG_PERFORMANCE_MUTEXES
chrono.start();
#endif
this->mutex->p();
#ifdef DEBUG_PERFORMANCE_MUTEXES
if(chrono.getMillis() > 5) printf("In [%s::%s Line: %d] MUTEX LOCK took msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),this->mutex->getRefCount(),ownerId.c_str());
chrono.start();
#endif
#ifdef DEBUG_MUTEXES
if(ownerId != "") {
printf("Locked Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount());
@@ -122,6 +140,10 @@ public:
this->mutex->v();
#ifdef DEBUG_PERFORMANCE_MUTEXES
if(chrono.getMillis() > 100) printf("In [%s::%s Line: %d] MUTEX UNLOCKED and held locked for msecs: %lld, this->mutex->getRefCount() = %d ownerId [%s]\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),this->mutex->getRefCount(),ownerId.c_str());
#endif
#ifdef DEBUG_MUTEXES
if(ownerId != "") {
printf("UnLocked Mutex [%s] refCount: %d\n",ownerId.c_str(),this->mutex->getRefCount());