From 2f6506f4535415ffefb5c4735e9414a00bf5c1a8 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Mon, 12 Mar 2012 16:14:11 -0700 Subject: [PATCH] model: move 'main_thread' to model_checker struct --- libthreads.c | 8 ++++---- model.c | 5 +++++ model.h | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libthreads.c b/libthreads.c index c164d67..8d76bf1 100644 --- a/libthreads.c +++ b/libthreads.c @@ -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 ac50e3e..cd43153 100644 --- 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 e075ea2..5031c8b 100644 --- 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__ */ -- 2.34.1