From: Brian Norris Date: Sat, 10 Mar 2012 01:28:15 +0000 (-0800) Subject: libthreads: add thread_current() function X-Git-Tag: pldi2013~609 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=79f227f355cd5efbcad184b20d020493f27f1c35;p=model-checker.git libthreads: add thread_current() function Keeps along the lines of C11/C++11. C11: thrd_t thrd_current(void); C++11: namespace this_thread --- 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__ */