Skip to content

Commit 18d2832

Browse files
committed
Merge pull request #5971
351593b replace absolute sleep with conditional wait (pstratem)
2 parents 5048465 + 351593b commit 18d2832

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/net.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ NodeId nLastNodeId = 0;
100100
CCriticalSection cs_nLastNodeId;
101101

102102
static CSemaphore *semOutbound = NULL;
103+
boost::condition_variable messageHandlerCondition;
103104

104105
// Signals for message handling
105106
static CNodeSignals g_signals;
@@ -532,8 +533,10 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes)
532533
pch += handled;
533534
nBytes -= handled;
534535

535-
if (msg.complete())
536+
if (msg.complete()) {
536537
msg.nTime = GetTimeMicros();
538+
messageHandlerCondition.notify_one();
539+
}
537540
}
538541

539542
return true;
@@ -1358,6 +1361,9 @@ bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOu
13581361

13591362
void ThreadMessageHandler()
13601363
{
1364+
boost::mutex condition_mutex;
1365+
boost::unique_lock<boost::mutex> lock(condition_mutex);
1366+
13611367
SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL);
13621368
while (true)
13631369
{
@@ -1417,7 +1423,7 @@ void ThreadMessageHandler()
14171423
}
14181424

14191425
if (fSleep)
1420-
MilliSleep(100);
1426+
messageHandlerCondition.timed_wait(lock, boost::posix_time::microsec_clock::universal_time() + boost::posix_time::milliseconds(100));
14211427
}
14221428
}
14231429

0 commit comments

Comments
 (0)