From 2b3e2fda71a31bdad46ddc5ae876ccabc661467e Mon Sep 17 00:00:00 2001 From: jethead71 Date: Thu, 27 May 2010 21:36:04 +0000 Subject: [PATCH] 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/system-sdl.c | 5 +---- firmware/target/hosted/sdl/system-sdl.h | 1 + firmware/target/hosted/sdl/thread-sdl.c | 30 ++++++++++++++++++++---------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c index d56f1d787..ff4fe6570 100644 --- a/firmware/target/hosted/sdl/system-sdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c @@ -144,14 +144,11 @@ static int sdl_event_thread(void * param) return 0; } -void sim_do_exit(SDL_mutex *m) +void sim_do_exit(void) { /* wait for event thread to finish */ SDL_WaitThread(evt_thread, NULL); - /* cleanup */ - SDL_DestroyMutex(m); - SDL_Quit(); exit(EXIT_SUCCESS); while(1); diff --git a/firmware/target/hosted/sdl/system-sdl.h b/firmware/target/hosted/sdl/system-sdl.h index 53af7b835..dcb21f36b 100644 --- a/firmware/target/hosted/sdl/system-sdl.h +++ b/firmware/target/hosted/sdl/system-sdl.h @@ -45,6 +45,7 @@ void sim_kernel_shutdown(void); void sys_poweroff(void); void sys_handle_argv(int argc, char *argv[]); bool gui_message_loop(void); +void sim_do_exit(void); extern bool background; /* True if the background image is enabled */ extern bool showremote; diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c index ec6718d6f..5ef9867b2 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", -- 2.11.4.GIT