summaryrefslogtreecommitdiff
path: root/firmware/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/thread.c')
-rw-r--r--firmware/thread.c42
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 */
1518struct thread_entry * thread_id_entry(unsigned int thread_id) 1518struct 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 */
1527unsigned 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 */
1538struct 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 */
2150unsigned 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.