summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2001-05-23 19:38:26 +0000
committerjhb <jhb@FreeBSD.org>2001-05-23 19:38:26 +0000
commit3f4e4d353ca694c8535f3410280128fde8e1cc06 (patch)
tree5ca140e5d18dcf1f9ed3339ff8d7840b05508176 /sys/kern
parent31d58379e49d3c69e14104acf2b520798655a633 (diff)
downloadFreeBSD-src-3f4e4d353ca694c8535f3410280128fde8e1cc06.zip
FreeBSD-src-3f4e4d353ca694c8535f3410280128fde8e1cc06.tar.gz
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
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_synch.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 7d793de..a45b71e 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) {
OpenPOWER on IntegriCloud