summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl/thread-sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/sdl/thread-sdl.c')
-rw-r--r--firmware/target/hosted/sdl/thread-sdl.c22
1 files changed, 12 insertions, 10 deletions
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)
253 253
254struct thread_entry * thread_id_entry(unsigned int thread_id) 254struct thread_entry * thread_id_entry(unsigned int thread_id)
255{ 255{
256 return (thread_id == THREAD_ID_CURRENT) ? 256 return &threads[thread_id & THREAD_ID_SLOT_MASK];
257 cores[CURRENT_CORE].running :
258 &threads[thread_id & THREAD_ID_SLOT_MASK];
259} 257}
260 258
261static void add_to_list_l(struct thread_entry **list, 259static void add_to_list_l(struct thread_entry **list,
@@ -299,11 +297,16 @@ static void remove_from_list_l(struct thread_entry **list,
299 thread->l.next->l.prev = thread->l.prev; 297 thread->l.next->l.prev = thread->l.prev;
300} 298}
301 299
302unsigned int thread_get_current(void) 300unsigned int thread_self(void)
303{ 301{
304 return cores[CURRENT_CORE].running->id; 302 return cores[CURRENT_CORE].running->id;
305} 303}
306 304
305struct thread_entry* thread_self_entry(void)
306{
307 return cores[CURRENT_CORE].running;
308}
309
307void switch_thread(void) 310void switch_thread(void)
308{ 311{
309 struct thread_entry *current = cores[CURRENT_CORE].running; 312 struct thread_entry *current = cores[CURRENT_CORE].running;
@@ -562,7 +565,7 @@ void remove_thread(unsigned int thread_id)
562 SDL_Thread *t; 565 SDL_Thread *t;
563 SDL_sem *s; 566 SDL_sem *s;
564 567
565 if (thread_id != THREAD_ID_CURRENT && thread->id != thread_id) 568 if (thread->id != thread_id)
566 return; 569 return;
567 570
568 int oldlevel = disable_irq_save(); 571 int oldlevel = disable_irq_save();
@@ -629,11 +632,11 @@ void remove_thread(unsigned int thread_id)
629 632
630void thread_exit(void) 633void thread_exit(void)
631{ 634{
632 remove_thread(THREAD_ID_CURRENT); 635 unsigned int id = thread_self();
636 remove_thread(id);
633 /* This should never and must never be reached - if it is, the 637 /* This should never and must never be reached - if it is, the
634 * state is corrupted */ 638 * state is corrupted */
635 THREAD_PANICF("thread_exit->K:*R (ID: %d)", 639 THREAD_PANICF("thread_exit->K:*R (ID: %d)", id);
636 thread_id_entry(THREAD_ID_CURRENT)->id);
637 while (1); 640 while (1);
638} 641}
639 642
@@ -642,8 +645,7 @@ void thread_wait(unsigned int thread_id)
642 struct thread_entry *current = cores[CURRENT_CORE].running; 645 struct thread_entry *current = cores[CURRENT_CORE].running;
643 struct thread_entry *thread = thread_id_entry(thread_id); 646 struct thread_entry *thread = thread_id_entry(thread_id);
644 647
645 if (thread_id == THREAD_ID_CURRENT || 648 if (thread->id == thread_id && thread->state != STATE_KILLED)
646 (thread->id == thread_id && thread->state != STATE_KILLED))
647 { 649 {
648 current->bqp = &thread->queue; 650 current->bqp = &thread->queue;
649 block_thread(current); 651 block_thread(current);