Skip to content

Commit 574cc42

Browse files
committed
refactor: remove RecursiveMutex cs_totalBytesRecv, use std::atomic instead
The RecursiveMutex cs_totalBytesRecv is only used at two places: in CConnman::RecordBytesRecv() to increment the nTotalBytesRecv member, and in CConnman::GetTotalBytesRecv() to read it. For this simple use-case, we can make the member std::atomic instead to achieve the same result.
1 parent 64059b7 commit 574cc42

File tree

2 files changed

+1
-4
lines changed

2 files changed

+1
-4
lines changed

src/net.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,7 +2879,6 @@ bool CConnman::DisconnectNode(NodeId id)
28792879

28802880
void CConnman::RecordBytesRecv(uint64_t bytes)
28812881
{
2882-
LOCK(cs_totalBytesRecv);
28832882
nTotalBytesRecv += bytes;
28842883
}
28852884

@@ -2956,7 +2955,6 @@ uint64_t CConnman::GetOutboundTargetBytesLeft() const
29562955

29572956
uint64_t CConnman::GetTotalBytesRecv() const
29582957
{
2959-
LOCK(cs_totalBytesRecv);
29602958
return nTotalBytesRecv;
29612959
}
29622960

src/net.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,9 +1074,8 @@ class CConnman
10741074
static bool NodeFullyConnected(const CNode* pnode);
10751075

10761076
// Network usage totals
1077-
mutable RecursiveMutex cs_totalBytesRecv;
10781077
mutable RecursiveMutex cs_totalBytesSent;
1079-
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv) {0};
1078+
std::atomic<uint64_t> nTotalBytesRecv{0};
10801079
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent) {0};
10811080

10821081
// outbound limit & stats

0 commit comments

Comments
 (0)