Skip to content

Commit 30495d1

Browse files
author
MarcoFalke
committed
Merge #15201: net: Add missing locking annotation for vNodes. vNodes is guarded by cs_vNodes.
eea02be Add locking annotation for vNodes. vNodes is guarded by cs_vNodes. (practicalswift) Pull request description: Add locking annotation for `vNodes`. `vNodes` is guarded by `cs_vNodes`. Tree-SHA512: b1e18be22ba5b9dd153536380321b09b30a75a20575f975af9af94164f51982b32267ba0994e77c801513b59da05d923a974a9d2dfebdac48024c4bda98b53af
2 parents 6fc656a + eea02be commit 30495d1

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
@@ -174,7 +174,18 @@ class CConnman
174174
CConnman(uint64_t seed0, uint64_t seed1);
175175
~CConnman();
176176
bool Start(CScheduler& scheduler, const Options& options);
177-
void Stop();
177+
178+
// TODO: Remove NO_THREAD_SAFETY_ANALYSIS. Lock cs_vNodes before reading the variable vNodes.
179+
//
180+
// When removing NO_THREAD_SAFETY_ANALYSIS be aware of the following lock order requirements:
181+
// * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraOutboundCount
182+
// which locks cs_vNodes.
183+
// * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
184+
// locks cs_vNodes.
185+
//
186+
// Thus the implicit locking order requirement is: (1) cs_main, (2) g_cs_orphans, (3) cs_vNodes.
187+
void Stop() NO_THREAD_SAFETY_ANALYSIS;
188+
178189
void Interrupt();
179190
bool GetNetworkActive() const { return fNetworkActive; };
180191
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
@@ -382,7 +393,7 @@ class CConnman
382393
CCriticalSection cs_vOneShots;
383394
std::vector<std::string> vAddedNodes GUARDED_BY(cs_vAddedNodes);
384395
CCriticalSection cs_vAddedNodes;
385-
std::vector<CNode*> vNodes;
396+
std::vector<CNode*> vNodes GUARDED_BY(cs_vNodes);
386397
std::list<CNode*> vNodesDisconnected;
387398
mutable CCriticalSection cs_vNodes;
388399
std::atomic<NodeId> nLastNodeId{0};

0 commit comments

Comments
 (0)