removed cross deadlock between p3GxsReputation and p3IdService

This commit is contained in:
csoler 2016-07-10 22:46:37 -04:00
parent 1c277ab81b
commit 95915fa31d

View File

@ -341,10 +341,14 @@ void p3GxsReputation::cleanup()
// remove optionions about identities that do not exist anymore. That will in particular avoid asking p3idservice about deleted // remove optionions about identities that do not exist anymore. That will in particular avoid asking p3idservice about deleted
// identities, which would cause an excess of hits to the database. // identities, which would cause an excess of hits to the database.
// We do it in two steps to avoid a deadlock when calling rsIdentity from here.
bool updated = false ; bool updated = false ;
time_t now = time(NULL) ; time_t now = time(NULL) ;
std::list<RsGxsId> ids_to_check_for_last_usage_ts;
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/ RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
for(std::map<RsGxsId,Reputation>::iterator it(mReputations.begin());it!=mReputations.end();) for(std::map<RsGxsId,Reputation>::iterator it(mReputations.begin());it!=mReputations.end();)
@ -359,19 +363,24 @@ void p3GxsReputation::cleanup()
#endif #endif
updated = true ; updated = true ;
} }
else if(rsIdentity->getLastUsageTS(it->first) + REPUTATION_INFO_KEEP_DELAY < now) else
{
ids_to_check_for_last_usage_ts.push_back(it->first) ;
++it;
}
}
for(std::list<RsGxsId>::const_iterator it(ids_to_check_for_last_usage_ts.begin());it!=ids_to_check_for_last_usage_ts.end();++it)
if(rsIdentity->getLastUsageTS(*it) + REPUTATION_INFO_KEEP_DELAY < now)
{ {
#ifdef DEBUG_REPUTATION #ifdef DEBUG_REPUTATION
std::cerr << " Identity " << it->first << " has a last usage TS of " << now - rsIdentity->getLastUsageTS(it->first) << " secs ago: deleting it." << std::endl; std::cerr << " Identity " << *it << " has a last usage TS of " << now - rsIdentity->getLastUsageTS(*it) << " secs ago: deleting it." << std::endl;
#endif #endif
std::map<RsGxsId,Reputation>::iterator tmp(it) ;
++tmp ; RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
mReputations.erase(it) ; mReputations.erase(*it) ;
it = tmp ;
updated = true ; updated = true ;
} }
else
++it ;
if(updated) if(updated)
IndicateConfigChanged() ; IndicateConfigChanged() ;