summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_mutex.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2002-09-03 18:25:16 +0000
committerjhb <jhb@FreeBSD.org>2002-09-03 18:25:16 +0000
commitd8e689eb0900c6d104b4a22398efd9d6c57f0d9d (patch)
tree8273a391c85123e4081de6ff13197760440860cd /sys/kern/kern_mutex.c
parent5825d567f81ff5f32a843f17ff64be7ffca1cccd (diff)
downloadFreeBSD-src-d8e689eb0900c6d104b4a22398efd9d6c57f0d9d.zip
FreeBSD-src-d8e689eb0900c6d104b4a22398efd9d6c57f0d9d.tar.gz
Add some KASSERT()'s to ensure that we don't perform spin mutex ops on
sleep mutexes and vice versa. WITNESS normally should catch this but not everyone uses WITNESS so this is a fallback to catch nasty but easy to do bugs.
Diffstat (limited to 'sys/kern/kern_mutex.c')
-rw-r--r--sys/kern/kern_mutex.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index 982b376..00a789c 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -316,6 +316,9 @@ _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line)
{
MPASS(curthread != NULL);
+ KASSERT(m->mtx_object.lo_class == &lock_class_mtx_sleep,
+ ("mtx_lock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name,
+ file, line));
_get_sleep_lock(m, curthread, opts, file, line);
LOCK_LOG_LOCK("LOCK", &m->mtx_object, opts, m->mtx_recurse, file,
line);
@@ -336,6 +339,12 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line)
{
MPASS(curthread != NULL);
+ KASSERT(m->mtx_object.lo_class == &lock_class_mtx_sleep,
+ ("mtx_unlock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name,
+ file, line));
+ WITNESS_UNLOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line);
+ LOCK_LOG_LOCK("UNLOCK", &m->mtx_object, opts, m->mtx_recurse, file,
+ line);
mtx_assert(m, MA_OWNED);
#ifdef MUTEX_PROFILING
if (m->mtx_acqtime != 0) {
@@ -392,9 +401,6 @@ unlock:
}
out:
#endif
- WITNESS_UNLOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line);
- LOCK_LOG_LOCK("UNLOCK", &m->mtx_object, opts, m->mtx_recurse, file,
- line);
_rel_sleep_lock(m, curthread, opts, file, line);
}
@@ -403,6 +409,9 @@ _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file, int line)
{
MPASS(curthread != NULL);
+ KASSERT(m->mtx_object.lo_class == &lock_class_mtx_spin,
+ ("mtx_lock_spin() of sleep mutex %s @ %s:%d",
+ m->mtx_object.lo_name, file, line));
#if defined(SMP) || LOCK_DEBUG > 0 || 1
_get_spin_lock(m, curthread, opts, file, line);
#else
@@ -418,10 +427,13 @@ _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file, int line)
{
MPASS(curthread != NULL);
- mtx_assert(m, MA_OWNED);
+ KASSERT(m->mtx_object.lo_class == &lock_class_mtx_spin,
+ ("mtx_unlock_spin() of sleep mutex %s @ %s:%d",
+ m->mtx_object.lo_name, file, line));
WITNESS_UNLOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line);
LOCK_LOG_LOCK("UNLOCK", &m->mtx_object, opts, m->mtx_recurse, file,
line);
+ mtx_assert(m, MA_OWNED);
#if defined(SMP) || LOCK_DEBUG > 0 || 1
_rel_spin_lock(m);
#else
OpenPOWER on IntegriCloud