Skip to content

Commit

Permalink
Don't wake up select if it was already woken up (#2863)
Browse files Browse the repository at this point in the history
This avoids calling WakeupSelect() for each node instead of just once.
  • Loading branch information
codablock authored and UdjinM6 committed Apr 12, 2019
1 parent 7fe1a4a commit fbe4476
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,10 +1321,10 @@ void CConnman::ThreadSocketHandler()
}
}

isInSelect = true;
wakeupSelectNeeded = true;
int nSelect = select(have_fds ? hSocketMax + 1 : 0,
&fdsetRecv, &fdsetSend, &fdsetError, &timeout);
isInSelect = false;
wakeupSelectNeeded = false;
if (interruptNet)
return;

Expand Down Expand Up @@ -1521,6 +1521,8 @@ void CConnman::WakeSelect()
LogPrint("net", "write to wakeupPipe failed\n");
}
#endif

wakeupSelectNeeded = false;
}


Expand Down Expand Up @@ -3236,7 +3238,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg, bool allowOpti
if (optimisticSend == true)
nBytesSent = SocketSendData(pnode);
// wake up select() call in case there was no pending data before (so it was not selecting this socket for sending)
else if (!hasPendingData && isInSelect)
else if (!hasPendingData && wakeupSelectNeeded)
WakeSelect();
}
if (nBytesSent)
Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ class CConnman
/** a pipe which is added to select() calls to wakeup before the timeout */
int wakeupPipe[2]{-1,-1};
#endif
std::atomic<bool> isInSelect{false};
std::atomic<bool> wakeupSelectNeeded{false};

std::thread threadDNSAddressSeed;
std::thread threadSocketHandler;
Expand Down

0 comments on commit fbe4476

Please sign in to comment.