[pulseaudio-discuss] [PATCH 2/4] sink, source: add missing stream "attached" flag handling

Tanu Kaskinen tanuk at iki.fi
Wed Dec 7 23:59:03 UTC 2016


The functions that call attach()/detach() for all streams on a sink or
source didn't update the "attached" flag accordingly. Since the flag is
only used in assertions, this omission didn't cause any harm in normal
use.
---
 src/pulsecore/sink.c   | 12 ++++++++++--
 src/pulsecore/source.c | 12 ++++++++++--
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 29aef26..64f2ef7 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -2928,9 +2928,13 @@ void pa_sink_detach_within_thread(pa_sink *s) {
     pa_sink_assert_io_context(s);
     pa_assert(PA_SINK_IS_LINKED(s->thread_info.state));
 
-    PA_HASHMAP_FOREACH(i, s->thread_info.inputs, state)
+    PA_HASHMAP_FOREACH(i, s->thread_info.inputs, state) {
+        pa_assert(i->thread_info.attached);
+        i->thread_info.attached = false;
+
         if (i->detach)
             i->detach(i);
+    }
 
     if (s->monitor_source)
         pa_source_detach_within_thread(s->monitor_source);
@@ -2945,9 +2949,13 @@ void pa_sink_attach_within_thread(pa_sink *s) {
     pa_sink_assert_io_context(s);
     pa_assert(PA_SINK_IS_LINKED(s->thread_info.state));
 
-    PA_HASHMAP_FOREACH(i, s->thread_info.inputs, state)
+    PA_HASHMAP_FOREACH(i, s->thread_info.inputs, state) {
+        pa_assert(!i->thread_info.attached);
+        i->thread_info.attached = true;
+
         if (i->attach)
             i->attach(i);
+    }
 
     if (s->monitor_source)
         pa_source_attach_within_thread(s->monitor_source);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index daed8ad..44bdad8 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -2285,9 +2285,13 @@ void pa_source_detach_within_thread(pa_source *s) {
     pa_source_assert_io_context(s);
     pa_assert(PA_SOURCE_IS_LINKED(s->thread_info.state));
 
-    PA_HASHMAP_FOREACH(o, s->thread_info.outputs, state)
+    PA_HASHMAP_FOREACH(o, s->thread_info.outputs, state) {
+        pa_assert(o->thread_info.attached);
+        o->thread_info.attached = false;
+
         if (o->detach)
             o->detach(o);
+    }
 }
 
 /* Called from IO thread */
@@ -2299,9 +2303,13 @@ void pa_source_attach_within_thread(pa_source *s) {
     pa_source_assert_io_context(s);
     pa_assert(PA_SOURCE_IS_LINKED(s->thread_info.state));
 
-    PA_HASHMAP_FOREACH(o, s->thread_info.outputs, state)
+    PA_HASHMAP_FOREACH(o, s->thread_info.outputs, state) {
+        pa_assert(!o->thread_info.attached);
+        o->thread_info.attached = true;
+
         if (o->attach)
             o->attach(o);
+    }
 }
 
 /* Called from IO thread */
-- 
2.10.2



More information about the pulseaudio-discuss mailing list