Merge #5883: refactor: use atomic to avoid blocking chainlocks cs on each call to cleanup

75d81fd2c0 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
This commit is contained in:
pasta 2024-02-24 11:16:31 -06:00
commit d6b5590c18
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
2 changed files with 3 additions and 6 deletions

View File

@ -617,11 +617,8 @@ void CChainLocksHandler::Cleanup()
return;
}
{
LOCK(cs);
if (GetTimeMillis() - lastCleanupTime < CLEANUP_INTERVAL) {
return;
}
if (GetTimeMillis() - lastCleanupTime < CLEANUP_INTERVAL) {
return;
}
// need mempool.cs due to GetTransaction calls

View File

@ -82,7 +82,7 @@ private:
std::map<uint256, int64_t> seenChainLocks GUARDED_BY(cs);
int64_t lastCleanupTime GUARDED_BY(cs) {0};
std::atomic<int64_t> lastCleanupTime{0};
public:
explicit CChainLocksHandler(CChainState& chainstate, CConnman& _connman, CMasternodeSync& mn_sync, CQuorumManager& _qman,