summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2010-05-27 21:36:04 +0000
committerMichael Sevakis <jethead71@rockbox.org>2010-05-27 21:36:04 +0000
commit6ce5279ff33d98480e438866900c9328d654d01b (patch)
tree2590305e9e73868447a5e0eed09cd39cfd32bd5c /firmware/target/hosted/sdl
parent8ea056db4b6c60e2e623cd0e79ccb64aea5bec51 (diff)
downloadrockbox-6ce5279ff33d98480e438866900c9328d654d01b.tar.gz
rockbox-6ce5279ff33d98480e438866900c9328d654d01b.zip
Simulator: get rid of SDL_mutex* parameter to sim_do_exit.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26338 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/sdl')
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c5
-rw-r--r--firmware/target/hosted/sdl/system-sdl.h1
-rw-r--r--firmware/target/hosted/sdl/thread-sdl.c30
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
147void sim_do_exit(SDL_mutex *m) 147void 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);
45void sys_poweroff(void); 45void sys_poweroff(void);
46void sys_handle_argv(int argc, char *argv[]); 46void sys_handle_argv(int argc, char *argv[]);
47bool gui_message_loop(void); 47bool gui_message_loop(void);
48void sim_do_exit(void);
48 49
49extern bool background; /* True if the background image is enabled */ 50extern bool background; /* True if the background image is enabled */
50extern bool showremote; 51extern 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 */
62static SDL_mutex *m; 62static SDL_mutex *m;
63static volatile bool threads_exit = false; 63#define THREADS_RUN 0
64#define THREADS_EXIT 1
65#define THREADS_EXIT_COMMAND_DONE 2
66static volatile int threads_status = THREADS_RUN;
64 67
65extern long start_tick; 68extern long start_tick;
66 69
67void sim_do_exit(SDL_mutex *m);
68
69void sim_thread_shutdown(void) 70void 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
127static void new_thread_id(unsigned int slot_num, 131static 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
217void sim_thread_exception_wait(void) 227void 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",