X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=schedule.c;h=f4f1c13df96232f545423b00fbc968c9c8bd1361;hb=ca42b4367e6451fdc8d55a4baa3013c1dda6902e;hp=10e7fdc181499c2ef2142ad609b3902e00075edd;hpb=60e0a49ba320b32b9cc0d2f8d73c8d95c92fc0ba;p=cdsspec-compiler.git diff --git a/schedule.c b/schedule.c index 10e7fdc..f4f1c13 100644 --- a/schedule.c +++ b/schedule.c @@ -1,8 +1,12 @@ +#include + +#include "libthreads.h" #include "schedule.h" #include "common.h" +#include "model.h" struct thread_list_node { - struct thread *this; + struct thread *t; struct thread_list_node *next; int live; }; @@ -11,6 +15,7 @@ struct thread_list_node { struct thread_list_node *head, *tail; struct thread_list_node nodes[NUM_LIST_NODES]; +struct thread *current; static void enqueue_thread(struct thread *t) { @@ -18,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; @@ -31,27 +38,51 @@ static void enqueue_thread(struct thread *t) tail = node; } -static int dequeue_thread(struct thread **t) +static struct thread *dequeue_thread(void) { - if (!head) { - *t = NULL; - return -1; - } - *t = head->this; + struct thread *pop; + + if (!head) + return NULL; + + pop = head->t; head->live = 0; if (head == tail) tail = NULL; head = head->next; - return 0; + + /* Set new current thread */ + current = pop; + + return pop; } -void schedule_add_thread(struct thread *t) +static void default_add_thread(struct thread *t) { - DEBUG("thread %d\n", t->index); + DEBUG("thread %d\n", t->id); enqueue_thread(t); } -int schedule_choose_next(struct thread **t) +static struct thread *default_choose_next(void) { - return dequeue_thread(t); + return dequeue_thread(); +} + +static struct thread *default_thread_current(void) +{ + return current; +} + +void scheduler_init(struct model_checker *mod) +{ + struct scheduler *sched; + + /* Initialize default scheduler */ + sched = (struct scheduler *)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; }