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