schedule: create 'class Scheduler' with implementation 'class DefaultScheduler'
[model-checker.git] / schedule.c
index c8f54e84e493b2c591d53a3b33bafdc850d64022..4f5f3de7d70ddf881e15ac6bd39cb27c795c728e 100644 (file)
@@ -6,7 +6,7 @@
 #include "model.h"
 
 struct thread_list_node {
-       struct thread *this;
+       struct thread *t;
        struct thread_list_node *next;
        int live;
 };
@@ -23,9 +23,11 @@ static void enqueue_thread(struct thread *t)
        struct thread_list_node *node;
 
        for (node = nodes, i = 0; node->live && i < NUM_LIST_NODES; i++, node++);
-       if (i >= NUM_LIST_NODES)
+       if (i >= NUM_LIST_NODES) {
                printf("ran out of nodes\n");
-       node->this = t;
+               exit(1);
+       }
+       node->t = t;
        node->next = NULL;
        node->live = 1;
 
@@ -43,7 +45,7 @@ static struct thread *dequeue_thread(void)
        if (!head)
                return NULL;
 
-       pop = head->this;
+       pop = head->t;
        head->live = 0;
        if (head == tail)
                tail = NULL;
@@ -55,32 +57,18 @@ static struct thread *dequeue_thread(void)
        return pop;
 }
 
-static void default_add_thread(struct thread *t)
+void DefaultScheduler::add_thread(struct thread *t)
 {
-       DEBUG("thread %d\n", t->index);
+       DEBUG("thread %d\n", t->id);
        enqueue_thread(t);
 }
 
-static struct thread *default_choose_next(void)
+struct thread *DefaultScheduler::next_thread(void)
 {
        return dequeue_thread();
 }
 
-static struct thread *default_thread_current(void)
+struct thread *DefaultScheduler::get_current_thread(void)
 {
        return current;
 }
-
-void scheduler_init(struct model_checker *mod)
-{
-       struct scheduler *sched;
-
-       /* Initialize default scheduler */
-       sched = malloc(sizeof(*sched));
-       sched->init = NULL;
-       sched->exit = NULL;
-       sched->add_thread = default_add_thread;
-       sched->next_thread = default_choose_next;
-       sched->get_current_thread = default_thread_current;
-       mod->scheduler = sched;
-}