From: Brian Norris Date: Wed, 14 Mar 2012 22:56:56 +0000 (-0700) Subject: schedule: move schedule.c --> schedule.cc X-Git-Tag: pldi2013~576 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f19fd46f4e67fd2d4a4041a4eecaa6789f97aba1;p=model-checker.git schedule: move schedule.c --> schedule.cc --- diff --git a/Makefile b/Makefile index 6c52f67..84a7b0a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC=g++ BIN=libthreads -SOURCE=libthreads.c schedule.c libatomic.c userprog.c model.cc +SOURCE=libthreads.c schedule.cc libatomic.c userprog.c model.cc HEADERS=libthreads.h schedule.h common.h libatomic.h model.h FLAGS=-Wall diff --git a/schedule.c b/schedule.c deleted file mode 100644 index 4f5f3de..0000000 --- a/schedule.c +++ /dev/null @@ -1,74 +0,0 @@ -#include - -#include "libthreads.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) -{ - 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; -} - -static struct thread *dequeue_thread(void) -{ - struct thread *pop; - - if (!head) - return NULL; - - pop = head->t; - head->live = 0; - if (head == tail) - tail = NULL; - head = head->next; - - /* Set new current thread */ - current = 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(); -} - -struct thread *DefaultScheduler::get_current_thread(void) -{ - return current; -} diff --git a/schedule.cc b/schedule.cc new file mode 100644 index 0000000..4f5f3de --- /dev/null +++ b/schedule.cc @@ -0,0 +1,74 @@ +#include + +#include "libthreads.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) +{ + 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; +} + +static struct thread *dequeue_thread(void) +{ + struct thread *pop; + + if (!head) + return NULL; + + pop = head->t; + head->live = 0; + if (head == tail) + tail = NULL; + head = head->next; + + /* Set new current thread */ + current = 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(); +} + +struct thread *DefaultScheduler::get_current_thread(void) +{ + return current; +}