fixed thread issue in RsGxsCleanupThread that caused random crashes

This commit is contained in:
csoler 2017-06-12 20:36:02 +02:00
parent 1766087f71
commit 79825eb2e2
3 changed files with 88 additions and 81 deletions

View File

@ -190,18 +190,29 @@ void RsGenExchange::tick()
now = time(NULL);
if(mChecking || (mLastCheck + INTEGRITY_CHECK_PERIOD < now))
{
if(mIntegrityCheck)
mLastCheck = time(NULL);
{
RS_STACK_MUTEX(mGenMtx) ;
if(!mIntegrityCheck)
{
mIntegrityCheck = new RsGxsIntegrityCheck(mDataStore,this,mGixs);
mIntegrityCheck->start("gxs integrity");
mChecking = true;
}
}
if(mIntegrityCheck->isDone())
{
RS_STACK_MUTEX(mGenMtx) ;
std::list<RsGxsGroupId> grpIds;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgIds;
mIntegrityCheck->getDeletedIds(grpIds, msgIds);
if (!grpIds.empty())
{
RS_STACK_MUTEX(mGenMtx) ;
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PROCESSED, false);
gc->mGrpIdList = grpIds;
#ifdef GEN_EXCH_DEBUG
@ -217,9 +228,8 @@ void RsGenExchange::tick()
mNetService->removeGroups(grpIds) ;
}
if (!msgIds.empty()) {
RS_STACK_MUTEX(mGenMtx) ;
if (!msgIds.empty())
{
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_PROCESSED, false);
c->msgChangeMap = msgIds;
mNotifications.push_back(c);
@ -227,17 +237,9 @@ void RsGenExchange::tick()
delete mIntegrityCheck;
mIntegrityCheck = NULL;
mLastCheck = time(NULL);
mChecking = false;
}
}
else
{
mIntegrityCheck = new RsGxsIntegrityCheck(mDataStore,this,mGixs);
mIntegrityCheck->start("gxs integrity");
mChecking = true;
}
}
}
bool RsGenExchange::messagePublicationTest(const RsGxsMsgMetaData& meta)

View File

@ -136,6 +136,9 @@ RsGxsIntegrityCheck::RsGxsIntegrityCheck(RsGeneralDataService* const dataService
void RsGxsIntegrityCheck::run()
{
check();
RsStackMutex stack(mIntegrityMutex);
mDone = true;
}
bool RsGxsIntegrityCheck::check()
@ -286,8 +289,8 @@ bool RsGxsIntegrityCheck::check()
mDs->removeMsgs(msgsToDel);
{
RsStackMutex stack(mIntegrityMutex);
mDone = true;
std::vector<RsGxsGroupId>::iterator grpIt;
for(grpIt = grpsToDel.begin(); grpIt != grpsToDel.end(); ++grpIt)
@ -351,6 +354,7 @@ bool RsGxsIntegrityCheck::check()
#ifdef DEBUG_GXSUTIL
GXSUTIL_DEBUG() << " total actual cache requests: "<< nb_requested_not_in_cache << std::endl;
#endif
}
return true;
}

View File

@ -179,6 +179,7 @@ void RsThread::start(const std::string &threadName)
THREAD_DEBUG << "pqithreadstreamer::start() initing should_stop=0" << std::endl;
#endif
mShouldStopSemaphore.set(0) ;
mHasStoppedSemaphore.set(0) ;
int err ;