- bugfixes, some related to things pointed out by valgrind, some from opengl research and some for more stable operation

This commit is contained in:
Mark Vejvoda
2011-02-12 07:34:32 +00:00
parent d056486ec4
commit cc973f3427
13 changed files with 238 additions and 96 deletions

View File

@@ -49,14 +49,16 @@ Mutex * BaseThread::getMutexThreadOwnerValid() {
}
void BaseThread::setThreadOwnerValid(bool value) {
MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,mutexOwnerId);
threadOwnerValid = value;
safeMutex.ReleaseLock();
}
bool BaseThread::getThreadOwnerValid() {
bool ret = false;
MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexThreadOwnerValid,mutexOwnerId);
ret = threadOwnerValid;
safeMutex.ReleaseLock();
@@ -64,17 +66,18 @@ bool BaseThread::getThreadOwnerValid() {
}
void BaseThread::signalQuit() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
setQuitStatus(true);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
}
void BaseThread::setQuitStatus(bool value) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
MutexSafeWrapper safeMutex(&mutexQuit,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexQuit,mutexOwnerId);
quit = value;
safeMutex.ReleaseLock();
@@ -85,7 +88,8 @@ bool BaseThread::getQuitStatus() {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool retval = false;
MutexSafeWrapper safeMutex(&mutexQuit,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexQuit,mutexOwnerId);
retval = quit;
safeMutex.ReleaseLock();
@@ -96,7 +100,8 @@ bool BaseThread::getQuitStatus() {
bool BaseThread::getHasBeginExecution() {
bool retval = false;
MutexSafeWrapper safeMutex(&mutexBeginExecution,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexBeginExecution,mutexOwnerId);
retval = hasBeginExecution;
safeMutex.ReleaseLock();
@@ -108,7 +113,8 @@ bool BaseThread::getHasBeginExecution() {
void BaseThread::setHasBeginExecution(bool value) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
MutexSafeWrapper safeMutex(&mutexBeginExecution,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexBeginExecution,mutexOwnerId);
hasBeginExecution = value;
safeMutex.ReleaseLock();
@@ -119,7 +125,9 @@ bool BaseThread::getRunningStatus() {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
bool retval = false;
MutexSafeWrapper safeMutex(&mutexRunning,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexRunning,mutexOwnerId);
retval = running;
safeMutex.ReleaseLock();
@@ -133,25 +141,30 @@ bool BaseThread::getRunningStatus() {
}
void BaseThread::setRunningStatus(bool value) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] value = %d\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),value);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] value = %d\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),value);
MutexSafeWrapper safeMutex(&mutexRunning,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexRunning,mutexOwnerId);
running = value;
setHasBeginExecution(true);
if(value == true) {
setHasBeginExecution(true);
}
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
}
void BaseThread::setExecutingTask(bool value) {
MutexSafeWrapper safeMutex(&mutexExecutingTask,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexExecutingTask,mutexOwnerId);
executingTask = value;
safeMutex.ReleaseLock();
}
bool BaseThread::getExecutingTask() {
bool retval = false;
MutexSafeWrapper safeMutex(&mutexExecutingTask,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexExecutingTask,mutexOwnerId);
retval = executingTask;
safeMutex.ReleaseLock();
@@ -160,7 +173,8 @@ bool BaseThread::getExecutingTask() {
bool BaseThread::getDeleteSelfOnExecutionDone() {
bool retval = false;
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,mutexOwnerId);
retval = deleteSelfOnExecutionDone;
safeMutex.ReleaseLock();
@@ -168,7 +182,8 @@ bool BaseThread::getDeleteSelfOnExecutionDone() {
}
void BaseThread::setDeleteSelfOnExecutionDone(bool value) {
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexDeleteSelfOnExecutionDone,mutexOwnerId);
deleteSelfOnExecutionDone = value;
}
@@ -218,14 +233,11 @@ bool BaseThread::shutdownAndWait() {
}
sleep(0);
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
//sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
sleep(0);
}
}
//sleep(0);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
return ret;
}

View File

@@ -87,13 +87,15 @@ SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInter
this->needTaskSignal = needTaskSignal;
setTaskSignalled(false);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId);
lastExecuteTimestamp = time(NULL);
}
bool SimpleTaskThread::isThreadExecutionLagging() {
bool result = false;
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId);
result = (difftime(time(NULL),lastExecuteTimestamp) >= 5.0);
safeMutex.ReleaseLock();
@@ -111,6 +113,7 @@ bool SimpleTaskThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
}
void SimpleTaskThread::execute() {
bool mustDeleteSelf = false;
{
{
RunningStatusSafeWrapper runningStatus(this);
@@ -141,7 +144,8 @@ void SimpleTaskThread::execute() {
ExecutingTaskSafeWrapper safeExecutingTaskMutex(this);
this->simpleTaskInterface->simpleTask(this);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp,mutexOwnerId);
lastExecuteTimestamp = time(NULL);
safeMutex.ReleaseLock();
}
@@ -174,14 +178,19 @@ void SimpleTaskThread::execute() {
}
}
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s] END\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
mustDeleteSelf = getDeleteSelfOnExecutionDone();
}
if(mustDeleteSelf == true) {
delete this;
}
deleteSelfIfRequired();
}
void SimpleTaskThread::setTaskSignalled(bool value) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&mutexTaskSignaller,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexTaskSignaller,mutexOwnerId);
taskSignalled = value;
safeMutex.ReleaseLock();
@@ -192,7 +201,8 @@ bool SimpleTaskThread::getTaskSignalled() {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool retval = false;
MutexSafeWrapper safeMutex(&mutexTaskSignaller,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexTaskSignaller,mutexOwnerId);
retval = taskSignalled;
safeMutex.ReleaseLock();
@@ -209,7 +219,8 @@ LogFileThread::LogFileThread() : BaseThread() {
}
void LogFileThread::addLogEntry(SystemFlags::DebugType type, string logEntry) {
MutexSafeWrapper safeMutex(&mutexLogList,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLogList,mutexOwnerId);
LogFileEntry entry;
entry.type = type;
entry.entry = logEntry;
@@ -233,6 +244,7 @@ bool LogFileThread::checkSaveCurrentLogBufferToDisk() {
}
void LogFileThread::execute() {
bool mustDeleteSelf = false;
{
RunningStatusSafeWrapper runningStatus(this);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -270,19 +282,25 @@ void LogFileThread::execute() {
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is exiting\n",__FILE__,__FUNCTION__,__LINE__);
mustDeleteSelf = getDeleteSelfOnExecutionDone();
}
if(mustDeleteSelf == true) {
delete this;
}
deleteSelfIfRequired();
}
std::size_t LogFileThread::getLogEntryBufferCount() {
MutexSafeWrapper safeMutex(&mutexLogList,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(&mutexLogList,mutexOwnerId);
std::size_t logCount = logList.size();
safeMutex.ReleaseLock();
return logCount;
}
void LogFileThread::saveToDisk(bool forceSaveAll,bool logListAlreadyLocked) {
MutexSafeWrapper safeMutex(NULL,string(__FILE__) + "_" + intToStr(__LINE__));
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
MutexSafeWrapper safeMutex(NULL,mutexOwnerId);
if(logListAlreadyLocked == false) {
safeMutex.setMutex(&mutexLogList);
}