Condition variable usage, zevent_cv

The following incorrect usage of cv_broadcast() was caught by
code inspection.  The cv_broadcast() function must be called
under the associated mutex to preventing racing with cv_wait().

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
This commit is contained in:
Brian Behlendorf 2012-10-15 13:36:26 -07:00
parent 6cb7ab069d
commit 99db9bfde7
1 changed files with 7 additions and 4 deletions

View File

@ -481,14 +481,13 @@ zfs_zevent_drain_all(int *count)
static void
zfs_zevent_insert(zevent_t *ev)
{
mutex_enter(&zevent_lock);
ASSERT(MUTEX_HELD(&zevent_lock));
list_insert_head(&zevent_list, ev);
if (zevent_len_cur >= zfs_zevent_len_max)
zfs_zevent_drain(list_tail(&zevent_list));
else
zevent_len_cur++;
mutex_exit(&zevent_lock);
}
/*
@ -528,8 +527,11 @@ zfs_zevent_post(nvlist_t *nvl, nvlist_t *detector, zevent_cb_t *cb)
ev->ev_nvl = nvl;
ev->ev_detector = detector;
ev->ev_cb = cb;
mutex_enter(&zevent_lock);
zfs_zevent_insert(ev);
cv_broadcast(&zevent_cv);
mutex_exit(&zevent_lock);
}
static int
@ -1520,9 +1522,10 @@ fm_fini(void)
int count;
zfs_zevent_drain_all(&count);
cv_broadcast(&zevent_cv);
mutex_enter(&zevent_lock);
cv_broadcast(&zevent_cv);
zevent_flags |= ZEVENT_SHUTDOWN;
while (zevent_waiters > 0) {
mutex_exit(&zevent_lock);