unify style for returning pointers
[c11tester.git] / schedule.cc
1 #include "threads.h"
2 #include "schedule.h"
3 #include "common.h"
4 #include "model.h"
5
6 void Scheduler::add_thread(Thread *t)
7 {
8         DEBUG("thread %d\n", t->get_id());
9         readyList.push_back(t);
10 }
11
12 Thread * Scheduler::next_thread(void)
13 {
14         Thread *t = model->schedule_next_thread();
15
16         if (t != NULL) {
17                 current = t;
18                 readyList.remove(t);
19         } else if (readyList.empty()) {
20                 t = NULL;
21         } else {
22                 t = readyList.front();
23                 current = t;
24                 readyList.pop_front();
25         }
26
27         print();
28
29         return t;
30 }
31
32 Thread * Scheduler::get_current_thread(void)
33 {
34         return current;
35 }
36
37 void Scheduler::print()
38 {
39         if (current)
40                 printf("Current thread: %d\n", current->get_id());
41         else
42                 printf("No current thread\n");
43         printf("Num. threads in ready list: %ld\n", readyList.size());
44
45         std::list<Thread *>::iterator it;
46         for (it = readyList.begin(); it != readyList.end(); it++)
47                 printf("In ready list: thread %d\n", (*it)->get_id());
48 }