diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-04-28 10:41:05 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-04-28 10:41:46 +0200 |
commit | 18d28326785a7111b50528107550c3d37ec40d89 (patch) | |
tree | 0e6d9c95890af64b4f6b7a3af45214013e90e483 /src | |
parent | 5048465fc5ed2236f513edbe95cd74f9c71f7c76 (diff) | |
parent | 351593b9c8687b4da2e86769899b8b61ea44b630 (diff) |
Merge pull request #5971
351593b replace absolute sleep with conditional wait (pstratem)
Diffstat (limited to 'src')
-rw-r--r-- | src/net.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp index e5f67262ce..45a06a105f 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -100,6 +100,7 @@ NodeId nLastNodeId = 0; CCriticalSection cs_nLastNodeId; static CSemaphore *semOutbound = NULL; +boost::condition_variable messageHandlerCondition; // Signals for message handling static CNodeSignals g_signals; @@ -532,8 +533,10 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes) pch += handled; nBytes -= handled; - if (msg.complete()) + if (msg.complete()) { msg.nTime = GetTimeMicros(); + messageHandlerCondition.notify_one(); + } } return true; @@ -1358,6 +1361,9 @@ bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOu void ThreadMessageHandler() { + boost::mutex condition_mutex; + boost::unique_lock<boost::mutex> lock(condition_mutex); + SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); while (true) { @@ -1417,7 +1423,7 @@ void ThreadMessageHandler() } if (fSleep) - MilliSleep(100); + messageHandlerCondition.timed_wait(lock, boost::posix_time::microsec_clock::universal_time() + boost::posix_time::milliseconds(100)); } } |