diff options
author | Max Kellermann <max@duempel.org> | 2009-10-31 17:02:12 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-10-31 17:02:12 +0100 |
commit | 25a806a347ce420126eb75d82c5fb875eb0a5e0d (patch) | |
tree | 0d39bed8c073a720acd42f17b04dbee91b0a8c01 /src/decoder_control.c | |
parent | 73cff374fd94a1c16e0201fcda020396c0f41962 (diff) | |
download | mpd-25a806a347ce420126eb75d82c5fb875eb0a5e0d.tar.gz mpd-25a806a347ce420126eb75d82c5fb875eb0a5e0d.tar.xz mpd-25a806a347ce420126eb75d82c5fb875eb0a5e0d.zip |
player_control: protect command, state, error with a mutex
Use GMutex/GCond instead of the notify library. Manually lock the
player_control object before accessing the protected attributes. Use
the GCond object to notify the player thread and the main thread.
Diffstat (limited to '')
-rw-r--r-- | src/decoder_control.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/decoder_control.c b/src/decoder_control.c index 3b993431c..d7f5808fc 100644 --- a/src/decoder_control.c +++ b/src/decoder_control.c @@ -18,7 +18,7 @@ */ #include "decoder_control.h" -#include "notify.h" +#include "player_control.h" #include <assert.h> @@ -40,38 +40,34 @@ void dc_deinit(void) } static void -dc_command_wait_locked(struct notify *notify) +dc_command_wait_locked(void) { while (dc.command != DECODE_COMMAND_NONE) { decoder_signal(); - decoder_unlock(); - - notify_wait(notify); - - decoder_lock(); + player_wait_decoder(); } } void -dc_command_wait(struct notify *notify) +dc_command_wait(void) { decoder_lock(); - dc_command_wait_locked(notify); + dc_command_wait_locked(); decoder_unlock(); } static void -dc_command_locked(struct notify *notify, enum decoder_command cmd) +dc_command_locked(enum decoder_command cmd) { dc.command = cmd; - dc_command_wait_locked(notify); + dc_command_wait_locked(); } static void -dc_command(struct notify *notify, enum decoder_command cmd) +dc_command(enum decoder_command cmd) { decoder_lock(); - dc_command_locked(notify, cmd); + dc_command_locked(cmd); decoder_unlock(); } @@ -86,13 +82,13 @@ static void dc_command_async(enum decoder_command cmd) } void -dc_start(struct notify *notify, struct song *song) +dc_start(struct song *song) { assert(dc.pipe != NULL); assert(song != NULL); dc.next_song = song; - dc_command(notify, DECODE_COMMAND_START); + dc_command(DECODE_COMMAND_START); } void @@ -106,7 +102,7 @@ dc_start_async(struct song *song) } void -dc_stop(struct notify *notify) +dc_stop(void) { decoder_lock(); @@ -115,16 +111,16 @@ dc_stop(struct notify *notify) late and the decoder thread is already executing the old command, we'll call STOP again in this function (see below). */ - dc_command_locked(notify, DECODE_COMMAND_STOP); + dc_command_locked(DECODE_COMMAND_STOP); if (dc.state != DECODE_STATE_STOP && dc.state != DECODE_STATE_ERROR) - dc_command_locked(notify, DECODE_COMMAND_STOP); + dc_command_locked(DECODE_COMMAND_STOP); decoder_unlock(); } bool -dc_seek(struct notify *notify, double where) +dc_seek(double where) { assert(dc.state != DECODE_STATE_START); assert(where >= 0.0); @@ -135,7 +131,7 @@ dc_seek(struct notify *notify, double where) dc.seek_where = where; dc.seek_error = false; - dc_command(notify, DECODE_COMMAND_SEEK); + dc_command(DECODE_COMMAND_SEEK); if (dc.seek_error) return false; |