3 #include "libthreads.h"
8 struct thread_list_node {
10 struct thread_list_node *next;
14 #define NUM_LIST_NODES 32
16 struct thread_list_node *head, *tail;
17 struct thread_list_node nodes[NUM_LIST_NODES];
18 struct thread *current;
20 static void enqueue_thread(struct thread *t)
23 struct thread_list_node *node;
25 for (node = nodes, i = 0; node->live && i < NUM_LIST_NODES; i++, node++);
26 if (i >= NUM_LIST_NODES) {
27 printf("ran out of nodes\n");
41 static struct thread *dequeue_thread(void)
54 /* Set new current thread */
60 static void default_add_thread(struct thread *t)
62 DEBUG("thread %d\n", t->id);
66 static struct thread *default_choose_next(void)
68 return dequeue_thread();
71 static struct thread *default_thread_current(void)
76 void scheduler_init(struct model_checker *mod)
78 struct scheduler *sched;
80 /* Initialize default scheduler */
81 sched = malloc(sizeof(*sched));
84 sched->add_thread = default_add_thread;
85 sched->next_thread = default_choose_next;
86 sched->get_current_thread = default_thread_current;
87 mod->scheduler = sched;