Remove some recursive locks (#1624)
* unnecessary recursive lock removed in `VersionBitsTipState` method * interface changed for CRateChecksGuard; unnecessary recursive lock removed
This commit is contained in:
parent
d7a8489f31
commit
adc7c6cb12
@ -277,7 +277,7 @@ void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj, CGovernance
|
||||
std::vector<vote_time_pair_t> vecVotePairs;
|
||||
mapOrphanVotes.GetAll(nHash, vecVotePairs);
|
||||
|
||||
CRateChecksGuard guard(false, *this);
|
||||
ScopedLockBool guard(cs, fRateChecksEnabled, false);
|
||||
|
||||
int64_t nNow = GetAdjustedTime();
|
||||
for(size_t i = 0; i < vecVotePairs.size(); ++i) {
|
||||
@ -467,7 +467,7 @@ void CGovernanceManager::UpdateCachesAndClean()
|
||||
it->second.fDirtyCache = true;
|
||||
}
|
||||
|
||||
CRateChecksGuard guard(false, *this);
|
||||
ScopedLockBool guard(cs, fRateChecksEnabled, false);
|
||||
|
||||
// UPDATE CACHE FOR EACH OBJECT THAT IS FLAGGED DIRTYCACHE=TRUE
|
||||
|
||||
@ -986,7 +986,7 @@ void CGovernanceManager::CheckMasternodeOrphanVotes()
|
||||
{
|
||||
LOCK2(cs_main, cs);
|
||||
|
||||
CRateChecksGuard guard(false, *this);
|
||||
ScopedLockBool guard(cs, fRateChecksEnabled, false);
|
||||
|
||||
for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) {
|
||||
it->second.CheckOrphanVotes();
|
||||
@ -997,7 +997,7 @@ void CGovernanceManager::CheckMasternodeOrphanObjects()
|
||||
{
|
||||
LOCK2(cs_main, cs);
|
||||
int64_t nNow = GetAdjustedTime();
|
||||
CRateChecksGuard guard(false, *this);
|
||||
ScopedLockBool guard(cs, fRateChecksEnabled, false);
|
||||
object_info_m_it it = mapMasternodeOrphanObjects.begin();
|
||||
while(it != mapMasternodeOrphanObjects.end()) {
|
||||
object_info_pair_t& pair = it->second;
|
||||
|
@ -265,23 +265,22 @@ private:
|
||||
|
||||
bool fRateChecksEnabled;
|
||||
|
||||
class CRateChecksGuard
|
||||
class ScopedLockBool
|
||||
{
|
||||
CGovernanceManager& govman;
|
||||
bool fRateChecksPrev;
|
||||
bool& ref;
|
||||
bool fPrevValue;
|
||||
|
||||
public:
|
||||
CRateChecksGuard(bool value, CGovernanceManager& gm) : govman(gm)
|
||||
ScopedLockBool(CCriticalSection& _cs, bool& _ref, bool _value) : ref(_ref)
|
||||
{
|
||||
ENTER_CRITICAL_SECTION(govman.cs)
|
||||
fRateChecksPrev = govman.fRateChecksEnabled;
|
||||
govman.fRateChecksEnabled = value;
|
||||
AssertLockHeld(_cs);
|
||||
fPrevValue = ref;
|
||||
ref = _value;
|
||||
}
|
||||
|
||||
~CRateChecksGuard()
|
||||
~ScopedLockBool()
|
||||
{
|
||||
govman.fRateChecksEnabled = fRateChecksPrev;
|
||||
LEAVE_CRITICAL_SECTION(govman.cs)
|
||||
ref = fPrevValue;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -4367,7 +4367,7 @@ std::string GetWarnings(const std::string& strFor)
|
||||
|
||||
ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
AssertLockHeld(cs_main);
|
||||
return VersionBitsState(chainActive.Tip(), params, pos, versionbitscache);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user