Fix wonky tail queue swap in condition variables code.
authorChristopher Koch <chrisko@google.com>
Wed, 3 Aug 2016 21:36:36 +0000 (14:36 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 3 Aug 2016 22:22:32 +0000 (15:22 -0700)
TAILQs happen to refer to themselves (double pointer), so just swapping the
contents of the struct is not enough.

Change-Id: Id06cdbda8dcc3f77812e943c4f8d38354cc2cb1f
Signed-off-by: Christopher Koch <chrisko@google.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/parlib/mutex.c

index 0e4e7dd..c293197 100644 (file)
@@ -266,22 +266,13 @@ static void uth_default_cv_signal(struct uth_default_cv *cv)
                uthread_runnable(first->uth);
 }
 
-static void swap_cv_lists(struct cv_link_tq *a, struct cv_link_tq *b)
-{
-       struct cv_link_tq temp;
-
-       temp = *a;
-       *a = *b;
-       *b = temp;
-}
-
 static void uth_default_cv_broadcast(struct uth_default_cv *cv)
 {
        struct cv_link_tq restartees = TAILQ_HEAD_INITIALIZER(restartees);
        struct uth_cv_link *i, *safe;
 
        spin_pdr_lock(&cv->lock);
-       swap_cv_lists(&cv->waiters, &restartees);
+       TAILQ_SWAP(&cv->waiters, &restartees, uth_cv_link, next);
        spin_pdr_unlock(&cv->lock);
        /* Need the SAFE, since we can't touch the linkage once the uth could run */
        TAILQ_FOREACH_SAFE(i, &restartees, next, safe)