Change visitLeaves to visit a snapshot so the ledger stays unlocked

This commit is contained in:
David Schwartz
2013-12-03 10:29:16 -08:00
committed by JoelKatz
parent 0e53105ab5
commit b3c79f5c2f
2 changed files with 17 additions and 4 deletions

View File

@@ -238,6 +238,8 @@ private:
bool walkBranch (SHAMapTreeNode * node, SHAMapItem::ref otherMapItem, bool isFirstMap,
Delta & differences, int & maxCount);
void visitLeavesInternal (FUNCTION_TYPE<void (SHAMapItem::ref item)>& function);
private:
#if 1
LockType mLock;

View File

@@ -25,8 +25,16 @@ KeyCache <uint256, UptimeTimerAdapter> SHAMap::fullBelowCache ("fullBelowCache",
void SHAMap::visitLeaves (FUNCTION_TYPE<void (SHAMapItem::ref item)> function)
{
ScopedLockType sl (mLock, __FILE__, __LINE__);
SHAMap::pointer snap;
{
ScopedLockType sl (mLock, __FILE__, __LINE__);
snap = snapShot (false);
}
snap->visitLeavesInternal(function);
}
void SHAMap::visitLeavesInternal (FUNCTION_TYPE<void (SHAMapItem::ref item)>& function)
{
assert (root->isValid ());
if (!root || root->isEmpty ())
@@ -50,18 +58,21 @@ void SHAMap::visitLeaves (FUNCTION_TYPE<void (SHAMapItem::ref item)> function)
{
if (node->isEmptyBranch (pos))
++pos;
else
else
{
SHAMapTreeNode* child = getNodePointer (node->getChildNodeID (pos), node->getChildHash (pos));
if (child->isLeaf ())
{
function (child->peekItem ());
mTNByID.erase (*child); // don't need this leaf anymore
++pos;
}
else
{
if (pos != 15)
stack.push (posPair (pos + 1, node)); // save next position
else
mTNByID.erase (*node); // don't need this inner node anymore
node = child;
pos = 0;
@@ -72,8 +83,8 @@ void SHAMap::visitLeaves (FUNCTION_TYPE<void (SHAMapItem::ref item)> function)
if (stack.empty ())
break;
pos = stack.top ().first;
node = stack.top ().second;
stack.pop ();
node = stack.top ().second;
stack.pop ();
}
}