From 6ce5279ff33d98480e438866900c9328d654d01b Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 27 May 2010 21:36:04 +0000 Subject: Simulator: get rid of SDL_mutex* parameter to sim_do_exit. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26338 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/hosted/sdl/thread-sdl.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'firmware/target/hosted/sdl/thread-sdl.c') diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c index ec6718d6f8..5ef9867b23 100644 --- a/firmware/target/hosted/sdl/thread-sdl.c +++ b/firmware/target/hosted/sdl/thread-sdl.c @@ -60,12 +60,13 @@ static jmp_buf thread_jmpbufs[MAXTHREADS]; * that enables us to simulate a cooperative environment even if * the host is preemptive */ static SDL_mutex *m; -static volatile bool threads_exit = false; +#define THREADS_RUN 0 +#define THREADS_EXIT 1 +#define THREADS_EXIT_COMMAND_DONE 2 +static volatile int threads_status = THREADS_RUN; extern long start_tick; -void sim_do_exit(SDL_mutex *m); - void sim_thread_shutdown(void) { int i; @@ -79,7 +80,7 @@ void sim_thread_shutdown(void) on each unlock but that is safe. */ /* Do this before trying to acquire lock */ - threads_exit = true; + threads_status = THREADS_EXIT; /* Take control */ SDL_LockMutex(m); @@ -122,6 +123,9 @@ void sim_thread_shutdown(void) } SDL_UnlockMutex(m); + + /* Signal completion of operation */ + threads_status = THREADS_EXIT_COMMAND_DONE; } static void new_thread_id(unsigned int slot_num, @@ -210,8 +214,14 @@ void init_threads(void) SDL_UnlockMutex(m); - /* doesn't return */ - sim_do_exit(m); + /* Set to 'COMMAND_DONE' when other rockbox threads have exited. */ + while (threads_status < THREADS_EXIT_COMMAND_DONE) + SDL_Delay(10); + + SDL_DestroyMutex(m); + + /* We're the main thead - perform exit - doesn't return. */ + sim_do_exit(); } void sim_thread_exception_wait(void) @@ -219,7 +229,7 @@ void sim_thread_exception_wait(void) while (1) { SDL_Delay(HZ/10); - if (threads_exit) + if (threads_status != THREADS_RUN) thread_exit(); } } @@ -230,7 +240,7 @@ void sim_thread_lock(void *me) SDL_LockMutex(m); cores[CURRENT_CORE].running = (struct thread_entry *)me; - if (threads_exit) + if (threads_status != THREADS_RUN) thread_exit(); } @@ -371,7 +381,7 @@ void switch_thread(void) cores[CURRENT_CORE].running = current; - if (threads_exit) + if (threads_status != THREADS_RUN) thread_exit(); } @@ -474,7 +484,7 @@ int runthread(void *data) cores[CURRENT_CORE].running = current; } - if (!threads_exit) + if (threads_status == THREADS_RUN) { current->context.start(); THREAD_SDL_DEBUGF("Thread Done: %d (%s)\n", -- cgit v1.2.3