From 0579b1842645d290ff150e82852d2830130ad86a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 13 Jan 2014 17:33:58 -0800 Subject: [PATCH] fix deadlock in silent node removal --- libraries/shared/src/NodeList.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index fc6dc1851e..bf4bb16d70 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -794,17 +794,19 @@ void NodeList::removeSilentNodes() { NodeHash::iterator nodeItem = _nodeHash.begin(); while (nodeItem != _nodeHash.end()) { - nodeItem.value()->lock(); - if ((usecTimestampNow() - nodeItem.value()->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) { - SharedNodePointer node = nodeItem.value(); + SharedNodePointer node = nodeItem.value(); + + node->lock(); + + if ((usecTimestampNow() - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) { // kill this node, don't lock - we already did it _nodeHash.erase(nodeItem); - - // unlock the node - node->unlock(); } + + // unlock the node + node->unlock(); } }