Skip to content

Commit

Permalink
Marked the empty_roots array mutable, simplified locking to use LOCK …
Browse files Browse the repository at this point in the history
…only (no more double-locking), and simplified CCriticalSection variable name.
  • Loading branch information
zebambam committed Sep 11, 2019
1 parent 502507e commit cf89467
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/zcash/IncrementalMerkleTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,14 @@ template<size_t Depth, typename Hash>
class EmptyMerkleRoots {
public:
void initialize() {
LOCK(cs);
if (!initialized) {
LOCK(cs_EmptyMerkleRoots_private_variables_write);
if (!initialized) {
empty_roots.at(0) = Hash::uncommitted();
for (size_t d = 1; d <= Depth; d++) {
empty_roots.at(d) = Hash::combine(empty_roots.at(d-1), empty_roots.at(d-1), d-1);
}
initialized = true;
}
}
}
}
EmptyMerkleRoots() { initialized = false; }
Hash empty_root(size_t depth) {
Expand All @@ -79,9 +77,9 @@ class EmptyMerkleRoots {
friend bool operator==(const EmptyMerkleRoots<D, H>& a,
const EmptyMerkleRoots<D, H>& b);
private:
CCriticalSection cs_EmptyMerkleRoots_private_variables_write;
bool initialized;
std::array<Hash, Depth+1> empty_roots;
CCriticalSection cs;
mutable bool initialized;
mutable std::array<Hash, Depth+1> empty_roots;
};

template<size_t Depth, typename Hash>
Expand Down

0 comments on commit cf89467

Please sign in to comment.