Commit 8fe03b8b authored by Max Kellermann's avatar Max Kellermann

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.
parent c01aa53e
...@@ -100,3 +100,10 @@ dc_seek(struct notify *notify, double where) ...@@ -100,3 +100,10 @@ dc_seek(struct notify *notify, double where)
return true; return true;
} }
void
dc_quit(struct notify *notify)
{
dc.quit = true;
dc_command(notify, DECODE_COMMAND_STOP);
}
...@@ -49,6 +49,7 @@ struct decoder_control { ...@@ -49,6 +49,7 @@ struct decoder_control {
volatile enum decoder_state state; volatile enum decoder_state state;
volatile enum decoder_command command; volatile enum decoder_command command;
bool quit;
bool seek_error; bool seek_error;
bool seekable; bool seekable;
volatile double seek_where; volatile double seek_where;
...@@ -122,4 +123,7 @@ dc_stop(struct notify *notify); ...@@ -122,4 +123,7 @@ dc_stop(struct notify *notify);
bool bool
dc_seek(struct notify *notify, double where); dc_seek(struct notify *notify, double where);
void
dc_quit(struct notify *notify);
#endif #endif
...@@ -204,7 +204,7 @@ static void decoder_run(void) ...@@ -204,7 +204,7 @@ static void decoder_run(void)
static void * decoder_task(G_GNUC_UNUSED void *arg) static void * decoder_task(G_GNUC_UNUSED void *arg)
{ {
while (1) { do {
assert(dc.state == DECODE_STATE_STOP || assert(dc.state == DECODE_STATE_STOP ||
dc.state == DECODE_STATE_ERROR); dc.state == DECODE_STATE_ERROR);
...@@ -226,7 +226,7 @@ static void * decoder_task(G_GNUC_UNUSED void *arg) ...@@ -226,7 +226,7 @@ static void * decoder_task(G_GNUC_UNUSED void *arg)
notify_wait(&dc.notify); notify_wait(&dc.notify);
break; break;
} }
} } while (dc.command != DECODE_COMMAND_NONE || !dc.quit);
return NULL; return NULL;
} }
......
...@@ -514,6 +514,7 @@ static void * player_task(G_GNUC_UNUSED void *arg) ...@@ -514,6 +514,7 @@ static void * player_task(G_GNUC_UNUSED void *arg)
break; break;
case PLAYER_COMMAND_EXIT: case PLAYER_COMMAND_EXIT:
dc_quit(&pc.notify);
closeAudioDevice(); closeAudioDevice();
player_command_finished(); player_command_finished();
pthread_exit(NULL); pthread_exit(NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment