LocalID - Use tbb hash map instead of std one for better concurrency

This commit is contained in:
Simon Walton 2018-04-02 10:46:38 -07:00
parent f4bd1f5ed7
commit 2ba64e1115
2 changed files with 3 additions and 6 deletions

View file

@ -696,7 +696,7 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t
auto oldSoloNode = previousSoloIt->second;
_localIDMap.erase(oldSoloNode->getLocalID());
_localIDMap.unsafe_erase(oldSoloNode->getLocalID());
_nodeHash.unsafe_erase(previousSoloIt);
handleNodeKill(oldSoloNode);
@ -840,6 +840,7 @@ void LimitedNodeList::removeSilentNodes() {
if (!node->isForcedNeverSilent()
&& (usecTimestampNow() - node->getLastHeardMicrostamp()) > (NODE_SILENCE_THRESHOLD_MSECS * USECS_PER_MSEC)) {
// call the NodeHash erase to get rid of this node
_localIDMap.unsafe_erase(node->getLocalID());
it = _nodeHash.unsafe_erase(it);
killedNodes.insert(node);
@ -852,10 +853,6 @@ void LimitedNodeList::removeSilentNodes() {
});
foreach(const SharedNodePointer& killedNode, killedNodes) {
{
QWriteLocker writeLock { &_nodeMutex };
_localIDMap.erase(killedNode->getLocalID());
}
handleNodeKill(killedNode);
}
}

View file

@ -431,7 +431,7 @@ private slots:
private:
mutable QReadWriteLock _sessionUUIDLock;
QUuid _sessionUUID;
using LocalIDMapping = std::unordered_map<Node::LocalID, SharedNodePointer>;
using LocalIDMapping = tbb::concurrent_unordered_map<Node::LocalID, SharedNodePointer>;
LocalIDMapping _localIDMap;
Node::LocalID _sessionLocalID { 0 };
};