From ca20a05be41491f67bd5c40517bed08f5a7328ba Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 13 Mar 2012 11:37:45 -0700 Subject: [PATCH] stricter typing of function pointers for makecontext() We need to use functions with no arguments (i.e., 'void (*)()') in order to retain strict type-checking with makecontext(). Of course, we still circumvent this type checking with casting, but we should straighten this out sometime... --- libthreads.c | 2 +- libthreads.h | 4 ++-- userprog.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libthreads.c b/libthreads.c index 1b7f3db..ca31067 100644 --- a/libthreads.c +++ b/libthreads.c @@ -100,7 +100,7 @@ static void thread_wait_finish(void) /* * User program API functions */ -int thread_create(struct thread *t, void (*start_routine), void *arg) +int thread_create(struct thread *t, void (*start_routine)(), void *arg) { int ret = 0; diff --git a/libthreads.h b/libthreads.h index 0848833..aa7faf4 100644 --- a/libthreads.h +++ b/libthreads.h @@ -11,7 +11,7 @@ typedef enum thread_state { } thread_state; struct thread { - void (*start_routine); + void (*start_routine)(); void *arg; ucontext_t context; void *stack; @@ -19,7 +19,7 @@ struct thread { thread_state state; }; -int thread_create(struct thread *t, void (*start_routine), void *arg); +int thread_create(struct thread *t, void (*start_routine)(), void *arg); void thread_join(struct thread *t); int thread_yield(void); struct thread *thread_current(void); diff --git a/userprog.c b/userprog.c index c27c701..1837fc9 100644 --- a/userprog.c +++ b/userprog.c @@ -20,8 +20,8 @@ void user_main() atomic_int obj; printf("%s() creating 2 threads\n", __func__); - thread_create(&t1, &a, &obj); - thread_create(&t2, &a, &obj); + thread_create(&t1, (void (*)())&a, &obj); + thread_create(&t2, (void (*)())&a, &obj); thread_join(&t1); thread_join(&t2); -- 2.34.1