merging stuff...made need to clean up some stuff...but need to push it somewhere...
[model-checker.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 void Scheduler::remove_thread(Thread *t)
13 {
14         if (current == t)
15                 current = NULL;
16         else
17                 readyList.remove(t);
18 }
19
20 Thread * Scheduler::next_thread(void)
21 {
22         Thread *t = model->schedule_next_thread();
23
24         if (t != NULL) {
25                 current = t;
26                 readyList.remove(t);
27         } else if (readyList.empty()) {
28                 t = NULL;
29         } else {
30                 t = readyList.front();
31                 current = t;
32                 readyList.pop_front();
33         }
34
35         print();
36
37         return t;
38 }
39
40 Thread * Scheduler::get_current_thread(void)
41 {
42         return current;
43 }
44
45 void Scheduler::print()
46 {
47         if (current)
48                 DEBUG("Current thread: %d\n", current->get_id());
49         else
50                 DEBUG("No current thread\n");
51         DEBUG("Num. threads in ready list: %zu\n", readyList.size());
52
53         std::list<Thread *, MyAlloc< Thread * > >::iterator it;
54         for (it = readyList.begin(); it != readyList.end(); it++)
55                 DEBUG("In ready list: thread %d\n", (*it)->get_id());
56 }