From 574cc4271ab09a4c8f8d076cb1a3a2d5b3924b73 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Sat, 28 Aug 2021 19:51:08 +0200 Subject: 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. --- src/net.cpp | 2 -- src/net.h | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/net.cpp b/src/net.cpp index 1b6d16ad9b..5406e7e49d 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2879,7 +2879,6 @@ bool CConnman::DisconnectNode(NodeId id) void CConnman::RecordBytesRecv(uint64_t bytes) { - LOCK(cs_totalBytesRecv); nTotalBytesRecv += bytes; } @@ -2956,7 +2955,6 @@ uint64_t CConnman::GetOutboundTargetBytesLeft() const uint64_t CConnman::GetTotalBytesRecv() const { - LOCK(cs_totalBytesRecv); return nTotalBytesRecv; } diff --git a/src/net.h b/src/net.h index bb024f35f0..7092a6524a 100644 --- a/src/net.h +++ b/src/net.h @@ -1074,9 +1074,8 @@ private: static bool NodeFullyConnected(const CNode* pnode); // Network usage totals - mutable RecursiveMutex cs_totalBytesRecv; mutable RecursiveMutex cs_totalBytesSent; - uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv) {0}; + std::atomic nTotalBytesRecv{0}; uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent) {0}; // outbound limit & stats -- cgit v1.2.3