summaryrefslogtreecommitdiffstats
path: root/uisimulator/sdl/thread-sdl.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-10-26 23:11:18 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-10-26 23:11:18 +0000
commitd6af28739747099f98f541d1b76ba501882e113c (patch)
treeb6ad8d89d0ef96dd4cea37dd89aad8d3fa345179 /uisimulator/sdl/thread-sdl.c
parentf026c0fc826149a3c88d462cca02b69ef5690c30 (diff)
downloadrockbox-d6af28739747099f98f541d1b76ba501882e113c.tar.gz
rockbox-d6af28739747099f98f541d1b76ba501882e113c.tar.bz2
rockbox-d6af28739747099f98f541d1b76ba501882e113c.zip
Implement as genuine a set_irq_level function for the sim as possible. The yield added earlier is still nescessary since other threads won't run anyway while viewing the database screen on either sim or target.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15321 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl/thread-sdl.c')
-rw-r--r--uisimulator/sdl/thread-sdl.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/uisimulator/sdl/thread-sdl.c b/uisimulator/sdl/thread-sdl.c
index 6a3c4af9eb..a07ac29738 100644
--- a/uisimulator/sdl/thread-sdl.c
+++ b/uisimulator/sdl/thread-sdl.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <memory.h>
#include <setjmp.h>
+#include "system-sdl.h"
#include "thread-sdl.h"
#include "kernel.h"
#include "thread.h"
@@ -45,7 +46,8 @@ static char __name[32];
#define THREAD_PANICF(str...) \
({ fprintf(stderr, str); exit(-1); })
-/* Thread entries as in core */
+/* Thread/core entries as in rockbox core */
+struct core_entry cores[NUM_CORES];
struct thread_entry threads[MAXTHREADS];
/* Jump buffers for graceful exit - kernel threads don't stay neatly
* in their start routines responding to messages so this is the only
@@ -133,6 +135,7 @@ bool thread_sdl_init(void *param)
running->name = "main";
running->state = STATE_RUNNING;
running->context.c = SDL_CreateCond();
+ cores[CURRENT_CORE].irq_level = STAY_IRQ_LEVEL;
if (running->context.c == NULL)
{
@@ -154,16 +157,6 @@ bool thread_sdl_init(void *param)
return true;
}
-void thread_sdl_lock(void)
-{
- SDL_LockMutex(m);
-}
-
-void thread_sdl_unlock(void)
-{
- SDL_UnlockMutex(m);
-}
-
static int find_empty_thread_slot(void)
{
int n;
@@ -220,6 +213,17 @@ static void remove_from_list_l(struct thread_entry **list,
thread->l.next->l.prev = thread->l.prev;
}
+static void run_blocking_ops(void)
+{
+ int level = cores[CURRENT_CORE].irq_level;
+
+ if (level != STAY_IRQ_LEVEL)
+ {
+ cores[CURRENT_CORE].irq_level = STAY_IRQ_LEVEL;
+ set_irq_level(level);
+ }
+}
+
struct thread_entry *thread_get_current(void)
{
return running;
@@ -373,6 +377,8 @@ void _block_thread(struct thread_queue *tq)
thread->bqp = tq;
add_to_list_l(&tq->queue, thread);
+ run_blocking_ops();
+
SDL_CondWait(thread->context.c, m);
running = thread;
@@ -388,6 +394,8 @@ void block_thread_w_tmo(struct thread_queue *tq, int ticks)
thread->bqp = tq;
add_to_list_l(&tq->queue, thread);
+ run_blocking_ops();
+
SDL_CondWaitTimeout(thread->context.c, m, (1000/HZ) * ticks);
running = thread;
@@ -451,6 +459,8 @@ void remove_thread(struct thread_entry *thread)
SDL_Thread *t;
SDL_cond *c;
+ int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
+
if (thread == NULL)
{
thread = current;
@@ -486,10 +496,12 @@ void remove_thread(struct thread_entry *thread)
{
/* Do a graceful exit - perform the longjmp back into the thread
function to return */
+ set_irq_level(oldlevel);
longjmp(thread_jmpbufs[current - threads], 1);
}
SDL_KillThread(t);
+ set_irq_level(oldlevel);
}
void thread_wait(struct thread_entry *thread)