fix various problems with my 64-bit clean hack
authorBrian Demsky <bdemsky@uci.edu>
Mon, 21 May 2012 06:50:34 +0000 (23:50 -0700)
committerBrian Demsky <bdemsky@uci.edu>
Mon, 21 May 2012 06:50:34 +0000 (23:50 -0700)
found missing initializer bug in scheduler

libthreads.cc
libthreads.h
main.cc
schedule.cc
schedule.h
threads.cc
threads.h

index b5760ae6eab89f381a67b12a4e05f0402ef7ad76..205821eac68255d696e89e945f71c06fd63ba7c5 100644 (file)
@@ -8,7 +8,7 @@
 /*
  * User program API functions
  */
 /*
  * 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();
 {
        int ret;
        DBG();
index a899881c3ee5185c94d3ad115ed90329e777699e..f6de95bb9fa4f3614f07658b2abe05f8217ec6fa 100644 (file)
@@ -5,7 +5,7 @@
 extern "C" {
 #endif
 
 extern "C" {
 #endif
 
-       typedef void (*thrd_start_t)();
+       typedef void (*thrd_start_t)(void *);
 
        typedef int thrd_t;
 
 
        typedef int thrd_t;
 
diff --git a/main.cc b/main.cc
index 967fd39e26955a561a04cf7e485c5d94c31978bc..d24602bea33fa2139975d5b148c4bfc509129345 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -57,7 +57,7 @@ void real_main() {
 
        do {
                /* Start user program */
 
        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();
     
                /* Wait for all threads to complete */
                thread_wait_finish();
index 40f9894ebb9a7be5a8ecc918fe56038471c64020..328bda6990c3e55a61574261f893fa77a9031eaa 100644 (file)
@@ -1,8 +1,15 @@
+/* -*- Mode: C; indent-tabs-mode: t -*- */
+
 #include "threads.h"
 #include "schedule.h"
 #include "common.h"
 #include "model.h"
 
 #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());
 void Scheduler::add_thread(Thread *t)
 {
        DEBUG("thread %d\n", t->get_id());
index 8267feec9df32f2b26ae1c32a81d3a36f0affb8f..e81ea935cc961b1568a25e095ae0ca4a6c9813bd 100644 (file)
@@ -1,3 +1,5 @@
+/* -*- Mode: C; indent-tabs-mode: t -*- */
+
 #ifndef __SCHEDULE_H__
 #define __SCHEDULE_H__
 
 #ifndef __SCHEDULE_H__
 #define __SCHEDULE_H__
 
@@ -9,6 +11,7 @@ class Thread;
 
 class Scheduler {
 public:
 
 class Scheduler {
 public:
+       Scheduler();
        void add_thread(Thread *t);
        void remove_thread(Thread *t);
        Thread * next_thread(void);
        void add_thread(Thread *t);
        void remove_thread(Thread *t);
        Thread * next_thread(void);
index 0ed7bdcabc084eabf0755c8df098b724d3c023c4..35000dc17d2ad40f73ea3652f0b634dd9f95678b 100644 (file)
@@ -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();
        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;
 }
 
        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;
        int ret;
 
        user_thread = t;
index b592804db95959445d5c4f967f449121e2d59bad..57319067b4adb74255435cb721d723650900153c 100644 (file)
--- a/threads.h
+++ b/threads.h
@@ -18,7 +18,7 @@ typedef enum thread_state {
 
 class Thread {
 public:
 
 class Thread {
 public:
-       Thread(thrd_t *t, void (*func)(), void *a);
+       Thread(thrd_t *t, void (*func)(void *), void *a);
        ~Thread();
        void complete();
 
        ~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; }
        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;
 
   MEMALLOC
 private:
        int create_context();
        Thread *parent;
 
-       void (*start_routine)();
+       void (*start_routine)(void *);
        void *arg;
        ucontext_t context;
        void *stack;
        void *arg;
        ucontext_t context;
        void *stack;