summaryrefslogtreecommitdiff
path: root/uisimulator/sdl/thread-sdl.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-09-09 01:59:07 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-09-09 01:59:07 +0000
commit0107dfc8276d73744bb097d643809205ef21d97b (patch)
tree17d434f51652d949d8167abaf85fe0eacd33612a /uisimulator/sdl/thread-sdl.c
parent424750ea95409c6e78188aa47fe7a0f47d1127cb (diff)
downloadrockbox-0107dfc8276d73744bb097d643809205ef21d97b.tar.gz
rockbox-0107dfc8276d73744bb097d643809205ef21d97b.zip
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
Diffstat (limited to 'uisimulator/sdl/thread-sdl.c')
-rw-r--r--uisimulator/sdl/thread-sdl.c25
1 files changed, 24 insertions, 1 deletions
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;
48static SDL_sem *s; 48static SDL_sem *s;
49static struct thread_entry *running; 49static struct thread_entry *running;
50 50
51extern long start_tick;
52
51void kill_sim_threads(void) 53void kill_sim_threads(void)
52{ 54{
53 int i; 55 int i;
@@ -62,6 +64,7 @@ void kill_sim_threads(void)
62 SDL_SemPost(s); 64 SDL_SemPost(s);
63 else 65 else
64 SDL_CondSignal(thread->context.c); 66 SDL_CondSignal(thread->context.c);
67 SDL_Delay(10);
65 SDL_KillThread(thread->context.t); 68 SDL_KillThread(thread->context.t);
66 SDL_DestroyCond(thread->context.c); 69 SDL_DestroyCond(thread->context.c);
67 } 70 }
@@ -129,6 +132,16 @@ struct thread_entry *thread_get_current(void)
129 return running; 132 return running;
130} 133}
131 134
135void thread_sdl_lock(void)
136{
137 SDL_LockMutex(m);
138}
139
140void thread_sdl_unlock(void)
141{
142 SDL_UnlockMutex(m);
143}
144
132void switch_thread(bool save_context, struct thread_entry **blocked_list) 145void switch_thread(bool save_context, struct thread_entry **blocked_list)
133{ 146{
134 struct thread_entry *current = running; 147 struct thread_entry *current = running;
@@ -137,6 +150,8 @@ void switch_thread(bool save_context, struct thread_entry **blocked_list)
137 150
138 SDL_SemWait(s); 151 SDL_SemWait(s);
139 152
153 SDL_Delay(0);
154
140 SDL_LockMutex(m); 155 SDL_LockMutex(m);
141 running = current; 156 running = current;
142 157
@@ -148,11 +163,19 @@ void switch_thread(bool save_context, struct thread_entry **blocked_list)
148void sleep_thread(int ticks) 163void sleep_thread(int ticks)
149{ 164{
150 struct thread_entry *current; 165 struct thread_entry *current;
166 int rem;
151 167
152 current = running; 168 current = running;
153 current->statearg = STATE_SLEEPING; 169 current->statearg = STATE_SLEEPING;
154 170
155 SDL_CondWaitTimeout(current->context.c, m, (1000/HZ) * ticks + (500/HZ)); 171 rem = (SDL_GetTicks() - start_tick) % (1000/HZ);
172 if (rem < 0)
173 rem = 0;
174
175 SDL_UnlockMutex(m);
176 SDL_Delay((1000/HZ) * ticks + ((1000/HZ)-1) - rem);
177 SDL_LockMutex(m);
178
156 running = current; 179 running = current;
157 180
158 current->statearg = STATE_RUNNING; 181 current->statearg = STATE_RUNNING;