decoder: terminate decoder thread before MPD cleanup

When MPD exits, it should manually free all resources in use, to allow
easy memory leak debugging.  Make the decoder thread terminate during
that.
This commit is contained in:
Max Kellermann 2008-12-28 19:48:53 +01:00
parent c01aa53e6a
commit 8fe03b8bce
4 changed files with 14 additions and 2 deletions

View File

@ -100,3 +100,10 @@ dc_seek(struct notify *notify, double where)
return true;
}
void
dc_quit(struct notify *notify)
{
dc.quit = true;
dc_command(notify, DECODE_COMMAND_STOP);
}

View File

@ -49,6 +49,7 @@ struct decoder_control {
volatile enum decoder_state state;
volatile enum decoder_command command;
bool quit;
bool seek_error;
bool seekable;
volatile double seek_where;
@ -122,4 +123,7 @@ dc_stop(struct notify *notify);
bool
dc_seek(struct notify *notify, double where);
void
dc_quit(struct notify *notify);
#endif

View File

@ -204,7 +204,7 @@ static void decoder_run(void)
static void * decoder_task(G_GNUC_UNUSED void *arg)
{
while (1) {
do {
assert(dc.state == DECODE_STATE_STOP ||
dc.state == DECODE_STATE_ERROR);
@ -226,7 +226,7 @@ static void * decoder_task(G_GNUC_UNUSED void *arg)
notify_wait(&dc.notify);
break;
}
}
} while (dc.command != DECODE_COMMAND_NONE || !dc.quit);
return NULL;
}

View File

@ -514,6 +514,7 @@ static void * player_task(G_GNUC_UNUSED void *arg)
break;
case PLAYER_COMMAND_EXIT:
dc_quit(&pc.notify);
closeAudioDevice();
player_command_finished();
pthread_exit(NULL);