mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-08-06 06:54:49 +02:00
net: remove unnecessary check of CNode::cs_vSend
It is not possible to have a node in `CConnman::vNodesDisconnected` and its reference count to be incremented - all `CNode::AddRef()` are done either before the node is added to `CConnman::vNodes` or while holding `CConnman::cs_vNodes` and the object being in `CConnman::vNodes`. So, the object being in `CConnman::vNodesDisconnected` and its reference count being zero means that it is not and will not start to be used by other threads. So, the lock of `CNode::cs_vSend` in `CConnman::DisconnectNodes()` will always succeed and is not necessary. Indeed all locks of `CNode::cs_vSend` are done either when the reference count is >0 or under the protection of `CConnman::cs_vNodes` and the node being in `CConnman::vNodes`.
This commit is contained in:
parent
e7776e20ed
commit
9096b13a47
11
src/net.cpp
11
src/net.cpp
@ -1224,23 +1224,14 @@ void CConnman::DisconnectNodes()
|
|||||||
std::list<CNode*> vNodesDisconnectedCopy = vNodesDisconnected;
|
std::list<CNode*> vNodesDisconnectedCopy = vNodesDisconnected;
|
||||||
for (CNode* pnode : vNodesDisconnectedCopy)
|
for (CNode* pnode : vNodesDisconnectedCopy)
|
||||||
{
|
{
|
||||||
// wait until threads are done using it
|
// Destroy the object only after other threads have stopped using it.
|
||||||
if (pnode->GetRefCount() <= 0) {
|
if (pnode->GetRefCount() <= 0) {
|
||||||
bool fDelete = false;
|
|
||||||
{
|
|
||||||
TRY_LOCK(pnode->cs_vSend, lockSend);
|
|
||||||
if (lockSend) {
|
|
||||||
fDelete = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fDelete) {
|
|
||||||
vNodesDisconnected.remove(pnode);
|
vNodesDisconnected.remove(pnode);
|
||||||
DeleteNode(pnode);
|
DeleteNode(pnode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CConnman::NotifyNumConnectionsChanged()
|
void CConnman::NotifyNumConnectionsChanged()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user