From 0107dfc8276d73744bb097d643809205ef21d97b Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sun, 9 Sep 2007 01:59:07 +0000 Subject: UISIMULATOR: Give the host OS some needed context switching hints (which _is_ supposed to work on Linux - but I can't tell on VMWare - and does on Windows). I guess I'll know for sure soon. Give sleep() even more genuine behavior. Add some button driver sync with the rockbox threads that should have been there for some time - this is basically interrupt-like processing as any thread not in the kernel pool should be considered. Make the screendump work again by posting the request. Perhaps help out shutting down for some users but not in the way I'd prefer - to think about. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14646 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/sdl/thread-sdl.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'uisimulator/sdl/thread-sdl.c') diff --git a/uisimulator/sdl/thread-sdl.c b/uisimulator/sdl/thread-sdl.c index aac8e2fbb9..8769b5d84f 100644 --- a/uisimulator/sdl/thread-sdl.c +++ b/uisimulator/sdl/thread-sdl.c @@ -48,6 +48,8 @@ static SDL_mutex *m; static SDL_sem *s; static struct thread_entry *running; +extern long start_tick; + void kill_sim_threads(void) { int i; @@ -62,6 +64,7 @@ void kill_sim_threads(void) SDL_SemPost(s); else SDL_CondSignal(thread->context.c); + SDL_Delay(10); SDL_KillThread(thread->context.t); SDL_DestroyCond(thread->context.c); } @@ -129,6 +132,16 @@ struct thread_entry *thread_get_current(void) return running; } +void thread_sdl_lock(void) +{ + SDL_LockMutex(m); +} + +void thread_sdl_unlock(void) +{ + SDL_UnlockMutex(m); +} + void switch_thread(bool save_context, struct thread_entry **blocked_list) { struct thread_entry *current = running; @@ -137,6 +150,8 @@ void switch_thread(bool save_context, struct thread_entry **blocked_list) SDL_SemWait(s); + SDL_Delay(0); + SDL_LockMutex(m); running = current; @@ -148,11 +163,19 @@ void switch_thread(bool save_context, struct thread_entry **blocked_list) void sleep_thread(int ticks) { struct thread_entry *current; + int rem; current = running; current->statearg = STATE_SLEEPING; - SDL_CondWaitTimeout(current->context.c, m, (1000/HZ) * ticks + (500/HZ)); + rem = (SDL_GetTicks() - start_tick) % (1000/HZ); + if (rem < 0) + rem = 0; + + SDL_UnlockMutex(m); + SDL_Delay((1000/HZ) * ticks + ((1000/HZ)-1) - rem); + SDL_LockMutex(m); + running = current; current->statearg = STATE_RUNNING; -- cgit v1.2.3