From 98150f503a808f4bb0d7be343f1a231a4c8ff0dc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 3 Nov 2009 21:02:54 +0100 Subject: player_thread: lock inside player_wait_for_decoder() Lock the player_control object when modifying its attributes. --- src/player_thread.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/player_thread.c') diff --git a/src/player_thread.c b/src/player_thread.c index e6c7ea761..91b373380 100644 --- a/src/player_thread.c +++ b/src/player_thread.c @@ -175,6 +175,11 @@ player_wait_for_decoder(struct player *player) { struct decoder_control *dc = player->dc; + assert(player->queued); + assert(pc.next_song != NULL); + + player->queued = false; + if (decoder_lock_has_failed(dc)) { player_lock(); pc.errored_song = dc->song; @@ -182,23 +187,28 @@ player_wait_for_decoder(struct player *player) pc.next_song = NULL; player_unlock(); - player->queued = false; return false; } + player->song = pc.next_song; + player->elapsed_time = 0.0; + + /* set the "starting" flag, which will be cleared by + player_check_decoder_startup() */ + player->decoder_starting = true; + + player_lock(); + + /* update player_control's song information */ pc.total_time = pc.next_song->tag != NULL ? pc.next_song->tag->time : 0; pc.bit_rate = 0; audio_format_clear(&pc.audio_format); - player->song = pc.next_song; + /* clear the queued song */ pc.next_song = NULL; - player->queued = false; - player->elapsed_time = 0.0; - /* set the "starting" flag, which will be cleared by - player_check_decoder_startup() */ - player->decoder_starting = true; + player_unlock(); /* call syncPlaylistWithQueue() in the main thread */ event_pipe_emit(PIPE_EVENT_PLAYLIST); -- cgit v1.2.3