From 5b7052254185beb9f8cde9216b1fa25764b5eeb6 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 26 Dec 2016 12:55:18 +0100 Subject: [PATCH] Mixer: Make reset operation more robust This change makes the operation more robust as it flags the whole group invalid in the first step. This should not be confused with being thread-safe - to be thread-safe, all accesses to _first and the following linked list need to be guarded by a mutex. This should be done outside of the mixer in the driver though, as the method depends on the board architecture. --- src/modules/systemlib/mixer/mixer_group.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/systemlib/mixer/mixer_group.cpp b/src/modules/systemlib/mixer/mixer_group.cpp index 3b3d606cb8..9ba34a729b 100644 --- a/src/modules/systemlib/mixer/mixer_group.cpp +++ b/src/modules/systemlib/mixer/mixer_group.cpp @@ -88,11 +88,15 @@ void MixerGroup::reset() { Mixer *mixer; + Mixer *next = _first; + + /* flag mixer as invalid */ + _first = nullptr; /* discard sub-mixers */ - while (_first != nullptr) { - mixer = _first; - _first = mixer->_next; + while (next != nullptr) { + mixer = next; + next = mixer->_next; delete mixer; mixer = nullptr; }