From 66b27fa60776b2a8bbceef971073315a628a9ab1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 29 Oct 2013 15:59:09 -0700 Subject: [PATCH 1/2] have silent node removal flag reset on join --- libraries/shared/src/NodeList.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index d5984c5bbc..3657830201 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -772,19 +772,14 @@ void* removeSilentNodes(void *args) { checkTimeUsecs = usecTimestampNow(); for(NodeList::iterator node = nodeList->begin(); node != nodeList->end(); ++node) { - qDebug() << "Locking node" << node->getUUID() << "\n"; node->lock(); - qDebug() << "N:" << usecTimestampNow() << "LH:" << node->getLastHeardMicrostamp() << "\n"; - qDebug() << "Diff:" << usecTimestampNow() - node->getLastHeardMicrostamp() << "\n"; - if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) { // kill this node, don't lock - we already did it nodeList->killNode(&(*node), false); } node->unlock(); - qDebug() << "Unlocking node" << node->getUUID() << "\n"; } sleepTime = NODE_SILENCE_THRESHOLD_USECS - (usecTimestampNow() - checkTimeUsecs); @@ -796,7 +791,6 @@ void* removeSilentNodes(void *args) { #else if (sleepTime > 0) { - qDebug() << "Sleeping for" << sleepTime << "\n"; usleep(sleepTime); } @@ -808,13 +802,23 @@ void* removeSilentNodes(void *args) { } void NodeList::startSilentNodeRemovalThread() { - pthread_create(&removeSilentNodesThread, NULL, removeSilentNodes, (void*) this); + if (!silentNodeThreadStopFlag) { + pthread_create(&removeSilentNodesThread, NULL, removeSilentNodes, (void*) this); + } else { + qDebug("Refusing to start silent node removal thread from previously failed join.\n"); + } + } void NodeList::stopSilentNodeRemovalThread() { silentNodeThreadStopFlag = true; - pthread_join(removeSilentNodesThread, NULL); + int joinResult = pthread_join(removeSilentNodesThread, NULL); + if (joinResult == 0) { + silentNodeThreadStopFlag = false; + } else { + qDebug("Silent node removal thread join failed with %d. Will not restart.\n", joinResult); + } } const QString QSETTINGS_GROUP_NAME = "NodeList"; From 03b23b504f32cf233d94baad243da62dd385a8af Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 29 Oct 2013 16:05:23 -0700 Subject: [PATCH 2/2] reference global with colon --- libraries/shared/src/NodeList.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 3657830201..3bf6813465 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -767,7 +767,7 @@ void* removeSilentNodes(void *args) { uint64_t checkTimeUsecs = 0; int sleepTime = 0; - while (!silentNodeThreadStopFlag) { + while (!::silentNodeThreadStopFlag) { checkTimeUsecs = usecTimestampNow(); @@ -802,7 +802,7 @@ void* removeSilentNodes(void *args) { } void NodeList::startSilentNodeRemovalThread() { - if (!silentNodeThreadStopFlag) { + if (!::silentNodeThreadStopFlag) { pthread_create(&removeSilentNodesThread, NULL, removeSilentNodes, (void*) this); } else { qDebug("Refusing to start silent node removal thread from previously failed join.\n"); @@ -811,11 +811,11 @@ void NodeList::startSilentNodeRemovalThread() { } void NodeList::stopSilentNodeRemovalThread() { - silentNodeThreadStopFlag = true; + ::silentNodeThreadStopFlag = true; int joinResult = pthread_join(removeSilentNodesThread, NULL); if (joinResult == 0) { - silentNodeThreadStopFlag = false; + ::silentNodeThreadStopFlag = false; } else { qDebug("Silent node removal thread join failed with %d. Will not restart.\n", joinResult); }