maintain the attach status in a boolean variable 'attach' accessible from the IO thread for sink_inputs/source_outputs

git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1872 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2007-09-20 20:30:03 +00:00
parent 75647bc38f
commit c40c1682be
6 changed files with 109 additions and 89 deletions

View file

@ -210,6 +210,7 @@ pa_sink_input* pa_sink_input_new(
i->thread_info.resampler = resampler; i->thread_info.resampler = resampler;
i->thread_info.volume = i->volume; i->thread_info.volume = i->volume;
i->thread_info.muted = i->muted; i->thread_info.muted = i->muted;
i->thread_info.attached = FALSE;
pa_assert_se(pa_idxset_put(core->sink_inputs, pa_sink_input_ref(i), &i->index) == 0); pa_assert_se(pa_idxset_put(core->sink_inputs, pa_sink_input_ref(i), &i->index) == 0);
pa_assert_se(pa_idxset_put(i->sink->inputs, i, NULL) == 0); pa_assert_se(pa_idxset_put(i->sink->inputs, i, NULL) == 0);
@ -308,6 +309,8 @@ static void sink_input_free(pa_object *o) {
pa_log_info("Freeing output %u \"%s\"", i->index, i->name); pa_log_info("Freeing output %u \"%s\"", i->index, i->name);
pa_assert(!i->thread_info.attached);
if (i->thread_info.resampled_chunk.memblock) if (i->thread_info.resampled_chunk.memblock)
pa_memblock_unref(i->thread_info.resampled_chunk.memblock); pa_memblock_unref(i->thread_info.resampled_chunk.memblock);
@ -915,4 +918,3 @@ pa_sink_input_state_t pa_sink_input_get_state(pa_sink_input *i) {
return i->state; return i->state;
} }

View file

@ -125,6 +125,8 @@ struct pa_sink_input {
pa_sink_input_state_t state; pa_sink_input_state_t state;
pa_atomic_t drained; pa_atomic_t drained;
pa_bool_t attached; /* True only between ->attach() and ->detach() calls */
pa_sample_spec sample_spec; pa_sample_spec sample_spec;
pa_memchunk resampled_chunk; pa_memchunk resampled_chunk;

View file

@ -813,6 +813,9 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
i->thread_info.sync_next->thread_info.sync_prev = i; i->thread_info.sync_next->thread_info.sync_prev = i;
} }
pa_assert(!i->thread_info.attached);
i->thread_info.attached = TRUE;
if (i->attach) if (i->attach)
i->attach(i); i->attach(i);
@ -825,6 +828,9 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
if (i->detach) if (i->detach)
i->detach(i); i->detach(i);
pa_assert(i->thread_info.attached);
i->thread_info.attached = FALSE;
/* Since the caller sleeps in pa_sink_input_unlink(), /* Since the caller sleeps in pa_sink_input_unlink(),
* we can safely access data outside of thread_info even * we can safely access data outside of thread_info even
* though it is mutable */ * though it is mutable */
@ -1016,4 +1022,3 @@ void pa_sink_attach_within_thread(pa_sink *s) {
if (s->monitor_source) if (s->monitor_source)
pa_source_attach_within_thread(s->monitor_source); pa_source_attach_within_thread(s->monitor_source);
} }

View file

@ -156,6 +156,7 @@ pa_source_output* pa_source_output_new(
o->userdata = NULL; o->userdata = NULL;
o->thread_info.state = o->state; o->thread_info.state = o->state;
o->thread_info.attached = FALSE;
o->thread_info.sample_spec = o->sample_spec; o->thread_info.sample_spec = o->sample_spec;
o->thread_info.resampler = resampler; o->thread_info.resampler = resampler;
@ -231,6 +232,8 @@ static void source_output_free(pa_object* mo) {
pa_log_info("Freeing output %u \"%s\"", o->index, o->name); pa_log_info("Freeing output %u \"%s\"", o->index, o->name);
pa_assert(!o->thread_info.attached);
if (o->thread_info.resampler) if (o->thread_info.resampler)
pa_resampler_free(o->thread_info.resampler); pa_resampler_free(o->thread_info.resampler);

View file

@ -100,6 +100,8 @@ struct pa_source_output {
struct { struct {
pa_source_output_state_t state; pa_source_output_state_t state;
pa_bool_t attached; /* True only between ->attach() and ->detach() calls */
pa_sample_spec sample_spec; pa_sample_spec sample_spec;
pa_resampler* resampler; /* may be NULL */ pa_resampler* resampler; /* may be NULL */

View file

@ -456,6 +456,9 @@ int pa_source_process_msg(pa_msgobject *object, int code, void *userdata, int64_
pa_source_output *o = PA_SOURCE_OUTPUT(userdata); pa_source_output *o = PA_SOURCE_OUTPUT(userdata);
pa_hashmap_put(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index), pa_source_output_ref(o)); pa_hashmap_put(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index), pa_source_output_ref(o));
pa_assert(!o->thread_info.attached);
o->thread_info.attached = TRUE;
if (o->attach) if (o->attach)
o->attach(o); o->attach(o);
@ -468,6 +471,9 @@ int pa_source_process_msg(pa_msgobject *object, int code, void *userdata, int64_
if (o->detach) if (o->detach)
o->detach(o); o->detach(o);
pa_assert(o->thread_info.attached);
o->thread_info.attached = FALSE;
if (pa_hashmap_remove(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index))) if (pa_hashmap_remove(s->thread_info.outputs, PA_UINT32_TO_PTR(o->index)))
pa_source_output_unref(o); pa_source_output_unref(o);