aboutsummaryrefslogtreecommitdiffstats
path: root/src/output_all.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-10-29 17:06:40 +0100
committerMax Kellermann <max@duempel.org>2009-10-29 17:06:40 +0100
commitbde3d1433997af8cc430f4b9d38e5bde97d3b760 (patch)
tree59ed180c3d0bf9f7b37065eea3fa13d7ffd72286 /src/output_all.c
parent1403172ef397c3dfc58a64c999a362cca977241b (diff)
downloadmpd-bde3d1433997af8cc430f4b9d38e5bde97d3b760.tar.gz
mpd-bde3d1433997af8cc430f4b9d38e5bde97d3b760.tar.xz
mpd-bde3d1433997af8cc430f4b9d38e5bde97d3b760.zip
output: consistently lock audio output objects
Always keep the audio_output object locked within the output thread, unless a plugin method is called. This fixes several race conditions.
Diffstat (limited to 'src/output_all.c')
-rw-r--r--src/output_all.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/output_all.c b/src/output_all.c
index a16be7386..05cd1d350 100644
--- a/src/output_all.c
+++ b/src/output_all.c
@@ -180,10 +180,18 @@ audio_output_all_enable_disable(void)
static bool
audio_output_all_finished(void)
{
- for (unsigned i = 0; i < num_audio_outputs; ++i)
- if (audio_output_is_open(&audio_outputs[i]) &&
- !audio_output_command_is_finished(&audio_outputs[i]))
+ for (unsigned i = 0; i < num_audio_outputs; ++i) {
+ struct audio_output *ao = &audio_outputs[i];
+ bool not_finished;
+
+ g_mutex_lock(ao->mutex);
+ not_finished = audio_output_is_open(ao) &&
+ !audio_output_command_is_finished(ao);
+ g_mutex_unlock(ao->mutex);
+
+ if (not_finished)
return false;
+ }
return true;
}
@@ -261,8 +269,7 @@ audio_output_all_play(struct music_chunk *chunk)
music_pipe_push(g_mp, chunk);
for (i = 0; i < num_audio_outputs; ++i)
- if (audio_output_is_open(&audio_outputs[i]))
- audio_output_play(&audio_outputs[i]);
+ audio_output_play(&audio_outputs[i]);
return true;
}
@@ -454,8 +461,7 @@ audio_output_all_pause(void)
audio_output_all_update();
for (i = 0; i < num_audio_outputs; ++i)
- if (audio_output_is_open(&audio_outputs[i]))
- audio_output_pause(&audio_outputs[i]);
+ audio_output_pause(&audio_outputs[i]);
audio_output_wait_all();
}
@@ -467,10 +473,8 @@ audio_output_all_cancel(void)
/* send the cancel() command to all audio outputs */
- for (i = 0; i < num_audio_outputs; ++i) {
- if (audio_output_is_open(&audio_outputs[i]))
- audio_output_cancel(&audio_outputs[i]);
- }
+ for (i = 0; i < num_audio_outputs; ++i)
+ audio_output_cancel(&audio_outputs[i]);
audio_output_wait_all();