From 13ac5472eaf9cd8969488e967ad5cf50763ad611 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 11 Oct 2013 10:23:59 -0700 Subject: [PATCH] fix an idiotic bug with silent node kill thread --- libraries/shared/src/NodeList.cpp | 18 ++++++++++++++---- libraries/shared/src/NodeList.h | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index d4aaa48aae..9735752aab 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -542,14 +542,17 @@ Node* NodeList::soloNodeOfType(char nodeType) { void* removeSilentNodes(void *args) { NodeList* nodeList = (NodeList*) args; - uint64_t checkTimeUsecs = usecTimestampNow(); - int sleepTime; + uint64_t checkTimeUsecs = 0; + int sleepTime = 0; while (!silentNodeThreadStopFlag) { + checkTimeUsecs = usecTimestampNow(); + for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) { - node->lock(); + + qDebug() << usecTimestampNow() - node->getLastHeardMicrostamp() << "\n"; if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) { @@ -564,10 +567,17 @@ void* removeSilentNodes(void *args) { } sleepTime = NODE_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUsecs); + #ifdef _WIN32 + Sleep( static_cast(1000.0f*sleepTime) ); + #else - usleep(sleepTime); + + if (sleepTime > 0) { + usleep(sleepTime); + } + #endif } diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 9914ac9094..8d2bd16cae 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -30,7 +30,7 @@ const int NODES_PER_BUCKET = 100; const int MAX_PACKET_SIZE = 1500; -const uint64_t NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000; +const uint64_t NODE_SILENCE_THRESHOLD_USECS = 2 * 1000 * 1000; const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000; extern const char SOLO_NODE_TYPES[2];