schedule: create 'class Scheduler' with implementation 'class DefaultScheduler'
[model-checker.git] / schedule.c
index 3b4d57cf1574500f75b267a49f6bf181e4a09a02..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;
 };
@@ -27,7 +27,7 @@ static void enqueue_thread(struct thread *t)
                printf("ran out of nodes\n");
                exit(1);
        }
-       node->this = t;
+       node->t = t;
        node->next = NULL;
        node->live = 1;
 
@@ -45,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;
@@ -57,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->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;
-}