parlib: Add uthread_self()
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 13 Apr 2017 19:30:16 +0000 (15:30 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 3 May 2017 16:13:02 +0000 (12:13 -0400)
Yes, this is just current_uthread, but having a layer of interposition is
useful for catching bugs.  Specifically, I'm worried about apps or
libraries calling one of the _self() functions from vcore context - they'd
get the ID of the thread running on that vcore, not the vcore itself.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/parlib/include/parlib/uthread.h
user/parlib/uthread.c
user/pthread/pthread.c

index b2f3f9c..15671f1 100644 (file)
@@ -149,6 +149,7 @@ void uthread_detach(struct uthread *uth);
 void uthread_join(struct uthread *uth, void **retval_loc);
 void uthread_join_arr(struct uth_join_request reqs[], size_t nr_req);
 void uthread_sched_yield(void);
+struct uthread *uthread_self(void);
 
 /* Call this when you are done with a uthread, forever, but before you free it */
 void uthread_cleanup(struct uthread *uthread);
index 1948a1c..123a5f8 100644 (file)
@@ -1396,3 +1396,8 @@ void uthread_sched_yield(void)
        }
        uthread_yield(TRUE, __uth_sched_yield_cb, NULL);
 }
+
+struct uthread *uthread_self(void)
+{
+       return current_uthread;
+}
index 7368009..77a90b7 100644 (file)
@@ -956,9 +956,9 @@ int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)
        return 0;
 }
 
-pthread_t pthread_self()
+pthread_t pthread_self(void)
 {
-  return (struct pthread_tcb*)current_uthread;
+       return (struct pthread_tcb*)uthread_self();
 }
 
 int pthread_equal(pthread_t t1, pthread_t t2)