freemyipod r423 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r422‎ | r423 | r424 >
Date:12:53, 15 January 2011
Author:theseven
Status:new
Tags:
Comment:
emBIOS: Kill all user threads before shutting down hardware
Modified paths:
  • /embios/trunk/shutdown.c (modified) (history)
  • /embios/trunk/thread.c (modified) (history)
  • /embios/trunk/thread.h (modified) (history)

Diff [purge]

Index: embios/trunk/shutdown.c
@@ -23,11 +23,13 @@
2424
2525 #include "global.h"
2626 #include "storage.h"
 27+#include "thread.h"
2728
2829
2930 void shutdown(bool shutdownhw)
3031 {
3132 DEBUGF("Shutting down...");
 33+ thread_killlevel(USER_THREAD, false);
3234 #ifdef HAVE_USB
3335 usb_exit();
3436 #endif
Index: embios/trunk/thread.c
@@ -464,6 +464,22 @@
465465 return ret;
466466 }
467467
 468+int thread_killlevel(enum thread_type type, bool killself)
 469+{
 470+ int i;
 471+ int count = 0;
 472+ uint32_t mode = enter_critical_section();
 473+ for (i = 0; i < MAX_THREADS; i++)
 474+ if (scheduler_threads[i].type == USER_THREAD && scheduler_threads[i].state != THREAD_FREE
 475+ && (killself || current_thread != &scheduler_threads[i]))
 476+ {
 477+ thread_terminate(i);
 478+ count++;
 479+ }
 480+ leave_critical_section(mode);
 481+ return count;
 482+}
 483+
468484 enum thread_state thread_get_state(int thread)
469485 {
470486 return scheduler_threads[thread].state;
Index: embios/trunk/thread.h
@@ -117,6 +117,7 @@
118118 int thread_suspend(int thread);
119119 int thread_resume(int thread);
120120 int thread_terminate(int thread);
 121+int thread_killlevel(enum thread_type type, bool killself);
121122 enum thread_state thread_get_state(int thread);
122123 void thread_exit();
123124 void mutex_init(struct mutex* obj) ICODE_ATTR;