Skip to content

Commit fa530bc

Browse files
author
MacroFake
committed
Add ChainstateManager::GetMutex(), an alias for ::cs_main
1 parent 0f90b58 commit fa530bc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/validation.h

+13
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,19 @@ class ChainstateManager
868868
const CChainParams& GetParams() const { return m_chainparams; }
869869
const Consensus::Params& GetConsensus() const { return m_chainparams.GetConsensus(); }
870870

871+
/**
872+
* Alias for ::cs_main.
873+
* Should be used in new code to make it easier to make ::cs_main a member
874+
* of this class.
875+
* Generally, methods of this class should be annotated to require this
876+
* mutex. This will make calling code more verbose, but also help to:
877+
* - Clarify that the method will acquire a mutex that heavily affects
878+
* overall performance.
879+
* - Force call sites to think how long they need to acquire the mutex to
880+
* get consistent results.
881+
*/
882+
RecursiveMutex& GetMutex() const LOCK_RETURNED(::cs_main) { return ::cs_main; }
883+
871884
std::thread m_load_block;
872885
//! A single BlockManager instance is shared across each constructed
873886
//! chainstate to avoid duplicating block metadata.

0 commit comments

Comments
 (0)