libthreads: add thread_current() function
authorBrian Norris <banorris@uci.edu>
Sat, 10 Mar 2012 01:28:15 +0000 (17:28 -0800)
committerBrian Norris <banorris@uci.edu>
Sat, 10 Mar 2012 01:36:08 +0000 (17:36 -0800)
Keeps along the lines of C11/C++11.

C11: thrd_t thrd_current(void);
C++11: namespace this_thread

libthreads.c
libthreads.h

index ca4477f66740b2b384612b720eda074b5e04e777..2e3474aaa881b0c460e3cc0e150b5fbcb7461545 100644 (file)
@@ -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();
        }
index a25b27797268326ca63db433b31ffcd4897c0b22..b73ab1c0cee46fc063c42d703f2b8e922d0d5210 100644 (file)
@@ -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__ */