Skip to content

Commit

Permalink
Merge pull request #5971
Browse files Browse the repository at this point in the history
351593b replace absolute sleep with conditional wait (pstratem)
  • Loading branch information
laanwj committed Apr 28, 2015
2 parents 5048465 + 351593b commit 18d2832
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/net.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 18d2832

Please sign in to comment.