model: implement, use schedule_next_thread()
[model-checker.git] / schedule.cc
index abb3e4b3975f34c3cbaf876ead0af680699864d9..13b640cd8e832b2cca826e5a4b68d66143bb854c 100644 (file)
@@ -1,26 +1,32 @@
-#include "libthreads.h"
+#include "threads.h"
 #include "schedule.h"
 #include "common.h"
 #include "model.h"
 
-void Scheduler::add_thread(struct thread *t)
+void Scheduler::add_thread(Thread *t)
 {
-       DEBUG("thread %d\n", t->id);
-       queue.push(t);
+       DEBUG("thread %d\n", t->get_id());
+       readyList.push_back(t);
 }
 
-struct thread *Scheduler::next_thread(void)
+Thread *Scheduler::next_thread(void)
 {
-       if (queue.empty())
+       Thread *t = model->schedule_next_thread();
+
+       if (t != NULL) {
+               readyList.remove(t);
+               return t;
+       }
+       if (readyList.empty())
                return NULL;
 
-       current = queue.front();
-       queue.pop();
+       current = readyList.front();
+       readyList.pop_front();
 
        return current;
 }
 
-struct thread *Scheduler::get_current_thread(void)
+Thread *Scheduler::get_current_thread(void)
 {
        return current;
 }