From b2f995d3df233ddd2143e21e66f6415d5af4d009 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 7 Dec 2016 00:00:03 +0000 Subject: [PATCH] algorithm->nestedEach in LimitedNodeList --- assignment-client/src/audio/AudioMixer.cpp | 5 +---- libraries/networking/src/LimitedNodeList.h | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index 1d41bc1bfd..9608f7c63b 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -391,10 +391,7 @@ void AudioMixer::start() { auto timer = _frameTiming.timer(); - // aquire the read-lock in a single thread, to avoid canonical rwlock undefined behaviors - // node removal will acquire a write lock; - // read locks (in slave threads) while a write lock is pending have undefined order in pthread - nodeList->algorithm([&](NodeList::const_iterator cbegin, NodeList::const_iterator cend) { + nodeList->nestedEach([&](NodeList::const_iterator cbegin, NodeList::const_iterator cend) { // prepare frames; pop off any new audio from their streams { auto timer = _prepareTiming.timer(); diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index ef26d87ec7..c635744512 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -175,15 +175,15 @@ public: SharedNodePointer findNodeWithAddr(const HifiSockAddr& addr); - // for use with algorithm using value_type = SharedNodePointer; using const_iterator = std::vector::const_iterator; // Cede control of iteration under a single read lock (e.g. for use by thread pools) + // Use this for nested loops instead of taking nested read locks! // This allows multiple threads (i.e. a thread pool) to share a lock // without deadlocking when a dying node attempts to acquire a write lock - template - void algorithm(NodeAlgorithmLambda functor) { + template + void nestedEach(NestedNodeLambda functor) { QReadLocker readLock(&_nodeMutex); std::vector nodes(_nodeHash.size());