From 28a7c5d3692e59b5c80a9f713cf931b6453cb1ca Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Wed, 26 May 2010 21:11:40 +0000 Subject: UISimulator: cleaner startup using semaphore only to tell when event_thread is done initializing. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26317 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/hosted/sdl/system-sdl.c | 37 ++++++++++----------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c index 7ab6fd2c34..d6c0dfa345 100644 --- a/firmware/target/hosted/sdl/system-sdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c @@ -75,17 +75,6 @@ void sys_poweroff(void) * Button read loop */ void gui_message_loop(void); -/* - * This callback let's the main thread run again after SDL has been initialized - **/ -static uint32_t cond_signal(uint32_t interval, void *param) -{ - (void)interval; - SDL_cond *c = (SDL_cond*)param; - /* remove timer, CondSignal returns 0 on success */ - return SDL_CondSignal(c); -} - /* * This thread will read the buttons in an interrupt like fashion, and * also initializes SDL_INIT_VIDEO and the surfaces @@ -143,9 +132,9 @@ static int sdl_event_thread(void * param) if (background && picture_surface != NULL) SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); - /* calling SDL_CondSignal() right away here doesn't work reliably so - * post-pone it a bit */ - SDL_AddTimer(100, cond_signal, param); + /* let system_init proceed */ + SDL_SemPost((SDL_sem *)param); + /* * finally enter the button loop */ while(1) @@ -157,26 +146,22 @@ static int sdl_event_thread(void * param) void system_init(void) { - SDL_cond *c; - SDL_mutex *m; + SDL_sem *s; + if (SDL_Init(SDL_INIT_TIMER)) panicf("%s", SDL_GetError()); atexit(sys_poweroff); - c = SDL_CreateCond(); - m = SDL_CreateMutex(); + s = SDL_CreateSemaphore(0); /* 0-count so it blocks */ - SDL_CreateThread(sdl_event_thread, c); + SDL_CreateThread(sdl_event_thread, s); - /* Lock mutex and wait for sdl_event_thread to run so that it can - * initialize the surfaces and video subsystem needed for SDL events */ - SDL_LockMutex(m); - SDL_CondWait(c, m); - SDL_UnlockMutex(m); + /* wait for sdl_event_thread to run so that it can initialize the surfaces + * and video subsystem needed for SDL events */ + SDL_SemWait(s); /* cleanup */ - SDL_DestroyCond(c); - SDL_DestroyMutex(m); + SDL_DestroySemaphore(s); } void system_exception_wait(void) -- cgit v1.2.3