- attempt to speed up mutex lock / unlock

This commit is contained in:
SoftCoder
2015-12-28 23:06:12 -08:00
parent ac0c0eafb9
commit c1144ad9d7
2 changed files with 44 additions and 38 deletions

View File

@@ -139,8 +139,14 @@ public:
this->ownerId = ownerId; this->ownerId = ownerId;
} }
} }
void p(); inline void p() {
void v(); SDL_mutexP(mutex);
refCount++;
}
inline void v() {
refCount--;
SDL_mutexV(mutex);
}
inline int getRefCount() const { return refCount; } inline int getRefCount() const { return refCount; }
inline SDL_mutex* getMutex() { return mutex; } inline SDL_mutex* getMutex() { return mutex; }

View File

@@ -513,53 +513,53 @@ Mutex::~Mutex() {
// } // }
} }
void Mutex::p() { /*
if(mutex == NULL) { inline void Mutex::p() {
// if(mutex == NULL) {
string stack = PlatformExceptionHandler::getStackTrace(); // string stack = PlatformExceptionHandler::getStackTrace();
// char szBuf[8096]="";
char szBuf[8096]=""; // snprintf(szBuf,8095,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s] deleteownerId [%s] stack: %s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,refCount,ownerId.c_str(),deleteownerId.c_str(),stack.c_str());
snprintf(szBuf,8095,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s] deleteownerId [%s] stack: %s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,refCount,ownerId.c_str(),deleteownerId.c_str(),stack.c_str()); // throw megaglest_runtime_error(szBuf);
throw megaglest_runtime_error(szBuf); // }
} // std::auto_ptr<Chrono> chronoLockPerf;
std::auto_ptr<Chrono> chronoLockPerf; // if(debugMutexLock == true) {
if(debugMutexLock == true) { // chronoLockPerf.reset(new Chrono());
chronoLockPerf.reset(new Chrono()); // chronoLockPerf->start();
chronoLockPerf->start(); // }
}
// maxRefCount = max(maxRefCount,refCount+1); // maxRefCount = max(maxRefCount,refCount+1);
SDL_mutexP(mutex); SDL_mutexP(mutex);
refCount++; refCount++;
if(debugMutexLock == true) { // if(debugMutexLock == true) {
if(chronoLockPerf->getMillis() >= debugMutexLockMillisecondThreshold) { // if(chronoLockPerf->getMillis() >= debugMutexLockMillisecondThreshold) {
printf("\n**WARNING possible mutex lock detected ms [%lld] Last ownerid: [%s]\n",(long long int)chronoLockPerf->getMillis(),lastownerId.c_str()); // printf("\n**WARNING possible mutex lock detected ms [%lld] Last ownerid: [%s]\n",(long long int)chronoLockPerf->getMillis(),lastownerId.c_str());
} // }
chronoPerf->start(); // chronoPerf->start();
} // }
} }
void Mutex::v() { inline void Mutex::v() {
if(mutex == NULL) { // if(mutex == NULL) {
char szBuf[8096]=""; // char szBuf[8096]="";
snprintf(szBuf,8095,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s] deleteownerId [%s]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,refCount,ownerId.c_str(),deleteownerId.c_str()); // snprintf(szBuf,8095,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s] deleteownerId [%s]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,refCount,ownerId.c_str(),deleteownerId.c_str());
throw megaglest_runtime_error(szBuf); // throw megaglest_runtime_error(szBuf);
} // }
refCount--; refCount--;
if(debugMutexLock == true) { // if(debugMutexLock == true) {
lastownerId = ownerId; // lastownerId = ownerId;
if(chronoPerf->getMillis() >= debugMutexLockMillisecondThreshold) { // if(chronoPerf->getMillis() >= debugMutexLockMillisecondThreshold) {
printf("About to get stacktrace for stuck mutex ...\n"); // printf("About to get stacktrace for stuck mutex ...\n");
string oldLastownerId = lastownerId; // string oldLastownerId = lastownerId;
lastownerId = PlatformExceptionHandler::getStackTrace(); // lastownerId = PlatformExceptionHandler::getStackTrace();
//
printf("\n**WARNING possible mutex lock (on unlock) detected ms [%lld] Last ownerid: [%s]\noldLastownerId: [%s]\n",(long long int)chronoPerf->getMillis(),lastownerId.c_str(),oldLastownerId.c_str()); // printf("\n**WARNING possible mutex lock (on unlock) detected ms [%lld] Last ownerid: [%s]\noldLastownerId: [%s]\n",(long long int)chronoPerf->getMillis(),lastownerId.c_str(),oldLastownerId.c_str());
} // }
} // }
SDL_mutexV(mutex); SDL_mutexV(mutex);
} }
*/
// ===================================================== // =====================================================
// class Semaphore // class Semaphore