diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 8a2c7cc33a..919b467805 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -17,6 +17,18 @@ SHAMap::SHAMap(uint32 seq) : mSeq(seq), mState(Modifying) mTNByID[*root] = root; } +SHAMap::pointer SHAMap::snapShot() +{ // Return a new SHAMap that is a snapshot of this one + // Initially nodes are shared, but CoW is forced on both ledgers + SHAMap::pointer ret = boost::make_shared(); + SHAMap& newMap = *ret; + newMap.mSeq = ++mSeq; + newMap.mTNByID = mTNByID; + newMap.root = root; + newMap.mState = Immutable; + return ret; +} + std::stack SHAMap::getStack(const uint256& id, bool include_nonmatching_leaf) { // Walk the tree as far as possible to the specified identifier @@ -142,7 +154,7 @@ void SHAMap::returnNode(SHAMapTreeNode::pointer& node, bool modify) { // make sure the node is suitable for the intended operation (copy on write) assert(node->isValid()); if (node && modify && (node->getSeq() != mSeq)) - { + { // have a CoW #ifdef DEBUG std::cerr << "returnNode COW" << std::endl; #endif diff --git a/src/SHAMap.h b/src/SHAMap.h index 836d4f97a2..182a54a5ec 100644 --- a/src/SHAMap.h +++ b/src/SHAMap.h @@ -258,6 +258,9 @@ public: // build new map SHAMap(uint32 seq = 0); + // Returns a new map that's a snapshot of this one. Force CoW + SHAMap::pointer snapShot(); + // hold the map stable across operations ScopedLock Lock() const { return ScopedLock(mLock); }