summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl/kernel-sdl.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-02-28 03:24:48 +0000
committerThomas Martitz <kugel@rockbox.org>2011-02-28 03:24:48 +0000
commitd8f6c75ab94ee97e9a49ce669d74dc252225586a (patch)
treef2eee157a098402ed5ae05866505bfa0e0a20d2b /firmware/target/hosted/sdl/kernel-sdl.c
parentd69d406e096d9df587e9b263cc16553d17b63162 (diff)
downloadrockbox-d8f6c75ab94ee97e9a49ce669d74dc252225586a.tar.gz
rockbox-d8f6c75ab94ee97e9a49ce669d74dc252225586a.zip
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
Diffstat (limited to 'firmware/target/hosted/sdl/kernel-sdl.c')
-rw-r--r--firmware/target/hosted/sdl/kernel-sdl.c32
1 files changed, 10 insertions, 22 deletions
diff --git a/firmware/target/hosted/sdl/kernel-sdl.c b/firmware/target/hosted/sdl/kernel-sdl.c
index 4fb1aede0a..5c16f86749 100644
--- a/firmware/target/hosted/sdl/kernel-sdl.c
+++ b/firmware/target/hosted/sdl/kernel-sdl.c
@@ -36,11 +36,8 @@ long start_tick;
36 36
37#ifndef HAVE_SDL_THREADS 37#ifndef HAVE_SDL_THREADS
38/* for the wait_for_interrupt function */ 38/* for the wait_for_interrupt function */
39static bool do_exit;
40static SDL_cond *wfi_cond; 39static SDL_cond *wfi_cond;
41static SDL_mutex *wfi_mutex; 40static SDL_mutex *wfi_mutex;
42#else
43#define do_exit false
44#endif 41#endif
45/* Condition to signal that "interrupts" may proceed */ 42/* Condition to signal that "interrupts" may proceed */
46static SDL_cond *sim_thread_cond; 43static SDL_cond *sim_thread_cond;
@@ -74,7 +71,7 @@ int set_irq_level(int level)
74 /* Not in a handler and "interrupts" are going from disabled to 71 /* Not in a handler and "interrupts" are going from disabled to
75 * enabled; signal any pending handlers still waiting */ 72 * enabled; signal any pending handlers still waiting */
76 if (handlers_pending > 0) 73 if (handlers_pending > 0)
77 SDL_CondSignal(sim_thread_cond); 74 SDL_CondBroadcast(sim_thread_cond);
78 } 75 }
79 76
80 interrupt_level = level; /* save new level */ 77 interrupt_level = level; /* save new level */
@@ -147,10 +144,14 @@ void sim_kernel_shutdown(void)
147{ 144{
148 SDL_RemoveTimer(tick_timer_id); 145 SDL_RemoveTimer(tick_timer_id);
149#ifndef HAVE_SDL_THREADS 146#ifndef HAVE_SDL_THREADS
150 do_exit = true; 147 SDL_DestroyCond(wfi_cond);
151 SDL_CondSignal(wfi_cond); 148 SDL_UnlockMutex(wfi_mutex);
149 SDL_DestroyMutex(wfi_mutex);
152#endif 150#endif
153 disable_irq(); 151 enable_irq();
152 while(handlers_pending > 0)
153 SDL_Delay(10);
154
154 SDL_DestroyMutex(sim_irq_mtx); 155 SDL_DestroyMutex(sim_irq_mtx);
155 SDL_DestroyCond(sim_thread_cond); 156 SDL_DestroyCond(sim_thread_cond);
156} 157}
@@ -164,7 +165,7 @@ Uint32 tick_timer(Uint32 interval, void *param)
164 165
165 new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ); 166 new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ);
166 167
167 while(new_tick != current_tick && !do_exit) 168 while(new_tick != current_tick)
168 { 169 {
169 sim_enter_irq_handler(); 170 sim_enter_irq_handler();
170 171
@@ -175,7 +176,7 @@ Uint32 tick_timer(Uint32 interval, void *param)
175 sim_exit_irq_handler(); 176 sim_exit_irq_handler();
176 } 177 }
177 178
178 return do_exit ? 0 : interval; 179 return interval;
179} 180}
180 181
181void tick_start(unsigned int interval_in_ms) 182void tick_start(unsigned int interval_in_ms)
@@ -203,23 +204,10 @@ void tick_start(unsigned int interval_in_ms)
203} 204}
204 205
205#ifndef HAVE_SDL_THREADS 206#ifndef HAVE_SDL_THREADS
206static void check_exit(void)
207{
208 if (UNLIKELY(do_exit))
209 {
210 SDL_DestroyCond(wfi_cond);
211 SDL_UnlockMutex(wfi_mutex);
212 SDL_DestroyMutex(wfi_mutex);
213 sim_do_exit();
214 }
215}
216
217void wait_for_interrupt(void) 207void wait_for_interrupt(void)
218{ 208{
219 /* the exit may come at any time, during the CondWait or before, 209 /* the exit may come at any time, during the CondWait or before,
220 * so check it twice */ 210 * so check it twice */
221 check_exit();
222 SDL_CondWait(wfi_cond, wfi_mutex); 211 SDL_CondWait(wfi_cond, wfi_mutex);
223 check_exit();
224} 212}
225#endif 213#endif