mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 02:56:55 +02:00
algorithm->nestedEach in LimitedNodeList
This commit is contained in:
parent
28960681d9
commit
b2f995d3df
2 changed files with 4 additions and 7 deletions
|
@ -391,10 +391,7 @@ void AudioMixer::start() {
|
||||||
|
|
||||||
auto timer = _frameTiming.timer();
|
auto timer = _frameTiming.timer();
|
||||||
|
|
||||||
// aquire the read-lock in a single thread, to avoid canonical rwlock undefined behaviors
|
nodeList->nestedEach([&](NodeList::const_iterator cbegin, NodeList::const_iterator cend) {
|
||||||
// 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) {
|
|
||||||
// prepare frames; pop off any new audio from their streams
|
// prepare frames; pop off any new audio from their streams
|
||||||
{
|
{
|
||||||
auto timer = _prepareTiming.timer();
|
auto timer = _prepareTiming.timer();
|
||||||
|
|
|
@ -175,15 +175,15 @@ public:
|
||||||
|
|
||||||
SharedNodePointer findNodeWithAddr(const HifiSockAddr& addr);
|
SharedNodePointer findNodeWithAddr(const HifiSockAddr& addr);
|
||||||
|
|
||||||
// for use with algorithm
|
|
||||||
using value_type = SharedNodePointer;
|
using value_type = SharedNodePointer;
|
||||||
using const_iterator = std::vector<value_type>::const_iterator;
|
using const_iterator = std::vector<value_type>::const_iterator;
|
||||||
|
|
||||||
// Cede control of iteration under a single read lock (e.g. for use by thread pools)
|
// 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
|
// 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
|
// without deadlocking when a dying node attempts to acquire a write lock
|
||||||
template<typename NodeAlgorithmLambda>
|
template<typename NestedNodeLambda>
|
||||||
void algorithm(NodeAlgorithmLambda functor) {
|
void nestedEach(NestedNodeLambda functor) {
|
||||||
QReadLocker readLock(&_nodeMutex);
|
QReadLocker readLock(&_nodeMutex);
|
||||||
|
|
||||||
std::vector<SharedNodePointer> nodes(_nodeHash.size());
|
std::vector<SharedNodePointer> nodes(_nodeHash.size());
|
||||||
|
|
Loading…
Reference in a new issue