mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-23 07:15:29 +01:00
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.
This commit is contained in:
parent
64059b78f5
commit
574cc4271a
2 changed files with 1 additions and 4 deletions
|
@ -2879,7 +2879,6 @@ bool CConnman::DisconnectNode(NodeId id)
|
||||||
|
|
||||||
void CConnman::RecordBytesRecv(uint64_t bytes)
|
void CConnman::RecordBytesRecv(uint64_t bytes)
|
||||||
{
|
{
|
||||||
LOCK(cs_totalBytesRecv);
|
|
||||||
nTotalBytesRecv += bytes;
|
nTotalBytesRecv += bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2956,7 +2955,6 @@ uint64_t CConnman::GetOutboundTargetBytesLeft() const
|
||||||
|
|
||||||
uint64_t CConnman::GetTotalBytesRecv() const
|
uint64_t CConnman::GetTotalBytesRecv() const
|
||||||
{
|
{
|
||||||
LOCK(cs_totalBytesRecv);
|
|
||||||
return nTotalBytesRecv;
|
return nTotalBytesRecv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1074,9 +1074,8 @@ private:
|
||||||
static bool NodeFullyConnected(const CNode* pnode);
|
static bool NodeFullyConnected(const CNode* pnode);
|
||||||
|
|
||||||
// Network usage totals
|
// Network usage totals
|
||||||
mutable RecursiveMutex cs_totalBytesRecv;
|
|
||||||
mutable RecursiveMutex cs_totalBytesSent;
|
mutable RecursiveMutex cs_totalBytesSent;
|
||||||
uint64_t nTotalBytesRecv GUARDED_BY(cs_totalBytesRecv) {0};
|
std::atomic<uint64_t> nTotalBytesRecv{0};
|
||||||
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent) {0};
|
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent) {0};
|
||||||
|
|
||||||
// outbound limit & stats
|
// outbound limit & stats
|
||||||
|
|
Loading…
Add table
Reference in a new issue