mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
Move shared_ptr releases to outside the lock in InboundLedgers::sweep
This commit is contained in:
@@ -221,23 +221,41 @@ void InboundLedgers::sweep ()
|
|||||||
{
|
{
|
||||||
mRecentFailures.sweep ();
|
mRecentFailures.sweep ();
|
||||||
|
|
||||||
int now = UptimeTimer::getInstance ().getElapsedSeconds ();
|
int const now = UptimeTimer::getInstance ().getElapsedSeconds ();
|
||||||
boost::mutex::scoped_lock sl (mLock);
|
|
||||||
|
|
||||||
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;
|
||||||
while (it != mLedgers.end ())
|
std::size_t total;
|
||||||
{
|
{
|
||||||
if (it->second->getLastAction () > now)
|
boost::mutex::scoped_lock sl (mLock);
|
||||||
|
MapType::iterator it (mLedgers.begin ());
|
||||||
|
total = mLedgers.size ();
|
||||||
|
stuffToSweep.reserve (total);
|
||||||
|
|
||||||
|
while (it != mLedgers.end ())
|
||||||
{
|
{
|
||||||
it->second->touch ();
|
if (it->second->getLastAction () > now)
|
||||||
++it;
|
{
|
||||||
|
it->second->touch ();
|
||||||
|
++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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ((it->second->getLastAction () + 60) < now)
|
|
||||||
it = mLedgers.erase (it);
|
|
||||||
else
|
|
||||||
++it;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WriteLog (lsDEBUG, InboundLedger) <<
|
||||||
|
"Sweeped " << stuffToSweep.size () <<
|
||||||
|
" out of " << total << " inbound ledgers.";
|
||||||
}
|
}
|
||||||
|
|
||||||
int InboundLedgers::getFetchCount (int& timeoutCount)
|
int InboundLedgers::getFetchCount (int& timeoutCount)
|
||||||
|
|||||||
@@ -64,8 +64,10 @@ public:
|
|||||||
void sweep ();
|
void sweep ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
typedef boost::unordered_map <uint256, InboundLedger::pointer> MapType;
|
||||||
|
|
||||||
boost::mutex mLock;
|
boost::mutex mLock;
|
||||||
boost::unordered_map <uint256, InboundLedger::pointer> mLedgers;
|
MapType mLedgers;
|
||||||
KeyCache <uint256, UptimeTimerAdapter> mRecentFailures;
|
KeyCache <uint256, UptimeTimerAdapter> mRecentFailures;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user