Allow uth_disable_notifs without current_uthread
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 8 Sep 2016 19:31:29 +0000 (15:31 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 16 Sep 2016 18:35:09 +0000 (14:35 -0400)
Upcoming changes to glibc's low-level locks will allow disable notifs to be
called before current_uthread is set up.

An unforunate side-effect of allowing this is that we lose the ability to
catch certain bugs (i.e. no long have an assert).  Also, if current_uthread
gets set in the middle of a disable/enable pair, then the
notif_disabled_depth and the associated logic will go crazy.

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

index 520c94b..49bd56a 100644 (file)
@@ -852,11 +852,12 @@ bool __check_preempt_pending(uint32_t vcoreid)
 void uth_disable_notifs(void)
 {
        if (!in_vcore_context()) {
-               assert(current_uthread);
-               if (current_uthread->notif_disabled_depth++)
-                       goto out;
-               current_uthread->flags |= UTHREAD_DONT_MIGRATE;
-               cmb();  /* don't issue the flag write before the vcore_id() read */
+               if (current_uthread) {
+                       if (current_uthread->notif_disabled_depth++)
+                               goto out;
+                       current_uthread->flags |= UTHREAD_DONT_MIGRATE;
+                       cmb();  /* don't issue the flag write before the vcore_id() read */
+               }
                disable_notifs(vcore_id());
        }
 out:
@@ -867,11 +868,12 @@ out:
 void uth_enable_notifs(void)
 {
        if (!in_vcore_context()) {
-               assert(current_uthread);
-               if (--current_uthread->notif_disabled_depth)
-                       return;
-               current_uthread->flags &= ~UTHREAD_DONT_MIGRATE;
-               cmb();  /* don't enable before ~DONT_MIGRATE */
+               if (current_uthread) {
+                       if (--current_uthread->notif_disabled_depth)
+                               return;
+                       current_uthread->flags &= ~UTHREAD_DONT_MIGRATE;
+                       cmb();  /* don't enable before ~DONT_MIGRATE */
+               }
                enable_notifs(vcore_id());
        }
 }