diff options
Diffstat (limited to 'firmware/target/hosted/sdl/system-sdl.c')
-rw-r--r-- | firmware/target/hosted/sdl/system-sdl.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c index d6c0dfa345..d56f1d7874 100644 --- a/firmware/target/hosted/sdl/system-sdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c | |||
@@ -54,6 +54,8 @@ bool sim_alarm_wakeup = false; | |||
54 | const char *sim_root_dir = NULL; | 54 | const char *sim_root_dir = NULL; |
55 | extern int display_zoom; | 55 | extern int display_zoom; |
56 | 56 | ||
57 | static SDL_Thread *evt_thread = NULL; | ||
58 | |||
57 | #ifdef DEBUG | 59 | #ifdef DEBUG |
58 | bool debug_audio = false; | 60 | bool debug_audio = false; |
59 | #endif | 61 | #endif |
@@ -64,16 +66,11 @@ int wps_verbose_level = 3; | |||
64 | 66 | ||
65 | void sys_poweroff(void) | 67 | void sys_poweroff(void) |
66 | { | 68 | { |
67 | /* Order here is relevent to prevent deadlocks and use of destroyed | ||
68 | sync primitives by kernel threads */ | ||
69 | sim_thread_shutdown(); | ||
70 | sim_kernel_shutdown(); | ||
71 | SDL_Quit(); | ||
72 | } | 69 | } |
73 | 70 | ||
74 | /* | 71 | /* |
75 | * Button read loop */ | 72 | * Button read loop */ |
76 | void gui_message_loop(void); | 73 | bool gui_message_loop(void); |
77 | 74 | ||
78 | /* | 75 | /* |
79 | * This thread will read the buttons in an interrupt like fashion, and | 76 | * This thread will read the buttons in an interrupt like fashion, and |
@@ -137,12 +134,28 @@ static int sdl_event_thread(void * param) | |||
137 | 134 | ||
138 | /* | 135 | /* |
139 | * finally enter the button loop */ | 136 | * finally enter the button loop */ |
140 | while(1) | 137 | while(gui_message_loop()); |
141 | gui_message_loop(); | 138 | |
139 | /* Order here is relevent to prevent deadlocks and use of destroyed | ||
140 | sync primitives by kernel threads */ | ||
141 | sim_thread_shutdown(); | ||
142 | sim_kernel_shutdown(); | ||
142 | 143 | ||
143 | return 0; | 144 | return 0; |
144 | } | 145 | } |
145 | 146 | ||
147 | void sim_do_exit(SDL_mutex *m) | ||
148 | { | ||
149 | /* wait for event thread to finish */ | ||
150 | SDL_WaitThread(evt_thread, NULL); | ||
151 | |||
152 | /* cleanup */ | ||
153 | SDL_DestroyMutex(m); | ||
154 | |||
155 | SDL_Quit(); | ||
156 | exit(EXIT_SUCCESS); | ||
157 | while(1); | ||
158 | } | ||
146 | 159 | ||
147 | void system_init(void) | 160 | void system_init(void) |
148 | { | 161 | { |
@@ -150,11 +163,10 @@ void system_init(void) | |||
150 | 163 | ||
151 | if (SDL_Init(SDL_INIT_TIMER)) | 164 | if (SDL_Init(SDL_INIT_TIMER)) |
152 | panicf("%s", SDL_GetError()); | 165 | panicf("%s", SDL_GetError()); |
153 | atexit(sys_poweroff); | ||
154 | 166 | ||
155 | s = SDL_CreateSemaphore(0); /* 0-count so it blocks */ | 167 | s = SDL_CreateSemaphore(0); /* 0-count so it blocks */ |
156 | 168 | ||
157 | SDL_CreateThread(sdl_event_thread, s); | 169 | evt_thread = SDL_CreateThread(sdl_event_thread, s); |
158 | 170 | ||
159 | /* wait for sdl_event_thread to run so that it can initialize the surfaces | 171 | /* wait for sdl_event_thread to run so that it can initialize the surfaces |
160 | * and video subsystem needed for SDL events */ | 172 | * and video subsystem needed for SDL events */ |