From 79f227f355cd5efbcad184b20d020493f27f1c35 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Fri, 9 Mar 2012 17:28:15 -0800 Subject: [PATCH] libthreads: add thread_current() function Keeps along the lines of C11/C++11. C11: thrd_t thrd_current(void); C++11: namespace this_thread --- libthreads.c | 9 +++++++-- libthreads.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libthreads.c b/libthreads.c index ca4477f..2e3474a 100644 --- a/libthreads.c +++ b/libthreads.c @@ -67,7 +67,7 @@ static int thread_yield() static void thread_dispose(struct thread *t) { - DEBUG("completed thread %d\n", current->index); + DEBUG("completed thread %d\n", thread_current()->index); t->completed = 1; stack_free(t->stack); } @@ -115,12 +115,17 @@ void thread_join(struct thread *t) thread_yield(); } +struct thread *thread_current(void) +{ + return current; +} + void a(int *parm) { int i; for (i = 0; i < 10; i++) { - printf("Thread %d, magic number %d, loop %d\n", current->index, *parm, i); + printf("Thread %d, magic number %d, loop %d\n", thread_current()->index, *parm, i); if (i % 2) thread_yield(); } diff --git a/libthreads.h b/libthreads.h index a25b277..b73ab1c 100644 --- a/libthreads.h +++ b/libthreads.h @@ -25,5 +25,6 @@ struct thread { int thread_create(struct thread *t, void (*start_routine), void *arg); void thread_join(struct thread *t); +struct thread *thread_current(void); #endif /* __LIBTHREADS_H__ */ -- 2.34.1