From f78f351da3ab2ef37d3c47a8577df0cec4e271cd Mon Sep 17 00:00:00 2001 From: jhb Date: Tue, 4 Mar 2003 20:32:41 +0000 Subject: Miscellaneous cleanups to _mtx_lock_sleep(): - Declare some local variables at the top of the function instead of in a nested block. - Use mtx_owned() instead of masking off bits from mtx_lock manually. - Read the value of mtx_lock into 'v' as a separate line rather than inside an if statement for clarity. This code is hairy enough as it is. --- sys/kern/kern_mutex.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sys/kern/kern_mutex.c') diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index f5641c5..d2d907f 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -487,14 +487,16 @@ void _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line) { struct thread *td = curthread; + struct thread *td1; #if defined(SMP) && defined(ADAPTIVE_MUTEXES) struct thread *owner; #endif + uintptr_t v; #ifdef KTR int cont_logged = 0; #endif - if ((m->mtx_lock & MTX_FLAGMASK) == (uintptr_t)td) { + if (mtx_owned(m)) { m->mtx_recurse++; atomic_set_ptr(&m->mtx_lock, MTX_RECURSED); if (LOCK_LOG_TEST(&m->mtx_object, opts)) @@ -508,15 +510,15 @@ _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line) m->mtx_object.lo_name, (void *)m->mtx_lock, file, line); while (!_obtain_lock(m, td)) { - uintptr_t v; - struct thread *td1; mtx_lock_spin(&sched_lock); + v = m->mtx_lock; + /* * Check if the lock has been released while spinning for * the sched_lock. */ - if ((v = m->mtx_lock) == MTX_UNOWNED) { + if (v == MTX_UNOWNED) { mtx_unlock_spin(&sched_lock); #ifdef __i386__ ia32_pause(); -- cgit v1.1