summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_mutex.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2006-07-27 19:58:18 +0000
committerjhb <jhb@FreeBSD.org>2006-07-27 19:58:18 +0000
commit9b98bcfb28da9641f7bc2452795817f02da89384 (patch)
tree7c81e0fd6fdc0bd6ec61593d8f903ab2f86c6c44 /sys/kern/kern_mutex.c
parent6b46a69f12998c9846877c8a8fb21b23651044c1 (diff)
downloadFreeBSD-src-9b98bcfb28da9641f7bc2452795817f02da89384.zip
FreeBSD-src-9b98bcfb28da9641f7bc2452795817f02da89384.tar.gz
Write a magic value into mtx_lock when destroying a mutex that will force
all other mtx_lock() operations to block. Previously, when the mutex was destroyed, it would still have a valid value in mtx_lock(): either the unowned cookie, which would allow a subsequent mtx_lock() to succeed, or a pointer to the thread who destroyed the mutex if the mutex was locked when it was destroyed. MFC after: 3 days
Diffstat (limited to 'sys/kern/kern_mutex.c')
-rw-r--r--sys/kern/kern_mutex.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c
index 634fa9d..04368e5 100644
--- a/sys/kern/kern_mutex.c
+++ b/sys/kern/kern_mutex.c
@@ -276,6 +276,8 @@ _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line)
{
MPASS(curthread != NULL);
+ KASSERT(m->mtx_lock != MTX_DESTROYED,
+ ("mtx_lock() of destroyed mutex @ %s:%d", file, line));
KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_sleep,
("mtx_lock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name,
file, line));
@@ -301,6 +303,8 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line)
{
MPASS(curthread != NULL);
+ KASSERT(m->mtx_lock != MTX_DESTROYED,
+ ("mtx_unlock() of destroyed mutex @ %s:%d", file, line));
KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_sleep,
("mtx_unlock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name,
file, line));
@@ -380,6 +384,8 @@ _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file, int line)
{
MPASS(curthread != NULL);
+ KASSERT(m->mtx_lock != MTX_DESTROYED,
+ ("mtx_lock_spin() of destroyed mutex @ %s:%d", file, line));
KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_spin,
("mtx_lock_spin() of sleep mutex %s @ %s:%d",
m->mtx_object.lo_name, file, line));
@@ -396,6 +402,8 @@ _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file, int line)
{
MPASS(curthread != NULL);
+ KASSERT(m->mtx_lock != MTX_DESTROYED,
+ ("mtx_unlock_spin() of destroyed mutex @ %s:%d", file, line));
KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_spin,
("mtx_unlock_spin() of sleep mutex %s @ %s:%d",
m->mtx_object.lo_name, file, line));
@@ -417,6 +425,8 @@ _mtx_trylock(struct mtx *m, int opts, const char *file, int line)
int rval;
MPASS(curthread != NULL);
+ KASSERT(m->mtx_lock != MTX_DESTROYED,
+ ("mtx_trylock() of destroyed mutex @ %s:%d", file, line));
KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_sleep,
("mtx_trylock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name,
file, line));
@@ -885,6 +895,7 @@ mtx_destroy(struct mtx *m)
__LINE__);
}
+ m->mtx_lock = MTX_DESTROYED;
lock_destroy(&m->mtx_object);
}
OpenPOWER on IntegriCloud