Properly assert that mtx_trylock() is not called on a mutex we already
owned. Previously the KASSERT would only trigger if we successfully acquired a lock that we already held. However, _obtain_lock() fails to acquire locks that we already hold, so the KASSERT was never checked in the case it was supposed to fail.
This commit is contained in:
parent
d7a715dc64
commit
6b869595c5
@ -464,19 +464,15 @@ _mtx_trylock(struct mtx *m, int opts, const char *file, int line)
|
||||
|
||||
MPASS(curthread != NULL);
|
||||
|
||||
KASSERT(!mtx_owned(m),
|
||||
("mtx_trylock() called on a mutex already owned"));
|
||||
|
||||
rval = _obtain_lock(m, curthread);
|
||||
|
||||
LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line);
|
||||
if (rval) {
|
||||
/*
|
||||
* We do not handle recursion in _mtx_trylock; see the
|
||||
* note at the top of the routine.
|
||||
*/
|
||||
KASSERT(!mtx_recursed(m),
|
||||
("mtx_trylock() called on a recursed mutex"));
|
||||
if (rval)
|
||||
WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE | LOP_TRYLOCK,
|
||||
file, line);
|
||||
}
|
||||
|
||||
return (rval);
|
||||
}
|
||||
|
@ -464,19 +464,15 @@ _mtx_trylock(struct mtx *m, int opts, const char *file, int line)
|
||||
|
||||
MPASS(curthread != NULL);
|
||||
|
||||
KASSERT(!mtx_owned(m),
|
||||
("mtx_trylock() called on a mutex already owned"));
|
||||
|
||||
rval = _obtain_lock(m, curthread);
|
||||
|
||||
LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line);
|
||||
if (rval) {
|
||||
/*
|
||||
* We do not handle recursion in _mtx_trylock; see the
|
||||
* note at the top of the routine.
|
||||
*/
|
||||
KASSERT(!mtx_recursed(m),
|
||||
("mtx_trylock() called on a recursed mutex"));
|
||||
if (rval)
|
||||
WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE | LOP_TRYLOCK,
|
||||
file, line);
|
||||
}
|
||||
|
||||
return (rval);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user