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
+16
-11
+16
-11
@@ -3560,19 +3560,24 @@ 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).
|
||||||
|
|
||||||
if (exited_ibd) {
|
bool disabled{false};
|
||||||
// If a background chainstate is in use, we may need to rebalance our
|
{
|
||||||
// allocation of caches once a chainstate exits initial block download.
|
LOCK(m_chainman.GetMutex());
|
||||||
LOCK(::cs_main);
|
if (exited_ibd) {
|
||||||
m_chainman.MaybeRebalanceCaches();
|
// If a background chainstate is in use, we may need to rebalance our
|
||||||
|
// allocation of caches once a chainstate exits initial block download.
|
||||||
|
m_chainman.MaybeRebalanceCaches();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write changes periodically to disk, after relay.
|
||||||
|
if (!FlushStateToDisk(state, FlushStateMode::PERIODIC)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
disabled = m_disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write changes periodically to disk, after relay.
|
if (disabled) {
|
||||||
if (!FlushStateToDisk(state, FlushStateMode::PERIODIC)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WITH_LOCK(::cs_main, return m_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