From 96bc0872c55ea4a0c1c52f7d5145f3f953226f78 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 19 Dec 2012 16:03:45 -0800 Subject: [PATCH] threads: change thrd_t to store Thread pointer I need to make some bigger changes to Thread allocation, so we'll need to modify the storage of thrd_t. --- include/threads.h | 7 ++++++- libthreads.cc | 2 +- threads-model.h | 2 +- threads.cc | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/threads.h b/include/threads.h index d1ff1929..66df5b11 100644 --- a/include/threads.h +++ b/include/threads.h @@ -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); diff --git a/libthreads.cc b/libthreads.cc index fce87daf..adb4b2bf 100644 --- a/libthreads.cc +++ b/libthreads.cc @@ -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; } diff --git a/threads-model.h b/threads-model.h index 344d58ba..02362100 100644 --- a/threads-model.h +++ b/threads-model.h @@ -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(); } /** diff --git a/threads.cc b/threads.cc index d170b7ad..6adc053a 100644 --- a/threads.cc +++ b/threads.cc @@ -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(); } -- 2.34.1