aboutsummaryrefslogtreecommitdiffstats
path: root/src/output_control.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/output_control.c')
-rw-r--r--src/output_control.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/src/output_control.c b/src/output_control.c
index 0823b667b..8efe08f05 100644
--- a/src/output_control.c
+++ b/src/output_control.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -38,6 +38,11 @@ enum {
struct notify audio_output_client_notify;
+/**
+ * Waits for command completion.
+ *
+ * @param ao the #audio_output instance; must be locked
+ */
static void ao_command_wait(struct audio_output *ao)
{
while (ao->command != AO_COMMAND_NONE) {
@@ -47,20 +52,43 @@ static void ao_command_wait(struct audio_output *ao)
}
}
-static void ao_command(struct audio_output *ao, enum audio_output_command cmd)
+/**
+ * Sends a command to the #audio_output object, but does not wait for
+ * completion.
+ *
+ * @param ao the #audio_output instance; must be locked
+ */
+static void ao_command_async(struct audio_output *ao,
+ enum audio_output_command cmd)
{
assert(ao->command == AO_COMMAND_NONE);
ao->command = cmd;
g_cond_signal(ao->cond);
+}
+
+/**
+ * Sends a command to the #audio_output object and waits for
+ * completion.
+ *
+ * @param ao the #audio_output instance; must be locked
+ */
+static void
+ao_command(struct audio_output *ao, enum audio_output_command cmd)
+{
+ ao_command_async(ao, cmd);
ao_command_wait(ao);
}
-static void ao_command_async(struct audio_output *ao,
- enum audio_output_command cmd)
+/**
+ * Lock the #audio_output object and execute the command
+ * synchronously.
+ */
+static void
+ao_lock_command(struct audio_output *ao, enum audio_output_command cmd)
{
- assert(ao->command == AO_COMMAND_NONE);
- ao->command = cmd;
- g_cond_signal(ao->cond);
+ g_mutex_lock(ao->mutex);
+ ao_command(ao, cmd);
+ g_mutex_unlock(ao->mutex);
}
void
@@ -78,9 +106,7 @@ audio_output_enable(struct audio_output *ao)
audio_output_thread_start(ao);
}
- g_mutex_lock(ao->mutex);
- ao_command(ao, AO_COMMAND_ENABLE);
- g_mutex_unlock(ao->mutex);
+ ao_lock_command(ao, AO_COMMAND_ENABLE);
}
void
@@ -97,9 +123,7 @@ audio_output_disable(struct audio_output *ao)
return;
}
- g_mutex_lock(ao->mutex);
- ao_command(ao, AO_COMMAND_DISABLE);
- g_mutex_unlock(ao->mutex);
+ ao_lock_command(ao, AO_COMMAND_DISABLE);
}
static void
@@ -286,9 +310,7 @@ void audio_output_finish(struct audio_output *ao)
assert(ao->fail_timer == NULL);
if (ao->thread != NULL) {
- g_mutex_lock(ao->mutex);
- ao_command(ao, AO_COMMAND_KILL);
- g_mutex_unlock(ao->mutex);
+ ao_lock_command(ao, AO_COMMAND_KILL);
g_thread_join(ao->thread);
}