From c893affeefa35975c916a222d20a989f31555646 Mon Sep 17 00:00:00 2001 From: Stéphane Doyon Date: Tue, 15 Jul 2008 14:06:11 +0000 Subject: Accept FS#8918: Voice multiple thumbnails and talk race fixes. -Allows loading multiple thumbnails back-to-back in the one thumbnail buffer. -Mutex to prevent race conditions with talk queue indices and thumbnail buffer state. -Synchronous shutup. -Shutup is a noop if no voice is queued. -mp3_play_stop() does nothing until the audio thread is ready. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18046 a1c6a512-1295-4272-9138-f99709370657 --- apps/voice_thread.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'apps/voice_thread.c') diff --git a/apps/voice_thread.c b/apps/voice_thread.c index 8d08e7744b..aeffa5bd7c 100644 --- a/apps/voice_thread.c +++ b/apps/voice_thread.c @@ -136,11 +136,12 @@ void mp3_play_data(const unsigned char* start, int size, /* Stop current voice clip from playing */ void mp3_play_stop(void) { - mutex_lock(&voice_mutex); /* Sync against voice_stop */ + if(!audio_is_thread_ready()) + return; - LOGFQUEUE("mp3 > voice Q_VOICE_STOP: 1"); - queue_remove_from_head(&voice_queue, Q_VOICE_STOP); - queue_post(&voice_queue, Q_VOICE_STOP, 1); + mutex_lock(&voice_mutex); /* Sync against voice_stop */ + LOGFQUEUE("mp3 >| voice Q_VOICE_STOP: 1"); + queue_send(&voice_queue, Q_VOICE_STOP, 1); mutex_unlock(&voice_mutex); } @@ -167,8 +168,7 @@ void voice_stop(void) mutex_lock(&voice_mutex); /* Stop the output and current clip */ - LOGFQUEUE("mp3 >| voice Q_VOICE_STOP: 1"); - queue_send(&voice_queue, Q_VOICE_STOP, 1); + mp3_play_stop(); /* Careful if using sync objects in talk.c - make sure locking order is * observed with one or the other always granted first */ @@ -298,8 +298,13 @@ static void voice_thread(void) struct voice_thread_data td; voice_data_init(&td); - audio_wait_for_init(); - + + /* audio thread will only set this once after it finished the final + * audio hardware init so this little construct is safe - even + * cross-core. */ + while (!audio_is_thread_ready()) + sleep(0); + goto message_wait; while (1) -- cgit v1.2.3