summaryrefslogtreecommitdiff
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 @@
19 19
20#include <stdlib.h> 20#include <stdlib.h>
21#include <string.h> 21#include <string.h>
22#include <setjmp.h>
22#include "autoconf.h" 23#include "autoconf.h"
23#include "button.h" 24#include "button.h"
24#include "thread.h" 25#include "thread.h"
@@ -41,7 +42,7 @@
41extern void app_main (void *); /* mod entry point */ 42extern void app_main (void *); /* mod entry point */
42extern void new_key(int key); 43extern void new_key(int key);
43extern void sim_tick_tasks(void); 44extern void sim_tick_tasks(void);
44extern void sim_io_init(void); 45extern bool sim_io_init(void);
45extern void sim_io_shutdown(void); 46extern void sim_io_shutdown(void);
46 47
47void button_event(int key, bool pressed); 48void button_event(int key, bool pressed);
@@ -49,7 +50,6 @@ void button_event(int key, bool pressed);
49SDL_Surface *gui_surface; 50SDL_Surface *gui_surface;
50bool background = false; /* Don't use backgrounds by default */ 51bool background = false; /* Don't use backgrounds by default */
51 52
52SDL_Thread *gui_thread;
53SDL_TimerID tick_timer_id; 53SDL_TimerID tick_timer_id;
54 54
55bool lcd_display_redraw = true; /* Used for player simulator */ 55bool lcd_display_redraw = true; /* Used for player simulator */
@@ -170,21 +170,13 @@ bool gui_startup(void)
170bool gui_shutdown(void) 170bool gui_shutdown(void)
171{ 171{
172 SDL_RemoveTimer(tick_timer_id); 172 SDL_RemoveTimer(tick_timer_id);
173 kill_sim_threads(); 173 /* Order here is relevent to prevent deadlocks and use of destroyed
174 sync primitives by kernel threads */
175 thread_sdl_shutdown();
174 sim_io_shutdown(); 176 sim_io_shutdown();
175 return true; 177 return true;
176} 178}
177 179
178/**
179 * Thin wrapper around normal app_main() to stop gcc complaining about types.
180 */
181int sim_app_main(void *param)
182{
183 app_main(param);
184
185 return 0;
186}
187
188#if defined(WIN32) && defined(main) 180#if defined(WIN32) && defined(main)
189/* Don't use SDL_main on windows -> no more stdio redirection */ 181/* Don't use SDL_main on windows -> no more stdio redirection */
190#undef main 182#undef main
@@ -231,14 +223,19 @@ int main(int argc, char *argv[])
231 background = false; 223 background = false;
232 } 224 }
233 225
234 sim_io_init(); 226 if (!sim_io_init()) {
227 fprintf(stderr, "sim_io_init failed\n");
228 return -1;
229 }
235 230
236 if (!gui_startup()) 231 if (!gui_startup()) {
232 fprintf(stderr, "gui_startup failed\n");
237 return -1; 233 return -1;
234 }
238 235
239 gui_thread = SDL_CreateThread(sim_app_main, NULL); 236 /* app_main will be called by the new main thread */
240 if (gui_thread == NULL) { 237 if (!thread_sdl_init(NULL)) {
241 printf("Error creating GUI thread!\n"); 238 fprintf(stderr, "thread_sdl_init failed\n");
242 return -1; 239 return -1;
243 } 240 }
244 241