schedule: add replaceable scheduler struct
[model-checker.git] / schedule.c
index f5ce644810856b06b3002996a1d95c1e11f17b9d..4ac8b4991b37a70993a10485923c367bc847d4d2 100644 (file)
@@ -1,4 +1,9 @@
+#include <stdlib.h>
+
+#include "libthreads.h"
 #include "schedule.h"
+#include "common.h"
+#include "model.h"
 
 struct thread_list_node {
        struct thread *this;
@@ -30,16 +35,20 @@ static void enqueue_thread(struct thread *t)
        tail = node;
 }
 
-static int dequeue_thread(struct thread **t)
+struct thread *dequeue_thread(void)
 {
+       struct thread *pop;
+
        if (!head)
-               return -1;
-       *t = head->this;
+               return NULL;
+
+       pop = head->this;
        head->live = 0;
        if (head == tail)
                tail = NULL;
        head = head->next;
-       return 0;
+
+       return pop;
 }
 
 void schedule_add_thread(struct thread *t)
@@ -48,7 +57,21 @@ void schedule_add_thread(struct thread *t)
        enqueue_thread(t);
 }
 
-int schedule_choose_next(struct thread **t)
+struct thread *schedule_choose_next(void)
 {
-       return dequeue_thread(t);
+       return dequeue_thread();
+}
+
+void scheduler_init(struct model_checker *mod)
+{
+       struct scheduler *sched;
+
+       /* Initialize FCFS scheduler */
+       sched = malloc(sizeof(*sched));
+       sched->init = NULL;
+       sched->exit = NULL;
+       sched->add_thread = schedule_add_thread;
+       sched->next_thread = schedule_choose_next;
+       sched->get_current_thread = thread_current;
+       mod->scheduler = sched;
 }