summaryrefslogtreecommitdiffstats
path: root/firmware
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
parent8ea056db4b6c60e2e623cd0e79ccb64aea5bec51 (diff)
downloadrockbox-6ce5279ff33d98480e438866900c9328d654d01b.tar.gz
rockbox-6ce5279ff33d98480e438866900c9328d654d01b.tar.bz2
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')
-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)
return 0;
}
-void sim_do_exit(SDL_mutex *m)
+void sim_do_exit(void)
{
/* wait for event thread to finish */
SDL_WaitThread(evt_thread, NULL);
- /* cleanup */
- SDL_DestroyMutex(m);
-
SDL_Quit();
exit(EXIT_SUCCESS);
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);
void sys_poweroff(void);
void sys_handle_argv(int argc, char *argv[]);
bool gui_message_loop(void);
+void sim_do_exit(void);
extern bool background; /* True if the background image is enabled */
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];
* that enables us to simulate a cooperative environment even if
* the host is preemptive */
static SDL_mutex *m;
-static volatile bool threads_exit = false;
+#define THREADS_RUN 0
+#define THREADS_EXIT 1
+#define THREADS_EXIT_COMMAND_DONE 2
+static volatile int threads_status = THREADS_RUN;
extern long start_tick;
-void sim_do_exit(SDL_mutex *m);
-
void sim_thread_shutdown(void)
{
int i;
@@ -79,7 +80,7 @@ void sim_thread_shutdown(void)
on each unlock but that is safe. */
/* Do this before trying to acquire lock */
- threads_exit = true;
+ threads_status = THREADS_EXIT;
/* Take control */
SDL_LockMutex(m);
@@ -122,6 +123,9 @@ void sim_thread_shutdown(void)
}
SDL_UnlockMutex(m);
+
+ /* Signal completion of operation */
+ threads_status = THREADS_EXIT_COMMAND_DONE;
}
static void new_thread_id(unsigned int slot_num,
@@ -210,8 +214,14 @@ void init_threads(void)
SDL_UnlockMutex(m);
- /* doesn't return */
- sim_do_exit(m);
+ /* Set to 'COMMAND_DONE' when other rockbox threads have exited. */
+ while (threads_status < THREADS_EXIT_COMMAND_DONE)
+ SDL_Delay(10);
+
+ SDL_DestroyMutex(m);
+
+ /* We're the main thead - perform exit - doesn't return. */
+ sim_do_exit();
}
void sim_thread_exception_wait(void)
@@ -219,7 +229,7 @@ void sim_thread_exception_wait(void)
while (1)
{
SDL_Delay(HZ/10);
- if (threads_exit)
+ if (threads_status != THREADS_RUN)
thread_exit();
}
}
@@ -230,7 +240,7 @@ void sim_thread_lock(void *me)
SDL_LockMutex(m);
cores[CURRENT_CORE].running = (struct thread_entry *)me;
- if (threads_exit)
+ if (threads_status != THREADS_RUN)
thread_exit();
}
@@ -371,7 +381,7 @@ void switch_thread(void)
cores[CURRENT_CORE].running = current;
- if (threads_exit)
+ if (threads_status != THREADS_RUN)
thread_exit();
}
@@ -474,7 +484,7 @@ int runthread(void *data)
cores[CURRENT_CORE].running = current;
}
- if (!threads_exit)
+ if (threads_status == THREADS_RUN)
{
current->context.start();
THREAD_SDL_DEBUGF("Thread Done: %d (%s)\n",