From d8f6c75ab94ee97e9a49ce669d74dc252225586a Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Mon, 28 Feb 2011 03:24:48 +0000 Subject: Hopefully get shutdown/exit handling on SDL/maemo right. Make shutdown_hw() not return as it's supposed to, ensure sim_do_exit() is called from main thread and move sim_kernel_shutdown() into it to simplify things. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29455 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/hosted/sdl/system-sdl.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'firmware/target/hosted/sdl/system-sdl.c') diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c index 4dc5509397..7ddc5f8699 100644 --- a/firmware/target/hosted/sdl/system-sdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c @@ -71,9 +71,10 @@ bool debug_audio = false; bool debug_wps = false; int wps_verbose_level = 3; - void sys_poweroff(void) { + /* Post SYS_POWEROFF event. Will post SDL_USEREVENT in shutdown_hw() if successful. */ + queue_broadcast(SYS_POWEROFF, 0); } /* @@ -187,16 +188,39 @@ static int sdl_event_thread(void * param) #ifdef HAVE_SDL_THREADS sim_thread_shutdown(); /* not needed for native threads */ #endif - sim_kernel_shutdown(); - return 0; } -void sim_do_exit(void) +void shutdown_hw(void) { + /* Shut down SDL event loop */ + SDL_Event event; + memset(&event, 0, sizeof(SDL_Event)); + event.type = SDL_USEREVENT; + SDL_PushEvent(&event); +#ifdef HAVE_SDL_THREADS + /* since sim_thread_shutdown() grabs the mutex we need to let it free, + * otherwise SDL_WaitThread will deadlock */ + struct thread_entry* t = sim_thread_unlock(); +#endif /* wait for event thread to finish */ SDL_WaitThread(evt_thread, NULL); +#ifdef HAVE_SDL_THREADS + /* lock again before entering the scheduler */ + sim_thread_lock(t); + /* sim_thread_shutdown() will cause sim_do_exit() to be called via longjmp, + * but only if we let the sdl thread scheduler exit the other threads */ + while(1) yield(); +#else + sim_do_exit(); +#endif +} + +void sim_do_exit() +{ + sim_kernel_shutdown(); + SDL_Quit(); exit(EXIT_SUCCESS); } -- cgit v1.2.3