freemyipod r541 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r540‎ | r541 | r542 >
Date:20:53, 6 February 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Fix thread_killlevel()
Modified paths:
  • /emcore/trunk/thread.c (modified) (history)

Diff [purge]

Index: emcore/trunk/thread.c
@@ -451,11 +451,10 @@
452452 leave_critical_section(mode);
453453 }
454454
455 -int thread_terminate(struct scheduler_thread* thread)
 455+int thread_terminate_internal(struct scheduler_thread* thread, uint32_t mode)
456456 {
457457 struct scheduler_thread* t;
458458 bool needsswitch = false;
459 - uint32_t mode = enter_critical_section();
460459
461460 if (!thread) thread = current_thread;
462461 if (thread->state == THREAD_RUNNING) needsswitch = true;
@@ -486,18 +485,32 @@
487486 return THREAD_OK;
488487 }
489488
 489+int thread_terminate(struct scheduler_thread* thread)
 490+{
 491+ uint32_t mode = enter_critical_section();
 492+ return thread_terminate_internal(thread, mode);
 493+}
 494+
490495 int thread_killlevel(enum thread_type type, bool killself)
491496 {
492497 struct scheduler_thread* t;
493498 int count = 0;
494 - uint32_t mode = enter_critical_section();
495 - for (t = head_thread; t; t = t->thread_next);
496 - if (t->type <= type && (killself || current_thread != t))
497 - {
498 - thread_terminate(t);
499 - count++;
500 - }
501 - leave_critical_section(mode);
 499+ while (true)
 500+ {
 501+ bool found = false;
 502+ uint32_t mode = enter_critical_section();
 503+ for (t = head_thread; t; t = t->thread_next)
 504+ if (t->type <= type && (killself || current_thread != t))
 505+ {
 506+ thread_terminate_internal(t, mode);
 507+ found = true;
 508+ count++;
 509+ break;
 510+ }
 511+ if (found) continue;
 512+ leave_critical_section(mode);
 513+ break;
 514+ }
502515 return count;
503516 }
504517