diff options
Diffstat (limited to 'firmware/target/hosted/sdl')
-rw-r--r-- | firmware/target/hosted/sdl/system-sdl.c | 5 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/system-sdl.h | 1 | ||||
-rw-r--r-- | firmware/target/hosted/sdl/thread-sdl.c | 30 |
3 files changed, 22 insertions, 14 deletions
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c index d56f1d7874..ff4fe6570e 100644 --- a/firmware/target/hosted/sdl/system-sdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c | |||
@@ -144,14 +144,11 @@ static int sdl_event_thread(void * param) | |||
144 | return 0; | 144 | return 0; |
145 | } | 145 | } |
146 | 146 | ||
147 | void sim_do_exit(SDL_mutex *m) | 147 | void sim_do_exit(void) |
148 | { | 148 | { |
149 | /* wait for event thread to finish */ | 149 | /* wait for event thread to finish */ |
150 | SDL_WaitThread(evt_thread, NULL); | 150 | SDL_WaitThread(evt_thread, NULL); |
151 | 151 | ||
152 | /* cleanup */ | ||
153 | SDL_DestroyMutex(m); | ||
154 | |||
155 | SDL_Quit(); | 152 | SDL_Quit(); |
156 | exit(EXIT_SUCCESS); | 153 | exit(EXIT_SUCCESS); |
157 | while(1); | 154 | while(1); |
diff --git a/firmware/target/hosted/sdl/system-sdl.h b/firmware/target/hosted/sdl/system-sdl.h index 53af7b8355..dcb21f36bb 100644 --- a/firmware/target/hosted/sdl/system-sdl.h +++ b/firmware/target/hosted/sdl/system-sdl.h | |||
@@ -45,6 +45,7 @@ void sim_kernel_shutdown(void); | |||
45 | void sys_poweroff(void); | 45 | void sys_poweroff(void); |
46 | void sys_handle_argv(int argc, char *argv[]); | 46 | void sys_handle_argv(int argc, char *argv[]); |
47 | bool gui_message_loop(void); | 47 | bool gui_message_loop(void); |
48 | void sim_do_exit(void); | ||
48 | 49 | ||
49 | extern bool background; /* True if the background image is enabled */ | 50 | extern bool background; /* True if the background image is enabled */ |
50 | extern bool showremote; | 51 | extern bool showremote; |
diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c index ec6718d6f8..5ef9867b23 100644 --- a/firmware/target/hosted/sdl/thread-sdl.c +++ b/firmware/target/hosted/sdl/thread-sdl.c | |||
@@ -60,12 +60,13 @@ static jmp_buf thread_jmpbufs[MAXTHREADS]; | |||
60 | * that enables us to simulate a cooperative environment even if | 60 | * that enables us to simulate a cooperative environment even if |
61 | * the host is preemptive */ | 61 | * the host is preemptive */ |
62 | static SDL_mutex *m; | 62 | static SDL_mutex *m; |
63 | static volatile bool threads_exit = false; | 63 | #define THREADS_RUN 0 |
64 | #define THREADS_EXIT 1 | ||
65 | #define THREADS_EXIT_COMMAND_DONE 2 | ||
66 | static volatile int threads_status = THREADS_RUN; | ||
64 | 67 | ||
65 | extern long start_tick; | 68 | extern long start_tick; |
66 | 69 | ||
67 | void sim_do_exit(SDL_mutex *m); | ||
68 | |||
69 | void sim_thread_shutdown(void) | 70 | void sim_thread_shutdown(void) |
70 | { | 71 | { |
71 | int i; | 72 | int i; |
@@ -79,7 +80,7 @@ void sim_thread_shutdown(void) | |||
79 | on each unlock but that is safe. */ | 80 | on each unlock but that is safe. */ |
80 | 81 | ||
81 | /* Do this before trying to acquire lock */ | 82 | /* Do this before trying to acquire lock */ |
82 | threads_exit = true; | 83 | threads_status = THREADS_EXIT; |
83 | 84 | ||
84 | /* Take control */ | 85 | /* Take control */ |
85 | SDL_LockMutex(m); | 86 | SDL_LockMutex(m); |
@@ -122,6 +123,9 @@ void sim_thread_shutdown(void) | |||
122 | } | 123 | } |
123 | 124 | ||
124 | SDL_UnlockMutex(m); | 125 | SDL_UnlockMutex(m); |
126 | |||
127 | /* Signal completion of operation */ | ||
128 | threads_status = THREADS_EXIT_COMMAND_DONE; | ||
125 | } | 129 | } |
126 | 130 | ||
127 | static void new_thread_id(unsigned int slot_num, | 131 | static void new_thread_id(unsigned int slot_num, |
@@ -210,8 +214,14 @@ void init_threads(void) | |||
210 | 214 | ||
211 | SDL_UnlockMutex(m); | 215 | SDL_UnlockMutex(m); |
212 | 216 | ||
213 | /* doesn't return */ | 217 | /* Set to 'COMMAND_DONE' when other rockbox threads have exited. */ |
214 | sim_do_exit(m); | 218 | while (threads_status < THREADS_EXIT_COMMAND_DONE) |
219 | SDL_Delay(10); | ||
220 | |||
221 | SDL_DestroyMutex(m); | ||
222 | |||
223 | /* We're the main thead - perform exit - doesn't return. */ | ||
224 | sim_do_exit(); | ||
215 | } | 225 | } |
216 | 226 | ||
217 | void sim_thread_exception_wait(void) | 227 | void sim_thread_exception_wait(void) |
@@ -219,7 +229,7 @@ void sim_thread_exception_wait(void) | |||
219 | while (1) | 229 | while (1) |
220 | { | 230 | { |
221 | SDL_Delay(HZ/10); | 231 | SDL_Delay(HZ/10); |
222 | if (threads_exit) | 232 | if (threads_status != THREADS_RUN) |
223 | thread_exit(); | 233 | thread_exit(); |
224 | } | 234 | } |
225 | } | 235 | } |
@@ -230,7 +240,7 @@ void sim_thread_lock(void *me) | |||
230 | SDL_LockMutex(m); | 240 | SDL_LockMutex(m); |
231 | cores[CURRENT_CORE].running = (struct thread_entry *)me; | 241 | cores[CURRENT_CORE].running = (struct thread_entry *)me; |
232 | 242 | ||
233 | if (threads_exit) | 243 | if (threads_status != THREADS_RUN) |
234 | thread_exit(); | 244 | thread_exit(); |
235 | } | 245 | } |
236 | 246 | ||
@@ -371,7 +381,7 @@ void switch_thread(void) | |||
371 | 381 | ||
372 | cores[CURRENT_CORE].running = current; | 382 | cores[CURRENT_CORE].running = current; |
373 | 383 | ||
374 | if (threads_exit) | 384 | if (threads_status != THREADS_RUN) |
375 | thread_exit(); | 385 | thread_exit(); |
376 | } | 386 | } |
377 | 387 | ||
@@ -474,7 +484,7 @@ int runthread(void *data) | |||
474 | cores[CURRENT_CORE].running = current; | 484 | cores[CURRENT_CORE].running = current; |
475 | } | 485 | } |
476 | 486 | ||
477 | if (!threads_exit) | 487 | if (threads_status == THREADS_RUN) |
478 | { | 488 | { |
479 | current->context.start(); | 489 | current->context.start(); |
480 | THREAD_SDL_DEBUGF("Thread Done: %d (%s)\n", | 490 | THREAD_SDL_DEBUGF("Thread Done: %d (%s)\n", |