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
This commit is contained in:
parent
f30e89ced3
commit
186abbd727
@ -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);
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,11 @@
|
||||
#define MTX_UNOWNED 0x00000004 /* Cookie for free mutex */
|
||||
#define MTX_FLAGMASK (MTX_RECURSED | MTX_CONTESTED | MTX_UNOWNED)
|
||||
|
||||
/*
|
||||
* Value stored in mutex->mtx_lock to denote a destroyed mutex.
|
||||
*/
|
||||
#define MTX_DESTROYED (MTX_CONTESTED | MTX_UNOWNED)
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#ifndef LOCORE
|
||||
|
Loading…
x
Reference in New Issue
Block a user