mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-16 10:20:30 +00:00
- Allow mtx_trylock() to recurse on a recursive mutex. Attempts to recurse
on a non-recursive mutex will fail but will not trigger any assertions. - Add an assertion to mtx_lock() that one never recurses on a non-recursive mutex. This is mostly useful for the non-WITNESS case. Requested by: deischen, julian, others (1)
This commit is contained in:
parent
973e839bed
commit
eac097962f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=124161
@ -338,10 +338,8 @@ _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file, int line)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* The important part of mtx_trylock{,_flags}()
|
* The important part of mtx_trylock{,_flags}()
|
||||||
* Tries to acquire lock `m.' We do NOT handle recursion here. If this
|
* Tries to acquire lock `m.' If this function is called on a mutex that
|
||||||
* function is called on a recursed mutex, it will return failure and
|
* is already owned, it will recursively acquire the lock.
|
||||||
* will not recursively acquire the lock. You are expected to know what
|
|
||||||
* you are doing.
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
_mtx_trylock(struct mtx *m, int opts, const char *file, int line)
|
_mtx_trylock(struct mtx *m, int opts, const char *file, int line)
|
||||||
@ -350,7 +348,12 @@ _mtx_trylock(struct mtx *m, int opts, const char *file, int line)
|
|||||||
|
|
||||||
MPASS(curthread != NULL);
|
MPASS(curthread != NULL);
|
||||||
|
|
||||||
rval = _obtain_lock(m, curthread);
|
if (mtx_owned(m) && (m->mtx_object.lo_flags & LO_RECURSABLE) != 0) {
|
||||||
|
m->mtx_recurse++;
|
||||||
|
atomic_set_ptr(&m->mtx_lock, MTX_RECURSED);
|
||||||
|
rval = 1;
|
||||||
|
} else
|
||||||
|
rval = _obtain_lock(m, curthread);
|
||||||
|
|
||||||
LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line);
|
LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line);
|
||||||
if (rval)
|
if (rval)
|
||||||
@ -380,6 +383,9 @@ _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mtx_owned(m)) {
|
if (mtx_owned(m)) {
|
||||||
|
KASSERT((m->mtx_object.lo_flags & LO_RECURSABLE) != 0,
|
||||||
|
("_mtx_lock_sleep: recursed on non-recursive mutex %s @ %s:%d\n",
|
||||||
|
m->mtx_object.lo_name, file, line));
|
||||||
m->mtx_recurse++;
|
m->mtx_recurse++;
|
||||||
atomic_set_ptr(&m->mtx_lock, MTX_RECURSED);
|
atomic_set_ptr(&m->mtx_lock, MTX_RECURSED);
|
||||||
if (LOCK_LOG_TEST(&m->mtx_object, opts))
|
if (LOCK_LOG_TEST(&m->mtx_object, opts))
|
||||||
|
Loading…
Reference in New Issue
Block a user