major rewrite - 'struct thread' replaced with internal 'class Thread'
[model-checker.git] / schedule.cc
index 4f5f3de7d70ddf881e15ac6bd39cb27c795c728e..60d84a8af6b307d1d51d892e3712aa8d8910ab87 100644 (file)
@@ -1,74 +1,26 @@
-#include <stdlib.h>
-
-#include "libthreads.h"
+#include "threads_internal.h"
 #include "schedule.h"
 #include "common.h"
 #include "model.h"
 
-struct thread_list_node {
-       struct thread *t;
-       struct thread_list_node *next;
-       int live;
-};
-
-#define NUM_LIST_NODES 32
-
-struct thread_list_node *head, *tail;
-struct thread_list_node nodes[NUM_LIST_NODES];
-struct thread *current;
-
-static void enqueue_thread(struct thread *t)
+void Scheduler::add_thread(Thread *t)
 {
-       int i;
-       struct thread_list_node *node;
-
-       for (node = nodes, i = 0; node->live && i < NUM_LIST_NODES; i++, node++);
-       if (i >= NUM_LIST_NODES) {
-               printf("ran out of nodes\n");
-               exit(1);
-       }
-       node->t = t;
-       node->next = NULL;
-       node->live = 1;
-
-       if (tail)
-               tail->next = node;
-       else
-               head = node;
-       tail = node;
+       DEBUG("thread %d\n", t->get_id());
+       queue.push(t);
 }
 
-static struct thread *dequeue_thread(void)
+Thread *Scheduler::next_thread(void)
 {
-       struct thread *pop;
-
-       if (!head)
+       if (queue.empty())
                return NULL;
 
-       pop = head->t;
-       head->live = 0;
-       if (head == tail)
-               tail = NULL;
-       head = head->next;
-
-       /* Set new current thread */
-       current = pop;
+       current = queue.front();
+       queue.pop();
 
-       return pop;
-}
-
-void DefaultScheduler::add_thread(struct thread *t)
-{
-       DEBUG("thread %d\n", t->id);
-       enqueue_thread(t);
-}
-
-struct thread *DefaultScheduler::next_thread(void)
-{
-       return dequeue_thread();
+       return current;
 }
 
-struct thread *DefaultScheduler::get_current_thread(void)
+Thread *Scheduler::get_current_thread(void)
 {
        return current;
 }