From cc889e9d608e6b07b78541849b7e63b6fb3f6058 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sat, 5 Mar 2011 17:48:06 +0000 Subject: Change the thread api a bit. * Remove THREAD_ID_CURRENT macro in favor of a thread_self() function, this allows thread functions to be simpler. * thread_self_entry() shortcut for kernel.c. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29521 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/hosted/sdl/thread-sdl.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'firmware/target/hosted/sdl/thread-sdl.c') diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c index 08f20367cc..eaffa86aee 100644 --- a/firmware/target/hosted/sdl/thread-sdl.c +++ b/firmware/target/hosted/sdl/thread-sdl.c @@ -253,9 +253,7 @@ void * sim_thread_unlock(void) struct thread_entry * thread_id_entry(unsigned int thread_id) { - return (thread_id == THREAD_ID_CURRENT) ? - cores[CURRENT_CORE].running : - &threads[thread_id & THREAD_ID_SLOT_MASK]; + return &threads[thread_id & THREAD_ID_SLOT_MASK]; } static void add_to_list_l(struct thread_entry **list, @@ -299,11 +297,16 @@ static void remove_from_list_l(struct thread_entry **list, thread->l.next->l.prev = thread->l.prev; } -unsigned int thread_get_current(void) +unsigned int thread_self(void) { return cores[CURRENT_CORE].running->id; } +struct thread_entry* thread_self_entry(void) +{ + return cores[CURRENT_CORE].running; +} + void switch_thread(void) { struct thread_entry *current = cores[CURRENT_CORE].running; @@ -562,7 +565,7 @@ void remove_thread(unsigned int thread_id) SDL_Thread *t; SDL_sem *s; - if (thread_id != THREAD_ID_CURRENT && thread->id != thread_id) + if (thread->id != thread_id) return; int oldlevel = disable_irq_save(); @@ -629,11 +632,11 @@ void remove_thread(unsigned int thread_id) void thread_exit(void) { - remove_thread(THREAD_ID_CURRENT); + unsigned int id = thread_self(); + remove_thread(id); /* This should never and must never be reached - if it is, the * state is corrupted */ - THREAD_PANICF("thread_exit->K:*R (ID: %d)", - thread_id_entry(THREAD_ID_CURRENT)->id); + THREAD_PANICF("thread_exit->K:*R (ID: %d)", id); while (1); } @@ -642,8 +645,7 @@ void thread_wait(unsigned int thread_id) struct thread_entry *current = cores[CURRENT_CORE].running; struct thread_entry *thread = thread_id_entry(thread_id); - if (thread_id == THREAD_ID_CURRENT || - (thread->id == thread_id && thread->state != STATE_KILLED)) + if (thread->id == thread_id && thread->state != STATE_KILLED) { current->bqp = &thread->queue; block_thread(current); -- cgit v1.2.3