lock stats updates need to be protected by the lock

This commit is contained in:
Kip Macy 2007-03-02 07:21:20 +00:00
parent 1fa420b671
commit c66d760608
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=167163
2 changed files with 8 additions and 44 deletions

View File

@ -157,9 +157,6 @@ _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line)
void
_mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line)
{
#ifdef LOCK_PROFILING
struct lock_object lo;
#endif
MPASS(curthread != NULL);
KASSERT(m->mtx_lock != MTX_DESTROYED,
("mtx_unlock() of destroyed mutex @ %s:%d", file, line));
@ -171,14 +168,9 @@ _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line)
LOCK_LOG_LOCK("UNLOCK", &m->mtx_object, opts, m->mtx_recurse, file,
line);
mtx_assert(m, MA_OWNED);
#ifdef LOCK_PROFILING
memcpy(&lo, &m->mtx_object, sizeof(lo));
m->mtx_object.lo_flags &= ~LO_CONTESTED;
#endif
lock_profile_release_lock(&m->mtx_object);
_rel_sleep_lock(m, curthread, opts, file, line);
#ifdef LOCK_PROFILING
lock_profile_release_lock(&lo);
#endif
}
void
@ -202,9 +194,7 @@ _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file, int line)
void
_mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file, int line)
{
#ifdef LOCK_PROFILING
struct lock_object lo;
#endif
MPASS(curthread != NULL);
KASSERT(m->mtx_lock != MTX_DESTROYED,
("mtx_unlock_spin() of destroyed mutex @ %s:%d", file, line));
@ -215,14 +205,9 @@ _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file, int line)
LOCK_LOG_LOCK("UNLOCK", &m->mtx_object, opts, m->mtx_recurse, file,
line);
mtx_assert(m, MA_OWNED);
#ifdef LOCK_PROFILING
memcpy(&lo, &m->mtx_object, sizeof(lo));
m->mtx_object.lo_flags &= ~LO_CONTESTED;
#endif
lock_profile_release_lock(&m->mtx_object);
_rel_spin_lock(m);
#ifdef LOCK_PROFILING
lock_profile_release_lock(&lo);
#endif
}
/*

View File

@ -228,10 +228,6 @@ _sx_try_xlock(struct sx *sx, const char *file, int line)
void
_sx_sunlock(struct sx *sx, const char *file, int line)
{
#ifdef LOCK_PROFILING
struct lock_object lo;
int count = -1;
#endif
_sx_assert(sx, SX_SLOCKED, file, line);
mtx_lock(sx->sx_lock);
@ -241,13 +237,10 @@ _sx_sunlock(struct sx *sx, const char *file, int line)
/* Release. */
sx->sx_cnt--;
#ifdef LOCK_PROFILING
if (sx->sx_cnt == 0) {
memcpy(&lo, &sx->sx_object, sizeof(lo));
sx->sx_object.lo_flags &= ~LO_CONTESTED;
count = 0;
lock_profile_release_lock(&sx->sx_object);
}
#endif
/*
* If we just released the last shared lock, wake any waiters up, giving
* exclusive lockers precedence. In order to make sure that exclusive
@ -263,19 +256,11 @@ _sx_sunlock(struct sx *sx, const char *file, int line)
LOCK_LOG_LOCK("SUNLOCK", &sx->sx_object, 0, 0, file, line);
mtx_unlock(sx->sx_lock);
#ifdef LOCK_PROFILING
if (count == 0)
lock_profile_release_lock(&lo);
#endif
}
void
_sx_xunlock(struct sx *sx, const char *file, int line)
{
#ifdef LOCK_PROFILING
struct lock_object lo;
#endif
_sx_assert(sx, SX_XLOCKED, file, line);
mtx_lock(sx->sx_lock);
MPASS(sx->sx_cnt == -1);
@ -287,10 +272,6 @@ _sx_xunlock(struct sx *sx, const char *file, int line)
sx->sx_cnt++;
sx->sx_xholder = NULL;
#ifdef LOCK_PROFILING
memcpy(&lo, &sx->sx_object, sizeof(lo));
sx->sx_object.lo_flags &= ~LO_CONTESTED;
#endif
/*
* Wake up waiters if there are any. Give precedence to slock waiters.
*/
@ -301,10 +282,8 @@ _sx_xunlock(struct sx *sx, const char *file, int line)
LOCK_LOG_LOCK("XUNLOCK", &sx->sx_object, 0, 0, file, line);
lock_profile_release_lock(&sx->sx_object);
mtx_unlock(sx->sx_lock);
#ifdef LOCK_PROFILING
lock_profile_release_lock(&lo);
#endif
}
int