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");
39 static struct thread *dequeue_thread(void)
52 /* Set new current thread */
58 static void default_add_thread(struct thread *t)
60 DEBUG("thread %d\n", t->index);
64 static struct thread *default_choose_next(void)
66 return dequeue_thread();
69 static struct thread *default_thread_current(void)
74 void scheduler_init(struct model_checker *mod)
76 struct scheduler *sched;
78 /* Initialize default scheduler */
79 sched = malloc(sizeof(*sched));
82 sched->add_thread = default_add_thread;
83 sched->next_thread = default_choose_next;
84 sched->get_current_thread = default_thread_current;
85 mod->scheduler = sched;