Skip to content

Commit d6b5590

Browse files
Merge dashpay#5883: refactor: use atomic to avoid blocking chainlocks cs on each call to cleanup
75d81fd refactor: use atomic to avoid blocking chainlocks cs on each call to cleanup (pasta) Pull request description: ## Issue being fixed or feature implemented Avoid needing to lock CS on each call to cleanup. Cleanup only gets called once every 5 seconds it seems; but maybe that'll change in the future. ## What was done? Make `lastCleanupTime` atomic instead of CS guarded ## How Has This Been Tested? Building ## Breaking Changes None ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ Top commit has no ACKs. Tree-SHA512: 587dbfbecce430c25b4d572b2e158fcda86aced3db976c16166c0cabcf960f46d300739bbf54644def30769347cc88ac14c58d71dd78d848f7d8af562cd12bc6
2 parents 3fd913a + 75d81fd commit d6b5590

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/llmq/chainlocks.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,8 @@ void CChainLocksHandler::Cleanup()
617617
return;
618618
}
619619

620-
{
621-
LOCK(cs);
622-
if (GetTimeMillis() - lastCleanupTime < CLEANUP_INTERVAL) {
623-
return;
624-
}
620+
if (GetTimeMillis() - lastCleanupTime < CLEANUP_INTERVAL) {
621+
return;
625622
}
626623

627624
// need mempool.cs due to GetTransaction calls

src/llmq/chainlocks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CChainLocksHandler : public CRecoveredSigsListener
8282

8383
std::map<uint256, int64_t> seenChainLocks GUARDED_BY(cs);
8484

85-
int64_t lastCleanupTime GUARDED_BY(cs) {0};
85+
std::atomic<int64_t> lastCleanupTime{0};
8686

8787
public:
8888
explicit CChainLocksHandler(CChainState& chainstate, CConnman& _connman, CMasternodeSync& mn_sync, CQuorumManager& _qman,

0 commit comments

Comments
 (0)