Add a mutex lock to protect CNode::nRefCount (#1321)
* Add a mutex lock to protect CNode::nRefCount * Added logging statement for CNode removal
This commit is contained in:
parent
5520bf6895
commit
8de792291a
@ -1050,6 +1050,9 @@ void ThreadSocketHandler()
|
||||
if (pnode->fDisconnect ||
|
||||
(pnode->GetRefCount() <= 0 && pnode->vRecvMsg.empty() && pnode->nSendSize == 0 && pnode->ssSend.empty()))
|
||||
{
|
||||
LogPrintf("ThreadSocketHandler -- removing node: peer=%d addr=%s nRefCount=%d fNetworkNode=%d fInbound=%d fMasternode=%d\n",
|
||||
pnode->id, pnode->addr.ToString(), pnode->GetRefCount(), pnode->fNetworkNode, pnode->fInbound, pnode->fMasternode);
|
||||
|
||||
// remove from vNodes
|
||||
vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end());
|
||||
|
||||
|
@ -436,6 +436,8 @@ private:
|
||||
static uint64_t nMaxOutboundLimit;
|
||||
static uint64_t nMaxOutboundTimeframe;
|
||||
|
||||
CCriticalSection cs_nRefCount;
|
||||
|
||||
CNode(const CNode&);
|
||||
void operator=(const CNode&);
|
||||
|
||||
@ -447,6 +449,7 @@ public:
|
||||
|
||||
int GetRefCount()
|
||||
{
|
||||
LOCK(cs_nRefCount);
|
||||
assert(nRefCount >= 0);
|
||||
return nRefCount;
|
||||
}
|
||||
@ -473,12 +476,14 @@ public:
|
||||
|
||||
CNode* AddRef()
|
||||
{
|
||||
LOCK(cs_nRefCount);
|
||||
nRefCount++;
|
||||
return this;
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
LOCK(cs_nRefCount);
|
||||
nRefCount--;
|
||||
assert(nRefCount >= 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user