From: Brian Demsky Date: Mon, 21 May 2012 06:50:34 +0000 (-0700) Subject: fix various problems with my 64-bit clean hack X-Git-Tag: pldi2013~420 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9ab763adc965ca76a8d65b9898d20c60cdb44445;p=model-checker.git fix various problems with my 64-bit clean hack found missing initializer bug in scheduler --- diff --git a/libthreads.cc b/libthreads.cc index b5760ae..205821e 100644 --- a/libthreads.cc +++ b/libthreads.cc @@ -8,7 +8,7 @@ /* * User program API functions */ -int thrd_create(thrd_t *t, void (*start_routine)(), void *arg) +int thrd_create(thrd_t *t, void (*start_routine)(void *), void *arg) { int ret; DBG(); diff --git a/libthreads.h b/libthreads.h index a899881..f6de95b 100644 --- a/libthreads.h +++ b/libthreads.h @@ -5,7 +5,7 @@ extern "C" { #endif - typedef void (*thrd_start_t)(); + typedef void (*thrd_start_t)(void *); typedef int thrd_t; diff --git a/main.cc b/main.cc index 967fd39..d24602b 100644 --- a/main.cc +++ b/main.cc @@ -57,7 +57,7 @@ void real_main() { do { /* Start user program */ - model->add_thread(new Thread(&user_thread, &user_main, NULL)); + model->add_thread(new Thread(&user_thread, (void (*)(void *)) &user_main, NULL)); /* Wait for all threads to complete */ thread_wait_finish(); diff --git a/schedule.cc b/schedule.cc index 40f9894..328bda6 100644 --- a/schedule.cc +++ b/schedule.cc @@ -1,8 +1,15 @@ +/* -*- Mode: C; indent-tabs-mode: t -*- */ + #include "threads.h" #include "schedule.h" #include "common.h" #include "model.h" +Scheduler::Scheduler(): +current(NULL) +{ +} + void Scheduler::add_thread(Thread *t) { DEBUG("thread %d\n", t->get_id()); diff --git a/schedule.h b/schedule.h index 8267fee..e81ea93 100644 --- a/schedule.h +++ b/schedule.h @@ -1,3 +1,5 @@ +/* -*- Mode: C; indent-tabs-mode: t -*- */ + #ifndef __SCHEDULE_H__ #define __SCHEDULE_H__ @@ -9,6 +11,7 @@ class Thread; class Scheduler { public: + Scheduler(); void add_thread(Thread *t); void remove_thread(Thread *t); Thread * next_thread(void); diff --git a/threads.cc b/threads.cc index 0ed7bdc..35000dc 100644 --- a/threads.cc +++ b/threads.cc @@ -45,7 +45,7 @@ int Thread::create_context() context.uc_stack.ss_size = STACK_SIZE; context.uc_stack.ss_flags = 0; context.uc_link = model->get_system_context(); - makecontext(&context, start_routine, 1); + makecontext(&context, thread_startup, 0); return 0; } @@ -70,7 +70,7 @@ void Thread::complete() } } -Thread::Thread(thrd_t *t, void (*func)(), void *a) { +Thread::Thread(thrd_t *t, void (*func)(void *), void *a) { int ret; user_thread = t; diff --git a/threads.h b/threads.h index b592804..5731906 100644 --- a/threads.h +++ b/threads.h @@ -18,7 +18,7 @@ typedef enum thread_state { class Thread { public: - Thread(thrd_t *t, void (*func)(), void *a); + Thread(thrd_t *t, void (*func)(void *), void *a); ~Thread(); void complete(); @@ -30,12 +30,13 @@ public: thread_id_t get_id(); thrd_t get_thrd_t() { return *user_thread; } Thread * get_parent() { return parent; } + friend void thread_startup(); MEMALLOC private: int create_context(); Thread *parent; - void (*start_routine)(); + void (*start_routine)(void *); void *arg; ucontext_t context; void *stack;