From 3888ef2f5504ab5b6b92d9fe1a9a4c0cbabecf0b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 25 Apr 2009 15:19:01 +0200 Subject: decoder_control: properly cancel an existing command in dc_stop() When the decoder thread has a pending command, send the STOP command to cancel this command. Send STOP again if the decoder thread is still running after that, just in case the decoder thread has executed the previous command (which was overwritten). --- src/decoder_control.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/decoder_control.c b/src/decoder_control.c index 7aa80c2c6..44bb63e15 100644 --- a/src/decoder_control.c +++ b/src/decoder_control.c @@ -80,8 +80,14 @@ dc_start_async(struct song *song) void dc_stop(struct notify *notify) { - if (dc.command == DECODE_COMMAND_START || - (dc.state != DECODE_STATE_STOP && dc.state != DECODE_STATE_ERROR)) + if (dc.command != DECODE_COMMAND_NONE) + /* Attempt to cancel the current command. If it's too + late and the decoder thread is already executing + the old command, we'll call STOP again in this + function (see below). */ + dc_command(notify, DECODE_COMMAND_STOP); + + if (dc.state != DECODE_STATE_STOP && dc.state != DECODE_STATE_ERROR) dc_command(notify, DECODE_COMMAND_STOP); } -- cgit v1.2.3