aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-09-16 22:16:14 +0200
committerMax Kellermann <max@duempel.org>2011-09-17 07:30:59 +0200
commit27206368da2357375cb40ef052b7a3c1f866f884 (patch)
treeba2ec968abdb97d124b0cd6a683f50177f8fdba5 /src/output
parent443e96381a0e24d9c22578ba6f7fb96de1814994 (diff)
downloadmpd-27206368da2357375cb40ef052b7a3c1f866f884.tar.gz
mpd-27206368da2357375cb40ef052b7a3c1f866f884.tar.xz
mpd-27206368da2357375cb40ef052b7a3c1f866f884.zip
output/pulse: improve locking
Always lock the main loop when operating on PULSE objects. Document this.
Diffstat (limited to 'src/output')
-rw-r--r--src/output/pulse_output_plugin.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/output/pulse_output_plugin.c b/src/output/pulse_output_plugin.c
index 911835e46..5fe2f572e 100644
--- a/src/output/pulse_output_plugin.c
+++ b/src/output/pulse_output_plugin.c
@@ -248,6 +248,8 @@ pulse_output_delete_stream(struct pulse_output *po)
/**
* Frees and clears the context.
+ *
+ * Caller must lock the main loop.
*/
static void
pulse_output_delete_context(struct pulse_output *po)
@@ -266,6 +268,8 @@ pulse_output_delete_context(struct pulse_output *po)
/**
* Create, set up and connect a context.
*
+ * Caller must lock the main loop.
+ *
* @return true on success, false on error
*/
static bool
@@ -356,12 +360,8 @@ pulse_output_enable(void *data, GError **error_r)
return false;
}
- pa_threaded_mainloop_unlock(po->mainloop);
-
/* create the libpulse context and connect it */
- pa_threaded_mainloop_lock(po->mainloop);
-
if (!pulse_output_setup_context(po, error_r)) {
pa_threaded_mainloop_unlock(po->mainloop);
pa_threaded_mainloop_stop(po->mainloop);
@@ -393,6 +393,8 @@ pulse_output_disable(void *data)
* Check if the context is (already) connected, and waits if not. If
* the context has been disconnected, retry to connect.
*
+ * Caller must lock the main loop.
+ *
* @return true on success, false on error
*/
static bool
@@ -402,8 +404,6 @@ pulse_output_wait_connection(struct pulse_output *po, GError **error_r)
pa_context_state_t state;
- pa_threaded_mainloop_lock(po->mainloop);
-
if (po->context == NULL && !pulse_output_setup_context(po, error_r))
return false;
@@ -412,7 +412,6 @@ pulse_output_wait_connection(struct pulse_output *po, GError **error_r)
switch (state) {
case PA_CONTEXT_READY:
/* nothing to do */
- pa_threaded_mainloop_unlock(po->mainloop);
return true;
case PA_CONTEXT_UNCONNECTED:
@@ -423,7 +422,6 @@ pulse_output_wait_connection(struct pulse_output *po, GError **error_r)
"failed to connect: %s",
pa_strerror(pa_context_errno(po->context)));
pulse_output_delete_context(po);
- pa_threaded_mainloop_unlock(po->mainloop);
return false;
case PA_CONTEXT_CONNECTING:
@@ -506,6 +504,8 @@ pulse_output_open(void *data, struct audio_format *audio_format,
assert(po->mainloop != NULL);
+ pa_threaded_mainloop_lock(po->mainloop);
+
if (po->context != NULL) {
switch (pa_context_get_state(po->context)) {
case PA_CONTEXT_UNCONNECTED:
@@ -525,8 +525,10 @@ pulse_output_open(void *data, struct audio_format *audio_format,
}
}
- if (!pulse_output_wait_connection(po, error_r))
+ if (!pulse_output_wait_connection(po, error_r)) {
+ pa_threaded_mainloop_unlock(po->mainloop);
return false;
+ }
/* MPD doesn't support the other pulseaudio sample formats, so
we just force MPD to send us everything as 16 bit */
@@ -536,8 +538,6 @@ pulse_output_open(void *data, struct audio_format *audio_format,
ss.rate = audio_format->sample_rate;
ss.channels = audio_format->channels;
- pa_threaded_mainloop_lock(po->mainloop);
-
/* create a stream .. */
po->stream = pa_stream_new(po->context, po->name, &ss, NULL);