model: move 'main_thread' to model_checker struct
authorBrian Norris <banorris@uci.edu>
Mon, 12 Mar 2012 23:14:11 +0000 (16:14 -0700)
committerBrian Norris <banorris@uci.edu>
Mon, 12 Mar 2012 23:14:11 +0000 (16:14 -0700)
libthreads.c
model.c
model.h

index c164d6779610198efe03a16d0c3d3816ba6fd90d..8d76bf12dbf7459cd83d97c18948fa08a39725fd 100644 (file)
@@ -10,8 +10,6 @@
 
 #define STACK_SIZE (1024 * 1024)
 
-static struct thread *main_thread;
-
 static void *stack_allocate(size_t size)
 {
        return malloc(size);
@@ -40,7 +38,7 @@ static int create_context(struct thread *t)
        t->context.uc_stack.ss_sp = t->stack;
        t->context.uc_stack.ss_size = STACK_SIZE;
        t->context.uc_stack.ss_flags = 0;
-       t->context.uc_link = &main_thread->context;
+       t->context.uc_link = &model->system_thread->context;
        makecontext(&t->context, t->start_routine, 1, t->arg);
 
        return 0;
@@ -86,7 +84,7 @@ static void thread_wait_finish(void)
                if ((curr = thread_current()))
                        thread_dispose(curr);
                next = model->scheduler->next_thread();
-       } while (next && !thread_swap(main_thread, next));
+       } while (next && !thread_swap(model->system_thread, next));
 }
 
 int thread_create(struct thread *t, void (*start_routine), void *arg)
@@ -126,11 +124,13 @@ struct thread *thread_current(void)
 int main()
 {
        struct thread user_thread;
+       struct thread *main_thread;
 
        model_checker_init();
 
        main_thread = malloc(sizeof(struct thread));
        create_initial_thread(main_thread);
+       model_checker_add_system_thread(main_thread);
 
        /* Start user program */
        thread_create(&user_thread, &user_main, NULL);
diff --git a/model.c b/model.c
index ac50e3e71e48102e1040f3208ba4ba4692b7131d..cd4315327e280a04a6eca3108e1d0cd92531f7ad 100644 (file)
--- a/model.c
+++ b/model.c
@@ -5,6 +5,11 @@
 
 struct model_checker *model;
 
+void model_checker_add_system_thread(struct thread *t)
+{
+       model->system_thread = t;
+}
+
 void model_checker_init(void)
 {
        model = malloc(sizeof(*model));
diff --git a/model.h b/model.h
index e075ea254640e7f32c0392d027af60a308b329c2..5031c8b207c12c1e4123fbe829e4daa0f0a0df29 100644 (file)
--- a/model.h
+++ b/model.h
@@ -3,10 +3,12 @@
 
 struct model_checker {
        struct scheduler *scheduler;
+       struct thread *system_thread;
 };
 
 extern struct model_checker *model;
 
 void model_checker_init(void);
+void model_checker_add_system_thread(struct thread *t);
 
 #endif /* __MODEL_H__ */