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

View File

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