Move shared_ptr releases to outside the lock in InboundLedgers::sweep

This commit is contained in:
Vinnie Falco
2013-08-22 15:09:42 -07:00
parent 35836c9896
commit 382b358bdf
2 changed files with 33 additions and 13 deletions

View File

@@ -221,10 +221,16 @@ void InboundLedgers::sweep ()
{
mRecentFailures.sweep ();
int now = UptimeTimer::getInstance ().getElapsedSeconds ();
boost::mutex::scoped_lock sl (mLock);
int const now = UptimeTimer::getInstance ().getElapsedSeconds ();
boost::unordered_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.begin ();
// Make a list of things to sweep, while holding the lock
std::vector <MapType::mapped_type> stuffToSweep;
std::size_t total;
{
boost::mutex::scoped_lock sl (mLock);
MapType::iterator it (mLedgers.begin ());
total = mLedgers.size ();
stuffToSweep.reserve (total);
while (it != mLedgers.end ())
{
@@ -234,11 +240,23 @@ void InboundLedgers::sweep ()
++it;
}
else if ((it->second->getLastAction () + 60) < now)
{
stuffToSweep.push_back (it->second);
// shouldn't cause the actual final delete
// since we are holding a reference in the vector.
it = mLedgers.erase (it);
}
else
{
++it;
}
}
}
WriteLog (lsDEBUG, InboundLedger) <<
"Sweeped " << stuffToSweep.size () <<
" out of " << total << " inbound ledgers.";
}
int InboundLedgers::getFetchCount (int& timeoutCount)
{

View File

@@ -64,8 +64,10 @@ public:
void sweep ();
private:
typedef boost::unordered_map <uint256, InboundLedger::pointer> MapType;
boost::mutex mLock;
boost::unordered_map <uint256, InboundLedger::pointer> mLedgers;
MapType mLedgers;
KeyCache <uint256, UptimeTimerAdapter> mRecentFailures;
};