diff options
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/sdl/thread-sdl.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/uisimulator/sdl/thread-sdl.c b/uisimulator/sdl/thread-sdl.c index 8769b5d84f..d146cfb64b 100644 --- a/uisimulator/sdl/thread-sdl.c +++ b/uisimulator/sdl/thread-sdl.c | |||
@@ -45,7 +45,6 @@ static char __name[32]; | |||
45 | 45 | ||
46 | struct thread_entry threads[MAXTHREADS]; /* Thread entries as in core */ | 46 | struct thread_entry threads[MAXTHREADS]; /* Thread entries as in core */ |
47 | static SDL_mutex *m; | 47 | static SDL_mutex *m; |
48 | static SDL_sem *s; | ||
49 | static struct thread_entry *running; | 48 | static struct thread_entry *running; |
50 | 49 | ||
51 | extern long start_tick; | 50 | extern long start_tick; |
@@ -60,9 +59,7 @@ void kill_sim_threads(void) | |||
60 | if (thread->context.t != NULL) | 59 | if (thread->context.t != NULL) |
61 | { | 60 | { |
62 | SDL_LockMutex(m); | 61 | SDL_LockMutex(m); |
63 | if (thread->statearg == STATE_RUNNING) | 62 | if (thread->statearg != STATE_RUNNING) |
64 | SDL_SemPost(s); | ||
65 | else | ||
66 | SDL_CondSignal(thread->context.c); | 63 | SDL_CondSignal(thread->context.c); |
67 | SDL_Delay(10); | 64 | SDL_Delay(10); |
68 | SDL_KillThread(thread->context.t); | 65 | SDL_KillThread(thread->context.t); |
@@ -70,7 +67,6 @@ void kill_sim_threads(void) | |||
70 | } | 67 | } |
71 | } | 68 | } |
72 | SDL_DestroyMutex(m); | 69 | SDL_DestroyMutex(m); |
73 | SDL_DestroySemaphore(s); | ||
74 | } | 70 | } |
75 | 71 | ||
76 | static int find_empty_thread_slot(void) | 72 | static int find_empty_thread_slot(void) |
@@ -144,19 +140,20 @@ void thread_sdl_unlock(void) | |||
144 | 140 | ||
145 | void switch_thread(bool save_context, struct thread_entry **blocked_list) | 141 | void switch_thread(bool save_context, struct thread_entry **blocked_list) |
146 | { | 142 | { |
143 | static int counter = 0; | ||
147 | struct thread_entry *current = running; | 144 | struct thread_entry *current = running; |
148 | 145 | ||
149 | SDL_UnlockMutex(m); | 146 | SDL_UnlockMutex(m); |
150 | 147 | ||
151 | SDL_SemWait(s); | 148 | if (counter++ >= 50) |
152 | 149 | { | |
153 | SDL_Delay(0); | 150 | SDL_Delay(0); |
151 | counter = 0; | ||
152 | } | ||
154 | 153 | ||
155 | SDL_LockMutex(m); | 154 | SDL_LockMutex(m); |
156 | running = current; | 155 | running = current; |
157 | 156 | ||
158 | SDL_SemPost(s); | ||
159 | |||
160 | (void)save_context; (void)blocked_list; | 157 | (void)save_context; (void)blocked_list; |
161 | } | 158 | } |
162 | 159 | ||
@@ -299,7 +296,6 @@ void init_threads(void) | |||
299 | int slot; | 296 | int slot; |
300 | 297 | ||
301 | m = SDL_CreateMutex(); | 298 | m = SDL_CreateMutex(); |
302 | s = SDL_CreateSemaphore(0); | ||
303 | 299 | ||
304 | memset(threads, 0, sizeof(threads)); | 300 | memset(threads, 0, sizeof(threads)); |
305 | 301 | ||
@@ -324,10 +320,6 @@ void init_threads(void) | |||
324 | if (SDL_LockMutex(m) == -1) { | 320 | if (SDL_LockMutex(m) == -1) { |
325 | THREAD_PANICF("Couldn't lock mutex\n"); | 321 | THREAD_PANICF("Couldn't lock mutex\n"); |
326 | } | 322 | } |
327 | |||
328 | if (SDL_SemPost(s) == -1) { | ||
329 | THREAD_PANICF("Couldn't post to semaphore\n"); | ||
330 | } | ||
331 | } | 323 | } |
332 | 324 | ||
333 | void remove_thread(struct thread_entry *thread) | 325 | void remove_thread(struct thread_entry *thread) |
@@ -347,9 +339,7 @@ void remove_thread(struct thread_entry *thread) | |||
347 | 339 | ||
348 | if (thread != current) | 340 | if (thread != current) |
349 | { | 341 | { |
350 | if (thread->statearg == STATE_RUNNING) | 342 | if (thread->statearg != STATE_RUNNING) |
351 | SDL_SemPost(s); | ||
352 | else | ||
353 | SDL_CondSignal(c); | 343 | SDL_CondSignal(c); |
354 | } | 344 | } |
355 | 345 | ||