threads: change thrd_t to store Thread pointer
authorBrian Norris <banorris@uci.edu>
Thu, 20 Dec 2012 00:03:45 +0000 (16:03 -0800)
committerBrian Norris <banorris@uci.edu>
Wed, 2 Jan 2013 22:15:49 +0000 (14:15 -0800)
I need to make some bigger changes to Thread allocation, so we'll need
to modify the storage of thrd_t.

include/threads.h
libthreads.cc
threads-model.h
threads.cc

index d1ff192..66df5b1 100644 (file)
@@ -5,13 +5,18 @@
 #ifndef __THREADS_H__
 #define __THREADS_H__
 
+/* Forward declaration */
+struct Thread; /* actually, class; but this is safe */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
        typedef void (*thrd_start_t)(void *);
 
-       typedef int thrd_t;
+       typedef struct {
+               struct Thread *priv;
+       } thrd_t;
 
        int thrd_create(thrd_t *t, thrd_start_t start_routine, void *arg);
        int thrd_join(thrd_t);
index fce87da..adb4b2b 100644 (file)
@@ -20,7 +20,7 @@ int thrd_create(thrd_t *t, thrd_start_t start_routine, void *arg)
 
 int thrd_join(thrd_t t)
 {
-       Thread *th = model->get_thread(thrd_to_id(t));
+       Thread *th = t.priv;
        model->switch_to_master(new ModelAction(THREAD_JOIN, std::memory_order_seq_cst, th, id_to_int(thrd_to_id(t))));
        return 0;
 }
index 344d58b..0236210 100644 (file)
@@ -148,7 +148,7 @@ Thread * thread_current();
 
 static inline thread_id_t thrd_to_id(thrd_t t)
 {
-       return t;
+       return t.priv->get_id();
 }
 
 /**
index d170b7a..6adc053 100644 (file)
@@ -161,7 +161,7 @@ Thread::Thread(thrd_t *t, void (*func)(void *), void *a) :
                model_print("Error in create_context\n");
 
        id = model->get_next_id();
-       *user_thread = id;
+       user_thread->priv = this;
        parent = thread_current();
 }