mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Merge #8007: Minor locking improvements
f0fdda0
IsInitialBlockDownload: usually avoid locking (Kaz Wesley)
This commit is contained in:
commit
6b781df74f
15
src/main.cpp
15
src/main.cpp
@ -37,6 +37,7 @@
|
|||||||
#include "validationinterface.h"
|
#include "validationinterface.h"
|
||||||
#include "versionbits.h"
|
#include "versionbits.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
@ -1577,18 +1578,24 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
|
|||||||
bool IsInitialBlockDownload()
|
bool IsInitialBlockDownload()
|
||||||
{
|
{
|
||||||
const CChainParams& chainParams = Params();
|
const CChainParams& chainParams = Params();
|
||||||
|
|
||||||
|
// Once this function has returned false, it must remain false.
|
||||||
|
static std::atomic<bool> latchToFalse{false};
|
||||||
|
// Optimization: pre-test latch before taking the lock.
|
||||||
|
if (latchToFalse.load(std::memory_order_relaxed))
|
||||||
|
return false;
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
if (latchToFalse.load(std::memory_order_relaxed))
|
||||||
|
return false;
|
||||||
if (fImporting || fReindex)
|
if (fImporting || fReindex)
|
||||||
return true;
|
return true;
|
||||||
if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints()))
|
if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints()))
|
||||||
return true;
|
return true;
|
||||||
static bool lockIBDState = false;
|
|
||||||
if (lockIBDState)
|
|
||||||
return false;
|
|
||||||
bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
|
bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
|
||||||
std::max(chainActive.Tip()->GetBlockTime(), pindexBestHeader->GetBlockTime()) < GetTime() - nMaxTipAge);
|
std::max(chainActive.Tip()->GetBlockTime(), pindexBestHeader->GetBlockTime()) < GetTime() - nMaxTipAge);
|
||||||
if (!state)
|
if (!state)
|
||||||
lockIBDState = true;
|
latchToFalse.store(true, std::memory_order_relaxed);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user