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).
This commit is contained in:
Max Kellermann 2009-04-25 15:19:01 +02:00
parent ceb00f787e
commit 3888ef2f55

View File

@ -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);
}