A few mostly cosmetic nits to aid in debugging:

- Call lock_init() first before setting any lock_object fields in
  lock init routines.  This way if the machine panics due to a duplicate
  init the lock's original state is preserved.
- Somewhat similarly, don't decrement td_locks and td_slocks until after
  an unlock operation has completed successfully.
This commit is contained in:
John Baldwin 2013-06-25 20:23:08 +00:00
parent cd32bd7ad1
commit b5fb43e572
4 changed files with 13 additions and 13 deletions

View File

@ -238,8 +238,6 @@ wakeupshlk(struct lock *lk, const char *file, int line)
u_int realexslp;
int queue, wakeup_swapper;
TD_LOCKS_DEC(curthread);
TD_SLOCKS_DEC(curthread);
WITNESS_UNLOCK(&lk->lock_object, 0, file, line);
LOCK_LOG_LOCK("SUNLOCK", &lk->lock_object, 0, 0, file, line);
@ -339,6 +337,8 @@ wakeupshlk(struct lock *lk, const char *file, int line)
}
lock_profile_release_lock(&lk->lock_object);
TD_LOCKS_DEC(curthread);
TD_SLOCKS_DEC(curthread);
return (wakeup_swapper);
}
@ -397,12 +397,12 @@ lockinit(struct lock *lk, int pri, const char *wmesg, int timo, int flags)
iflags |= LO_IS_VNODE;
iflags |= flags & (LK_ADAPTIVE | LK_NOSHARE);
lock_init(&lk->lock_object, &lock_class_lockmgr, wmesg, NULL, iflags);
lk->lk_lock = LK_UNLOCKED;
lk->lk_recurse = 0;
lk->lk_exslpfail = 0;
lk->lk_timo = timo;
lk->lk_pri = pri;
lock_init(&lk->lock_object, &lock_class_lockmgr, wmesg, NULL, iflags);
STACK_ZERO(lk);
}

View File

@ -243,7 +243,6 @@ __mtx_unlock_flags(volatile uintptr_t *c, int opts, const char *file, int line)
KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_sleep,
("mtx_unlock() of spin mutex %s @ %s:%d", m->lock_object.lo_name,
file, line));
curthread->td_locks--;
WITNESS_UNLOCK(&m->lock_object, opts | LOP_EXCLUSIVE, file, line);
LOCK_LOG_LOCK("UNLOCK", &m->lock_object, opts, m->mtx_recurse, file,
line);
@ -252,6 +251,7 @@ __mtx_unlock_flags(volatile uintptr_t *c, int opts, const char *file, int line)
if (m->mtx_recurse == 0)
LOCKSTAT_PROFILE_RELEASE_LOCK(LS_MTX_UNLOCK_RELEASE, m);
__mtx_unlock(m, curthread, opts, file, line);
curthread->td_locks--;
}
void
@ -894,10 +894,10 @@ _mtx_init(volatile uintptr_t *c, const char *name, const char *type, int opts)
flags |= LO_NOPROFILE;
/* Initialize mutex. */
lock_init(&m->lock_object, class, name, type, flags);
m->mtx_lock = MTX_UNOWNED;
m->mtx_recurse = 0;
lock_init(&m->lock_object, class, name, type, flags);
}
/*

View File

@ -207,9 +207,9 @@ _rw_init_flags(volatile uintptr_t *c, const char *name, int opts)
if (opts & RW_QUIET)
flags |= LO_QUIET;
lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags);
rw->rw_lock = RW_UNLOCKED;
rw->rw_recurse = 0;
lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags);
}
void
@ -319,13 +319,13 @@ _rw_wunlock_cookie(volatile uintptr_t *c, const char *file, int line)
KASSERT(rw->rw_lock != RW_DESTROYED,
("rw_wunlock() of destroyed rwlock @ %s:%d", file, line));
__rw_assert(c, RA_WLOCKED, file, line);
curthread->td_locks--;
WITNESS_UNLOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line);
LOCK_LOG_LOCK("WUNLOCK", &rw->lock_object, 0, rw->rw_recurse, file,
line);
if (!rw_recursed(rw))
LOCKSTAT_PROFILE_RELEASE_LOCK(LS_RW_WUNLOCK_RELEASE, rw);
__rw_wunlock(rw, curthread, file, line);
curthread->td_locks--;
}
/*
* Determines whether a new reader can acquire a lock. Succeeds if the
@ -598,8 +598,6 @@ _rw_runlock_cookie(volatile uintptr_t *c, const char *file, int line)
KASSERT(rw->rw_lock != RW_DESTROYED,
("rw_runlock() of destroyed rwlock @ %s:%d", file, line));
__rw_assert(c, RA_RLOCKED, file, line);
curthread->td_locks--;
curthread->td_rw_rlocks--;
WITNESS_UNLOCK(&rw->lock_object, 0, file, line);
LOCK_LOG_LOCK("RUNLOCK", &rw->lock_object, 0, 0, file, line);
@ -693,6 +691,8 @@ _rw_runlock_cookie(volatile uintptr_t *c, const char *file, int line)
break;
}
LOCKSTAT_PROFILE_RELEASE_LOCK(LS_RW_RUNLOCK_RELEASE, rw);
curthread->td_locks--;
curthread->td_rw_rlocks--;
}
/*

View File

@ -228,9 +228,9 @@ sx_init_flags(struct sx *sx, const char *description, int opts)
flags |= LO_QUIET;
flags |= opts & SX_NOADAPTIVE;
lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags);
sx->sx_lock = SX_LOCK_UNLOCKED;
sx->sx_recurse = 0;
lock_init(&sx->lock_object, &lock_class_sx, description, NULL, flags);
}
void
@ -362,11 +362,11 @@ _sx_sunlock(struct sx *sx, const char *file, int line)
KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
("sx_sunlock() of destroyed sx @ %s:%d", file, line));
_sx_assert(sx, SA_SLOCKED, file, line);
curthread->td_locks--;
WITNESS_UNLOCK(&sx->lock_object, 0, file, line);
LOCK_LOG_LOCK("SUNLOCK", &sx->lock_object, 0, 0, file, line);
__sx_sunlock(sx, file, line);
LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_SUNLOCK_RELEASE, sx);
curthread->td_locks--;
}
void
@ -378,13 +378,13 @@ _sx_xunlock(struct sx *sx, const char *file, int line)
KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
("sx_xunlock() of destroyed sx @ %s:%d", file, line));
_sx_assert(sx, SA_XLOCKED, file, line);
curthread->td_locks--;
WITNESS_UNLOCK(&sx->lock_object, LOP_EXCLUSIVE, file, line);
LOCK_LOG_LOCK("XUNLOCK", &sx->lock_object, 0, sx->sx_recurse, file,
line);
if (!sx_recursed(sx))
LOCKSTAT_PROFILE_RELEASE_LOCK(LS_SX_XUNLOCK_RELEASE, sx);
__sx_xunlock(sx, curthread, file, line);
curthread->td_locks--;
}
/*