diff options
author | jhb <jhb@FreeBSD.org> | 2006-07-27 21:45:55 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2006-07-27 21:45:55 +0000 |
commit | e1d747891ebae739b02fd9f0c83952f245af7641 (patch) | |
tree | 6aa25b1f8f1ba91bd0c1aa70c6b9d4dae14a8068 /sys/kern/kern_mutex.c | |
parent | d832089727940c20baeb04e3e758321140630059 (diff) | |
download | FreeBSD-src-e1d747891ebae739b02fd9f0c83952f245af7641.zip FreeBSD-src-e1d747891ebae739b02fd9f0c83952f245af7641.tar.gz |
Adjust td_locks for non-spin mutexes, rwlocks, and sx locks so that it is
a count of all non-spin locks, not just lockmgr locks. This can give us a
much cheaper way to see if we have any locks held (such as when returning
to userland via userret()) without requiring WITNESS.
MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_mutex.c')
-rw-r--r-- | sys/kern/kern_mutex.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 04368e5..6c66537 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -287,6 +287,7 @@ _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line) LOCK_LOG_LOCK("LOCK", &m->mtx_object, opts, m->mtx_recurse, file, line); WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line); + curthread->td_locks++; #ifdef MUTEX_PROFILING /* don't reset the timer when/if recursing */ if (m->mtx_acqtime == 0) { @@ -308,6 +309,7 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int 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)); + curthread->td_locks--; WITNESS_UNLOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line); LOCK_LOG_LOCK("UNLOCK", &m->mtx_object, opts, m->mtx_recurse, file, line); @@ -439,9 +441,11 @@ _mtx_trylock(struct mtx *m, int opts, const char *file, int line) rval = _obtain_lock(m, (uintptr_t)curthread); LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line); - if (rval) + if (rval) { WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE | LOP_TRYLOCK, file, line); + curthread->td_locks++; + } return (rval); } @@ -889,6 +893,8 @@ mtx_destroy(struct mtx *m) /* Perform the non-mtx related part of mtx_unlock_spin(). */ if (LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_spin) spinlock_exit(); + else + curthread->td_locks--; /* Tell witness this isn't locked to make it happy. */ WITNESS_UNLOCK(&m->mtx_object, LOP_EXCLUSIVE, __FILE__, |