diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index 04e66ccb3e53..f0bed3f9d4a2 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -517,14 +517,20 @@ transferlockers(from, to) KASSERT(from != to, ("lock transfer to self")); KASSERT((from->lk_flags&LK_WAITDRAIN) == 0, ("transfer draining lock")); - if (from->lk_waitcount == 0) + + mtx_lock(from->lk_interlock); + if (from->lk_waitcount == 0) { + mtx_unlock(from->lk_interlock); return; + } from->lk_newlock = to; wakeup((void *)from); - msleep(&from->lk_newlock, NULL, from->lk_prio, "lkxfer", 0); + msleep(&from->lk_newlock, from->lk_interlock, from->lk_prio, + "lkxfer", 0); from->lk_newlock = NULL; from->lk_flags &= ~(LK_WANT_EXCL | LK_WANT_UPGRADE); KASSERT(from->lk_waitcount == 0, ("active lock")); + mtx_unlock(from->lk_interlock); }