mtx_trylock and td_locks
sjs at netapp.com
Wed Jan 21 10:47:01 PST 2009
I just discovered something that I would think would be documented
somewhere, but my best google'ing turns up nary a mention of it.
In debug builds thread->td_locks is incremented and decremented with
mtx_lock, mtx_trylock, and mtx_unlock.
However, if LOCK_DEBUG = 0 then mtx_lock() and mtx_unlock become inline
routines that don't modify thread->td_locks. mtx_trylock() doesn't have a
non-debug inline version, so it still increments the thread value.
This means mtx_trylock() should not be used with mtx_unlock(), but rather
should always be paired with mtx_unlock_flags() to ensure thread->td_locks
receives proper accounting.
Is this by design? Or a bug?
mtx_trylock is not heavily used, so it's easy to understand that it may not
have had as much attention as the other locking routines.
More information about the freebsd-arch