refactor: consolidate 3 separate locks into one block
The main lock needs to be taken 3 separate times. It simplifies readability to take it once, and is more efficient.
This commit is contained in:
1 parent
41479ed1d2
commit
c1e554d3e5
1 file changed
+7
-2
+7
-2
@@ -3560,10 +3560,12 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
|
|||||||
} // release cs_main
|
} // release cs_main
|
||||||
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
|
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
|
||||||
|
|
||||||
|
bool disabled{false};
|
||||||
|
{
|
||||||
|
LOCK(m_chainman.GetMutex());
|
||||||
if (exited_ibd) {
|
if (exited_ibd) {
|
||||||
// If a background chainstate is in use, we may need to rebalance our
|
// If a background chainstate is in use, we may need to rebalance our
|
||||||
// allocation of caches once a chainstate exits initial block download.
|
// allocation of caches once a chainstate exits initial block download.
|
||||||
LOCK(::cs_main);
|
|
||||||
m_chainman.MaybeRebalanceCaches();
|
m_chainman.MaybeRebalanceCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3572,7 +3574,10 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WITH_LOCK(::cs_main, return m_disabled)) {
|
disabled = m_disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disabled) {
|
||||||
// Background chainstate has reached the snapshot base block, so exit.
|
// Background chainstate has reached the snapshot base block, so exit.
|
||||||
|
|
||||||
// Restart indexes to resume indexing for all blocks unique to the snapshot
|
// Restart indexes to resume indexing for all blocks unique to the snapshot
|
||||||
|
|||||||
Reference in new issue
Block a user