Skip to content

Commit eea02be

Browse files
Add locking annotation for vNodes. vNodes is guarded by cs_vNodes.
1 parent 6314433 commit eea02be

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/net.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,18 @@ class CConnman
177177
CConnman(uint64_t seed0, uint64_t seed1);
178178
~CConnman();
179179
bool Start(CScheduler& scheduler, const Options& options);
180-
void Stop();
180+
181+
// TODO: Remove NO_THREAD_SAFETY_ANALYSIS. Lock cs_vNodes before reading the variable vNodes.
182+
//
183+
// When removing NO_THREAD_SAFETY_ANALYSIS be aware of the following lock order requirements:
184+
// * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraOutboundCount
185+
// which locks cs_vNodes.
186+
// * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
187+
// locks cs_vNodes.
188+
//
189+
// Thus the implicit locking order requirement is: (1) cs_main, (2) g_cs_orphans, (3) cs_vNodes.
190+
void Stop() NO_THREAD_SAFETY_ANALYSIS;
191+
181192
void Interrupt();
182193
bool GetNetworkActive() const { return fNetworkActive; };
183194
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
@@ -418,7 +429,7 @@ class CConnman
418429
CCriticalSection cs_vOneShots;
419430
std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
420431
CCriticalSection cs_vAddedNodes;
421-
std::vector<CNode*> vNodes;
432+
std::vector<CNode*> vNodes GUARDED_BY(cs_vNodes);
422433
std::list<CNode*> vNodesDisconnected;
423434
mutable CCriticalSection cs_vNodes;
424435
std::atomic<NodeId> nLastNodeId{0};

0 commit comments

Comments
 (0)