Skip to content

Commit

Permalink
refact: net: remove of boost::condition_variable
Browse files Browse the repository at this point in the history
(This compiles but shouldn't work yet)
  • Loading branch information
a-petrini committed Oct 3, 2023
1 parent d9dbb58 commit 11f6a5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ std::map<CInv, CDataStream> mapRelay;
std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
CCriticalSection cs_mapRelay;

boost::condition_variable messageHandlerCondition;

// Signals for message handling
static CNodeSignals g_signals;
CNodeSignals& GetNodeSignals() { return g_signals; }
Expand Down Expand Up @@ -697,7 +695,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes)
if (msg.complete()) {
msg.nTime = GetTimeMicros();
AccountForRecvBytes(msg.hdr.pchCommand, msg.hdr.nMessageSize + CMessageHeader::HEADER_SIZE);
messageHandlerCondition.notify_one();
connman->condMsgProc.notify_one();
}
}

Expand Down Expand Up @@ -799,6 +797,9 @@ CConnman::~CConnman()
// In Bitcoin this is called CConnman::Interrupt()
bool CConnman::StopNode()
{

condMsgProc.notify_all();

LogPrintf("StopNode()\n");
if (semOutbound)
for (int i=0; i<MAX_OUTBOUND_CONNECTIONS; i++)
Expand Down Expand Up @@ -1837,8 +1838,10 @@ void CConnman::ThreadMessageHandler()
pnode->Release();
}

if (fSleep)
messageHandlerCondition.timed_wait(lock, boost::posix_time::microsec_clock::universal_time() + boost::posix_time::milliseconds(100));
if (fSleep) {
std::unique_lock<std::mutex> lock(mutexMsgProc);
condMsgProc.wait_until(lock, std::chrono::steady_clock::now() + std::chrono::milliseconds(100));
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ class CConnman {
// that peer during `net_processing.cpp:PushNodeVersion()`.
uint64_t GetLocalServices() const;

std::condition_variable condMsgProc;

private:
std::atomic<uint64_t> nTotalBytesRecv = 0;
std::atomic<uint64_t> nTotalBytesSent = 0;
Expand All @@ -846,8 +848,7 @@ class CConnman {
// // To be moved here in the next PR, when we will get rid of boost::thread!
//
// CThreadInterrupt interruptNet;
// std::condition_variable condMsgProc;
// std::mutex mutexMsgProc;
std::mutex mutexMsgProc;
// std::atomic<bool> flagInterruptMsgProc;
//
std::thread threadDNSAddressSeed;
Expand Down

0 comments on commit 11f6a5e

Please sign in to comment.