diff options
author | Max Kellermann <max@duempel.org> | 2010-11-04 22:47:51 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2010-11-04 23:28:18 +0100 |
commit | 9562f667412dc620bed7299477c8a5bd86e399c4 (patch) | |
tree | 76fcc4f86dac7aa0de23d3ae8a5d262d574a3856 /src/output_control.c | |
parent | 21223154aa3a3c794a3842aa8a5c85198ce85220 (diff) | |
download | mpd-9562f667412dc620bed7299477c8a5bd86e399c4.tar.gz mpd-9562f667412dc620bed7299477c8a5bd86e399c4.tar.xz mpd-9562f667412dc620bed7299477c8a5bd86e399c4.zip |
output_control: lock object in audio_output_open()
Protect the attributes "open" and "fail_timer".
Diffstat (limited to 'src/output_control.c')
-rw-r--r-- | src/output_control.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/output_control.c b/src/output_control.c index dd562f303..ecd226821 100644 --- a/src/output_control.c +++ b/src/output_control.c @@ -72,6 +72,12 @@ static void ao_command_async(struct audio_output *ao, notify_signal(&ao->notify); } +static void +audio_output_close_locked(struct audio_output *ao); + +/** + * Object must be locked (and unlocked) by the caller. + */ static bool audio_output_open(struct audio_output *ao, const struct audio_format *audio_format, @@ -98,7 +104,7 @@ audio_output_open(struct audio_output *ao, /* we're not using audio_output_cancel() here, because that function is asynchronous */ - ao_command(ao, AO_COMMAND_CANCEL); + ao_command_locked(ao, AO_COMMAND_CANCEL); } return true; @@ -109,7 +115,7 @@ audio_output_open(struct audio_output *ao, if (!ao->config_audio_format) { if (ao->open) - audio_output_close(ao); + audio_output_close_locked(ao); /* no audio format is configured: copy in->out, let the output's open() method determine the effective @@ -124,7 +130,7 @@ audio_output_open(struct audio_output *ao, open = ao->open; if (!open) { - ao_command(ao, AO_COMMAND_OPEN); + ao_command_locked(ao, AO_COMMAND_OPEN); open = ao->open; } @@ -141,12 +147,19 @@ audio_output_update(struct audio_output *ao, { assert(mp != NULL); + g_mutex_lock(ao->mutex); + if (ao->enabled) { if (ao->fail_timer == NULL || - g_timer_elapsed(ao->fail_timer, NULL) > REOPEN_AFTER) - return audio_output_open(ao, audio_format, mp); + g_timer_elapsed(ao->fail_timer, NULL) > REOPEN_AFTER) { + bool ret = audio_output_open(ao, audio_format, mp); + g_mutex_unlock(ao->mutex); + return ret; + } } else if (audio_output_is_open(ao)) - audio_output_close(ao); + audio_output_close_locked(ao); + + g_mutex_unlock(ao->mutex); return false; } |