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
// 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 ;
time_t now = time(NULL) ;
std::list<RsGxsId> ids_to_check_for_last_usage_ts;
{
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
for(std::map<RsGxsId,Reputation>::iterator it(mReputations.begin());it!=mReputations.end();)
@ -359,19 +363,24 @@ void p3GxsReputation::cleanup()
#endif
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
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
std::map<RsGxsId,Reputation>::iterator tmp(it) ;
++tmp ;
mReputations.erase(it) ;
it = tmp ;
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
mReputations.erase(*it) ;
updated = true ;
}
else
++it ;
if(updated)
IndicateConfigChanged() ;