Do the tryLocal/addPeers operations on an InboundLedger without the collection lock.

This commit is contained in:
David Schwartz
2013-10-03 16:36:33 -07:00
parent b3b22d7595
commit 647c0e302a
4 changed files with 24 additions and 17 deletions

View File

@@ -58,6 +58,27 @@ InboundLedger::~InboundLedger ()
{
}
void InboundLedger::init(ScopedLockType& collectionLock, bool couldBeNew)
{
ScopedLockType sl (mLock, __FILE__, __LINE__);
collectionLock.unlock ();
if (!tryLocal ())
{
addPeers ();
setTimer ();
}
else if (!isFailed ())
{
WriteLog (lsDEBUG, InboundLedger) << "Acquiring ledger we already have locally: " << getHash ();
mLedger->setClosed ();
mLedger->setImmutable ();
getApp ().getLedgerMaster ().storeLedger (mLedger);
if (couldBeNew)
getApp ().getLedgerMaster ().checkAccept (mLedger);
}
}
bool InboundLedger::tryLocal ()
{
// return value: true = no more work to do

View File

@@ -83,6 +83,7 @@ public:
void awaitData ();
void noAwaitData ();
bool checkLocal ();
void init(ScopedLockType& collectionLock, bool couldBeNew);
typedef std::pair <protocol::TMGetObjectByHash::ObjectType, uint256> neededHash_t;

View File

@@ -48,22 +48,7 @@ InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 s
ret = boost::make_shared<InboundLedger> (hash, seq);
assert (ret);
mLedgers.insert (std::make_pair (hash, ret));
if (!ret->tryLocal())
{
ret->addPeers ();
ret->setTimer (); // Cannot call in constructor
}
else if (!ret->isFailed ())
{
WriteLog (lsDEBUG, InboundLedger) << "Acquiring ledger we already have locally: " << hash;
Ledger::pointer ledger = ret->getLedger ();
ledger->setClosed ();
ledger->setImmutable ();
getApp().getLedgerMaster ().storeLedger (ledger);
if (couldBeNew)
getApp().getLedgerMaster().checkAccept(ledger);
}
ret->init (sl, couldBeNew);
}
}
}

View File

@@ -81,7 +81,7 @@ public:
private:
typedef boost::unordered_map <uint256, InboundLedger::pointer> MapType;
typedef RippleMutex LockType;
typedef RippleRecursiveMutex LockType;
typedef LockType::ScopedLockType ScopedLockType;
LockType mLock;