Browse Source

Split CNode::cs_vSend: message processing and message sending

cs_vSend is used for two purposes - to lock the datastructures used
to queue messages to place on the wire and to only call
SendMessages once at a time per-node. I believe SendMessages used
to access some of the vSendMsg stuff, but it doesn't anymore, so
these locks do not need to be on the same mutex, and also make
deadlocking much more likely.
0.14
Matt Corallo 8 years ago
parent
commit
d7c58ad514
  1. 22
      src/net.cpp
  2. 2
      src/net.h

22
src/net.cpp

@ -1147,12 +1147,10 @@ void CConnman::ThreadSocketHandler()
// * Hand off all complete messages to the processor, to be handled without // * Hand off all complete messages to the processor, to be handled without
// blocking here. // blocking here.
{ {
TRY_LOCK(pnode->cs_vSend, lockSend); LOCK(pnode->cs_vSend);
if (lockSend) { if (!pnode->vSendMsg.empty()) {
if (!pnode->vSendMsg.empty()) { FD_SET(pnode->hSocket, &fdsetSend);
FD_SET(pnode->hSocket, &fdsetSend); continue;
continue;
}
} }
} }
{ {
@ -1272,12 +1270,10 @@ void CConnman::ThreadSocketHandler()
continue; continue;
if (FD_ISSET(pnode->hSocket, &fdsetSend)) if (FD_ISSET(pnode->hSocket, &fdsetSend))
{ {
TRY_LOCK(pnode->cs_vSend, lockSend); LOCK(pnode->cs_vSend);
if (lockSend) { size_t nBytes = SocketSendData(pnode);
size_t nBytes = SocketSendData(pnode); if (nBytes) {
if (nBytes) { RecordBytesSent(nBytes);
RecordBytesSent(nBytes);
}
} }
} }
@ -1875,7 +1871,7 @@ void CConnman::ThreadMessageHandler()
// Send messages // Send messages
{ {
TRY_LOCK(pnode->cs_vSend, lockSend); TRY_LOCK(pnode->cs_sendProcessing, lockSend);
if (lockSend) if (lockSend)
GetNodeSignals().SendMessages(pnode, *this, flagInterruptMsgProc); GetNodeSignals().SendMessages(pnode, *this, flagInterruptMsgProc);
} }

2
src/net.h

@ -618,6 +618,8 @@ public:
std::list<CNetMessage> vProcessMsg; std::list<CNetMessage> vProcessMsg;
size_t nProcessQueueSize; size_t nProcessQueueSize;
CCriticalSection cs_sendProcessing;
std::deque<CInv> vRecvGetData; std::deque<CInv> vRecvGetData;
uint64_t nRecvBytes; uint64_t nRecvBytes;
std::atomic<int> nRecvVersion; std::atomic<int> nRecvVersion;

Loading…
Cancel
Save