parlib: UTH_EXT_BLK_JUSTICE -> _MISC
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 13 Apr 2017 17:24:17 +0000 (13:24 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 3 May 2017 16:13:02 +0000 (12:13 -0400)
And have pthreads track the appropriate state for threads blocking.  This
will only matter for diagnostics: we can look at a pthread and get a hint
as to what its doing or why it is blocked.

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

index 0e09db1..b2f3f9c 100644 (file)
@@ -24,7 +24,7 @@ __BEGIN_DECLS
 #define UTH_EXT_BLK_MUTEX                      1
 #define UTH_EXT_BLK_EVENTQ                     2
 #define UTH_EXT_BLK_YIELD                      3
-#define UTH_EXT_BLK_JUSTICE                    4       /* whatever.  might need more options */
+#define UTH_EXT_BLK_MISC                       4
 
 /* One per joiner, usually kept on the stack. */
 struct uth_join_kicker {
index 7f1d484..1948a1c 100644 (file)
@@ -529,7 +529,7 @@ void uthread_usleep(unsigned int usecs)
 
 static void __sleep_forever_cb(struct uthread *uth, void *arg)
 {
-       uthread_has_blocked(uth, NULL, UTH_EXT_BLK_JUSTICE);
+       uthread_has_blocked(uth, NULL, UTH_EXT_BLK_MISC);
 }
 
 void __attribute__((noreturn)) uthread_sleep_forever(void)
@@ -1342,7 +1342,7 @@ static void __uth_join_cb(struct uthread *uth, void *arg)
 {
        struct uth_join_kicker *jk = (struct uth_join_kicker*)arg;
 
-       uthread_has_blocked(uth, NULL, UTH_EXT_BLK_MUTEX);
+       uthread_has_blocked(uth, NULL, UTH_EXT_BLK_MISC);
        /* After this, and after all threads join, we could be woken up. */
        kref_put(&jk->kref);
 }
index 61a8486..7368009 100644 (file)
@@ -145,6 +145,7 @@ static void pth_thread_runnable(struct uthread *uthread)
                case (PTH_BLK_SYSC):
                case (PTH_BLK_PAUSED):
                case (PTH_BLK_MUTEX):
+               case (PTH_BLK_MISC):
                        /* can do whatever for each of these cases */
                        break;
                default:
@@ -252,16 +253,18 @@ static void pth_thread_has_blocked(struct uthread *uthread, uth_sync_t sync_obj,
        struct pthread_tcb *pthread = (struct pthread_tcb*)uthread;
 
        __pthread_generic_yield(pthread);
-       /* Could imagine doing something with the flags.  For now, we just treat
-        * most externally blocked reasons as 'MUTEX'.  Whatever we do here, we are
-        * mostly communicating to our future selves in pth_thread_runnable(), which
-        * gets called by whoever triggered this callback */
+       /* Whatever we do here, we are mostly communicating to our future selves in
+        * pth_thread_runnable(), which gets called by whoever triggered this
+        * callback */
        switch (flags) {
        case UTH_EXT_BLK_YIELD:
                pthread->state = PTH_BLK_YIELDING;
                break;
-       default:
+       case UTH_EXT_BLK_MUTEX:
                pthread->state = PTH_BLK_MUTEX;
+               break;
+       default:
+               pthread->state = PTH_BLK_MISC;
        };
        if (sync_obj)
                __uth_default_sync_enqueue(uthread, sync_obj);
index ce161bd..99c58f8 100644 (file)
@@ -23,6 +23,7 @@ __BEGIN_DECLS
 #define PTH_BLK_SYSC           6       /* blocked on a syscall */
 #define PTH_BLK_MUTEX          7       /* blocked externally, possibly on a mutex */
 #define PTH_BLK_PAUSED         8       /* handed back to us from uthread code */
+#define PTH_BLK_MISC           9       /* catch-all from uthread code */
 
 /* Entry for a pthread_cleanup_routine on the stack of cleanup handlers. */
 struct pthread_cleanup_routine {