From b516d2f5e1f9d2d0a1d694055169a18a1e24f0a3 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Wed, 23 May 2001 19:38:26 +0000 Subject: [PATCH] Add in assertions to ensure that we always call msleep or mawait with either a timeout or a held mutex to detect unprotected infinite sleeps that can easily lead to deadlock. Submitted by: alfred --- sys/kern/kern_synch.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 7d793de4ee2b..a45b71edae91 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -383,6 +383,8 @@ msleep(ident, mtx, priority, wmesg, timo) ktrcsw(p->p_tracep, 1, 0); #endif WITNESS_SLEEP(0, &mtx->mtx_object); + KASSERT(timo != 0 || mtx_owned(&Giant) || mtx != NULL, + ("sleeping without a mutex")); mtx_lock_spin(&sched_lock); if (cold || panicstr) { /* @@ -574,6 +576,8 @@ mawait(struct mtx *mtx, int priority, int timo) WITNESS_SAVE_DECL(mtx); WITNESS_SLEEP(0, &mtx->mtx_object); + KASSERT(timo > 0 || mtx_owned(&Giant) || mtx != NULL, + ("sleeping without a mutex")); mtx_lock_spin(&sched_lock); DROP_GIANT_NOSWITCH(); if (mtx != NULL) {