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 d1ff1929aba37840d9cab9f5b5bf087639057550..66df5b1191cfa1d050d020c7bd3a01d3e4bd9fc3 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 fce87daf5bc0d8969d4546ce6837a30dda4019eb..adb4b2bfdb0c4f709999d6d2c6af6554098e9325 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 344d58badada9f13297a149c220c0f33d505238a..02362100dca410b35f531ef536e2066f85315890 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 d170b7ada3554da89213ab6219fff15c11ed0019..6adc053ae2dbfc58a00bbbb2f0e6a7c2e79a7b4c 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();
 }