From 07f95c597cde73fa127c72085e443f65cb2c68f5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 18 Dec 2014 14:08:55 -0800 Subject: [PATCH] add read locks for find on tbb hash --- libraries/networking/src/LimitedNodeList.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index de533ec7be..907ac86704 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -352,6 +352,8 @@ int LimitedNodeList::findNodeAndUpdateWithDataFromPacket(const QByteArray& packe } SharedNodePointer LimitedNodeList::nodeWithUUID(const QUuid& nodeUUID) { + QReadLocker readLocker(&_nodeMutex); + NodeHash::const_iterator it = _nodeHash.find(nodeUUID); return it == _nodeHash.cend() ? SharedNodePointer() : it->second; } @@ -386,10 +388,14 @@ void LimitedNodeList::reset() { } void LimitedNodeList::killNodeWithUUID(const QUuid& nodeUUID) { + _nodeMutex.lockForRead(); + NodeHash::iterator it = _nodeHash.find(nodeUUID); if (it != _nodeHash.end()) { SharedNodePointer matchingNode = it->second; + _nodeMutex.unlock(); + QWriteLocker writeLocker(&_nodeMutex); _nodeHash.unsafe_erase(it);