1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Thomas Martitz 2011-03-05 17:48:06 +00:00
parent 0b0f99b18e
commit cc889e9d60
13 changed files with 67 additions and 55 deletions

View file

@ -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);