summaryrefslogtreecommitdiffstats
path: root/uisimulator/sdl/uisdl.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-09-10 03:49:12 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-09-10 03:49:12 +0000
commitc4a7631eb9235f72de569f5e578620c6e2bc6818 (patch)
tree1e67525787351b2637fab8a4fe0ae140398c9219 /uisimulator/sdl/uisdl.c
parent2e305c6381c72aaabc6d0f92459b32d8939691fb (diff)
downloadrockbox-c4a7631eb9235f72de569f5e578620c6e2bc6818.tar.gz
rockbox-c4a7631eb9235f72de569f5e578620c6e2bc6818.zip
UISIMULATOR: Do a graceful shutdown of all threads and avoid (mostly lockup) problems caused by not worrying about states. Have rockbox objects initialized only by rockbox threads save for the main 'gui' thread which is a needed exception.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14660 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl/uisdl.c')
-rw-r--r--uisimulator/sdl/uisdl.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c
index fdd40beb23..eada01f99a 100644
--- a/uisimulator/sdl/uisdl.c
+++ b/uisimulator/sdl/uisdl.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
+#include <setjmp.h>
#include "autoconf.h"
#include "button.h"
#include "thread.h"
@@ -41,7 +42,7 @@
extern void app_main (void *); /* mod entry point */
extern void new_key(int key);
extern void sim_tick_tasks(void);
-extern void sim_io_init(void);
+extern bool sim_io_init(void);
extern void sim_io_shutdown(void);
void button_event(int key, bool pressed);
@@ -49,7 +50,6 @@ void button_event(int key, bool pressed);
SDL_Surface *gui_surface;
bool background = false; /* Don't use backgrounds by default */
-SDL_Thread *gui_thread;
SDL_TimerID tick_timer_id;
bool lcd_display_redraw = true; /* Used for player simulator */
@@ -170,21 +170,13 @@ bool gui_startup(void)
bool gui_shutdown(void)
{
SDL_RemoveTimer(tick_timer_id);
- kill_sim_threads();
+ /* Order here is relevent to prevent deadlocks and use of destroyed
+ sync primitives by kernel threads */
+ thread_sdl_shutdown();
sim_io_shutdown();
return true;
}
-/**
- * Thin wrapper around normal app_main() to stop gcc complaining about types.
- */
-int sim_app_main(void *param)
-{
- app_main(param);
-
- return 0;
-}
-
#if defined(WIN32) && defined(main)
/* Don't use SDL_main on windows -> no more stdio redirection */
#undef main
@@ -231,14 +223,19 @@ int main(int argc, char *argv[])
background = false;
}
- sim_io_init();
+ if (!sim_io_init()) {
+ fprintf(stderr, "sim_io_init failed\n");
+ return -1;
+ }
- if (!gui_startup())
+ if (!gui_startup()) {
+ fprintf(stderr, "gui_startup failed\n");
return -1;
+ }
- gui_thread = SDL_CreateThread(sim_app_main, NULL);
- if (gui_thread == NULL) {
- printf("Error creating GUI thread!\n");
+ /* app_main will be called by the new main thread */
+ if (!thread_sdl_init(NULL)) {
+ fprintf(stderr, "thread_sdl_init failed\n");
return -1;
}