Skip to content

Commit 4eada5d

Browse files
author
MarcoFalke
committed
Merge bitcoin#20816: net: Move RecordBytesSent() call out of cs_vSend lock
378aedc [net] Add cs_vSend lock annotations (John Newbery) 6732545 [net] Move RecordBytesSent() call out of cs_vSend lock (John Newbery) Pull request description: RecordBytesSent() does not require cs_vSend to be locked, so reduce the scope of cs_vSend. Also correctly annotate the CNode data members that are guarded by cs_vSend. This is a simpler alternative to bitcoin#19673. ACKs for top commit: jnewbery: ok, reverting to commit 378aedc which has two ACKs already. Any style issues can be fixed up in future PRs. troygiorshev: ACK 378aedc theStack: re-ACK 378aedc MarcoFalke: review ACK 378aedc 🔌 Tree-SHA512: e9cd6c472b7e1479120c1bf2d1c640cf6d18c7d589a5f9b7dfc4875e5790adaab403a7a1b945a47e79e7249a614b8583270e4549f89b22e8a9edb2e4818b0d07
2 parents 417f95f + 378aedc commit 4eada5d

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/net.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,16 +1506,10 @@ void CConnman::SocketHandler()
15061506
}
15071507
}
15081508

1509-
//
1510-
// Send
1511-
//
1512-
if (sendSet)
1513-
{
1514-
LOCK(pnode->cs_vSend);
1515-
size_t nBytes = SocketSendData(pnode);
1516-
if (nBytes) {
1517-
RecordBytesSent(nBytes);
1518-
}
1509+
if (sendSet) {
1510+
// Send data
1511+
size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(pnode));
1512+
if (bytes_sent) RecordBytesSent(bytes_sent);
15191513
}
15201514

15211515
InactivityCheck(pnode);

src/net.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,10 @@ class CNode
849849
// socket
850850
std::atomic<ServiceFlags> nServices{NODE_NONE};
851851
SOCKET hSocket GUARDED_BY(cs_hSocket);
852-
size_t nSendSize{0}; // total size of all vSendMsg entries
853-
size_t nSendOffset{0}; // offset inside the first vSendMsg already sent
852+
/** Total size of all vSendMsg entries */
853+
size_t nSendSize GUARDED_BY(cs_vSend){0};
854+
/** Offset inside the first vSendMsg already sent */
855+
size_t nSendOffset GUARDED_BY(cs_vSend){0};
854856
uint64_t nSendBytes GUARDED_BY(cs_vSend){0};
855857
std::deque<std::vector<unsigned char>> vSendMsg GUARDED_BY(cs_vSend);
856858
Mutex cs_vSend;
@@ -979,7 +981,7 @@ class CNode
979981
Network ConnectedThroughNetwork() const;
980982

981983
protected:
982-
mapMsgCmdSize mapSendBytesPerMsgCmd;
984+
mapMsgCmdSize mapSendBytesPerMsgCmd GUARDED_BY(cs_vSend);
983985
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
984986

985987
public:

0 commit comments

Comments
 (0)