diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-03-05 17:48:06 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-03-05 17:48:06 +0000 |
commit | cc889e9d608e6b07b78541849b7e63b6fb3f6058 (patch) | |
tree | ea01a47602b68561d294f705e8ab7669fb00ae9a /firmware/thread.c | |
parent | 0b0f99b18ebe6305c9cab12bf8b36d154fc9c87f (diff) | |
download | rockbox-cc889e9d608e6b07b78541849b7e63b6fb3f6058.tar.gz rockbox-cc889e9d608e6b07b78541849b7e63b6fb3f6058.zip |
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
Diffstat (limited to 'firmware/thread.c')
-rw-r--r-- | firmware/thread.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/firmware/thread.c b/firmware/thread.c index ea73150853..cfedbbedba 100644 --- a/firmware/thread.c +++ b/firmware/thread.c | |||
@@ -1517,9 +1517,27 @@ static struct thread_entry * find_empty_thread_slot(void) | |||
1517 | */ | 1517 | */ |
1518 | struct thread_entry * thread_id_entry(unsigned int thread_id) | 1518 | struct thread_entry * thread_id_entry(unsigned int thread_id) |
1519 | { | 1519 | { |
1520 | return (thread_id == THREAD_ID_CURRENT) ? | 1520 | return &threads[thread_id & THREAD_ID_SLOT_MASK]; |
1521 | cores[CURRENT_CORE].running : | 1521 | } |
1522 | &threads[thread_id & THREAD_ID_SLOT_MASK]; | 1522 | |
1523 | /*--------------------------------------------------------------------------- | ||
1524 | * Return the thread id of the calling thread | ||
1525 | * -------------------------------------------------------------------------- | ||
1526 | */ | ||
1527 | unsigned int thread_self(void) | ||
1528 | { | ||
1529 | return cores[CURRENT_CORE].running->id; | ||
1530 | } | ||
1531 | |||
1532 | /*--------------------------------------------------------------------------- | ||
1533 | * Return the thread entry of the calling thread. | ||
1534 | * | ||
1535 | * INTERNAL: Intended for use by kernel and not for programs. | ||
1536 | *--------------------------------------------------------------------------- | ||
1537 | */ | ||
1538 | struct thread_entry* thread_self_entry(void) | ||
1539 | { | ||
1540 | return cores[CURRENT_CORE].running; | ||
1523 | } | 1541 | } |
1524 | 1542 | ||
1525 | /*--------------------------------------------------------------------------- | 1543 | /*--------------------------------------------------------------------------- |
@@ -1675,8 +1693,7 @@ void thread_wait(unsigned int thread_id) | |||
1675 | corelock_lock(&thread->waiter_cl); | 1693 | corelock_lock(&thread->waiter_cl); |
1676 | 1694 | ||
1677 | /* Be sure it hasn't been killed yet */ | 1695 | /* Be sure it hasn't been killed yet */ |
1678 | if (thread_id == THREAD_ID_CURRENT || | 1696 | if (thread->id == thread_id && thread->state != STATE_KILLED) |
1679 | (thread->id == thread_id && thread->state != STATE_KILLED)) | ||
1680 | { | 1697 | { |
1681 | IF_COP( current->obj_cl = &thread->waiter_cl; ) | 1698 | IF_COP( current->obj_cl = &thread->waiter_cl; ) |
1682 | current->bqp = &thread->queue; | 1699 | current->bqp = &thread->queue; |
@@ -1973,8 +1990,7 @@ int thread_set_priority(unsigned int thread_id, int priority) | |||
1973 | LOCK_THREAD(thread); | 1990 | LOCK_THREAD(thread); |
1974 | 1991 | ||
1975 | /* Make sure it's not killed */ | 1992 | /* Make sure it's not killed */ |
1976 | if (thread_id == THREAD_ID_CURRENT || | 1993 | if (thread->id == thread_id && thread->state != STATE_KILLED) |
1977 | (thread->id == thread_id && thread->state != STATE_KILLED)) | ||
1978 | { | 1994 | { |
1979 | int old_priority = thread->priority; | 1995 | int old_priority = thread->priority; |
1980 | 1996 | ||
@@ -2099,8 +2115,7 @@ int thread_get_priority(unsigned int thread_id) | |||
2099 | /* Simply check without locking slot. It may or may not be valid by the | 2115 | /* Simply check without locking slot. It may or may not be valid by the |
2100 | * time the function returns anyway. If all tests pass, it is the | 2116 | * time the function returns anyway. If all tests pass, it is the |
2101 | * correct value for when it was valid. */ | 2117 | * correct value for when it was valid. */ |
2102 | if (thread_id != THREAD_ID_CURRENT && | 2118 | if (thread->id != thread_id || thread->state == STATE_KILLED) |
2103 | (thread->id != thread_id || thread->state == STATE_KILLED)) | ||
2104 | base_priority = -1; | 2119 | base_priority = -1; |
2105 | 2120 | ||
2106 | return base_priority; | 2121 | return base_priority; |
@@ -2143,15 +2158,6 @@ void thread_thaw(unsigned int thread_id) | |||
2143 | restore_irq(oldlevel); | 2158 | restore_irq(oldlevel); |
2144 | } | 2159 | } |
2145 | 2160 | ||
2146 | /*--------------------------------------------------------------------------- | ||
2147 | * Return the ID of the currently executing thread. | ||
2148 | *--------------------------------------------------------------------------- | ||
2149 | */ | ||
2150 | unsigned int thread_get_current(void) | ||
2151 | { | ||
2152 | return cores[CURRENT_CORE].running->id; | ||
2153 | } | ||
2154 | |||
2155 | #if NUM_CORES > 1 | 2161 | #if NUM_CORES > 1 |
2156 | /*--------------------------------------------------------------------------- | 2162 | /*--------------------------------------------------------------------------- |
2157 | * Switch the processor that the currently executing thread runs on. | 2163 | * Switch the processor that the currently executing thread runs on. |