schedule: refactor next_thread() for better debug printing
authorBrian Norris <banorris@uci.edu>
Mon, 23 Apr 2012 22:39:07 +0000 (15:39 -0700)
committerBrian Norris <banorris@uci.edu>
Mon, 23 Apr 2012 22:54:55 +0000 (15:54 -0700)
It makes more sense to call print() at the end of the the next_thread()
routine, to see consistent printing for all cases. So I refactor the control
flow to a single return statement.

schedule.cc

index 2498347c44cc6e2cb6cbb870a829465c318504db..4d1cb126579584942c67e32160c8f5e33669472b 100644 (file)
@@ -13,19 +13,19 @@ Thread *Scheduler::next_thread(void)
 {
        Thread *t = model->schedule_next_thread();
 
-       print();
-
        if (t != NULL) {
                readyList.remove(t);
-               return t;
+       } else if (readyList.empty()) {
+               t = NULL;
+       } else {
+               t = readyList.front();
+               current = t;
+               readyList.pop_front();
        }
-       if (readyList.empty())
-               return NULL;
 
-       current = readyList.front();
-       readyList.pop_front();
+       print();
 
-       return current;
+       return t;
 }
 
 Thread *Scheduler::get_current_thread(void)