freemyipod r688 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r687‎ | r688 | r689 >
Date:23:52, 30 March 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Fix thread destruction being interrupted
Modified paths:
  • /emcore/trunk/thread.c (modified) (history)

Diff [purge]

Index: emcore/trunk/thread.c
@@ -473,15 +473,17 @@
474474
475475 if (!thread) thread = current_thread;
476476 if (thread->state == THREAD_RUNNING) needsswitch = true;
477 - else if (thread->state == THREAD_BLOCKED)
 477+ else
478478 {
479 - if (thread->block_type == THREAD_BLOCK_MUTEX)
480 - mutex_remove_from_queue((struct mutex*)t->blocked_by, thread);
481 - else if (thread->block_type == THREAD_BLOCK_WAKEUP)
482 - ((struct wakeup*)thread->blocked_by)->waiter = NULL;
 479+ if (thread->state == THREAD_BLOCKED)
 480+ {
 481+ if (thread->block_type == THREAD_BLOCK_MUTEX)
 482+ mutex_remove_from_queue((struct mutex*)t->blocked_by, thread);
 483+ else if (thread->block_type == THREAD_BLOCK_WAKEUP)
 484+ ((struct wakeup*)thread->blocked_by)->waiter = NULL;
 485+ }
 486+ thread->state = THREAD_SUSPENDED;
483487 }
484 - for (t = head_thread; t && t->thread_next != thread; t = t->thread_next);
485 - if (t) t->thread_next = thread->thread_next;
486488
487489 leave_critical_section(mode);
488490
@@ -495,6 +497,11 @@
496498 #endif
497499 free_all_of_thread(thread);
498500
 501+ mode = enter_critical_section();
 502+ for (t = head_thread; t && t->thread_next != thread; t = t->thread_next);
 503+ if (t) t->thread_next = thread->thread_next;
 504+ leave_critical_section(mode);
 505+
499506 if (needsswitch) yield();
500507
501508 return THREAD_OK;
@@ -515,7 +522,7 @@
516523 bool found = false;
517524 uint32_t mode = enter_critical_section();
518525 for (t = head_thread; t; t = t->thread_next)
519 - if (t->type <= type && (killself || current_thread != t))
 526+ if (t->type <= type && current_thread != t)
520527 {
521528 thread_terminate_internal(t, mode);
522529 found = true;
@@ -526,6 +533,7 @@
527534 leave_critical_section(mode);
528535 break;
529536 }
 537+ if (killself) thread_exit();
530538 return count;
531539 }
532540