Improve assertions slightly. When awakening assert that the CV has not

been destroyed.
This commit is contained in:
ad 2007-08-01 20:30:38 +00:00
parent 0a057fefdd
commit b5dd2da738
1 changed files with 15 additions and 9 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_condvar.c,v 1.9 2007/07/09 21:10:51 ad Exp $ */
/* $NetBSD: kern_condvar.c,v 1.10 2007/08/01 20:30:38 ad Exp $ */
/*-
* Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.9 2007/07/09 21:10:51 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.10 2007/08/01 20:30:38 ad Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@ -57,7 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.9 2007/07/09 21:10:51 ad Exp $");
static void cv_unsleep(lwp_t *);
static void cv_changepri(lwp_t *, pri_t);
syncobj_t cv_syncobj = {
static syncobj_t cv_syncobj = {
SOBJ_SLEEPQ_SORTED,
cv_unsleep,
cv_changepri,
@ -65,6 +65,8 @@ syncobj_t cv_syncobj = {
syncobj_noowner,
};
static const char deadcv[] = "deadcv";
/*
* cv_init:
*
@ -90,8 +92,9 @@ cv_destroy(kcondvar_t *cv)
{
#ifdef DIAGNOSTIC
KASSERT(cv->cv_waiters == 0 && cv->cv_wmesg != NULL);
cv->cv_wmesg = NULL;
KASSERT(cv->cv_wmesg != deadcv && cv->cv_wmesg != NULL);
KASSERT(cv->cv_waiters == 0);
cv->cv_wmesg = deadcv;
#endif
}
@ -106,7 +109,7 @@ cv_enter(kcondvar_t *cv, kmutex_t *mtx, lwp_t *l)
{
sleepq_t *sq;
KASSERT(cv->cv_wmesg != NULL);
KASSERT(cv->cv_wmesg != deadcv && cv->cv_wmesg != NULL);
KASSERT((l->l_flag & LW_INTR) == 0);
l->l_cv_signalled = 0;
@ -137,6 +140,8 @@ cv_exit(kcondvar_t *cv, kmutex_t *mtx, lwp_t *l, const int error)
if (__predict_false(error != 0) && l->l_cv_signalled != 0)
cv_signal(cv);
KASSERT(cv->cv_wmesg != deadcv && cv->cv_wmesg != NULL);
return error;
}
@ -151,13 +156,14 @@ cv_exit(kcondvar_t *cv, kmutex_t *mtx, lwp_t *l, const int error)
static void
cv_unsleep(lwp_t *l)
{
uintptr_t addr;
kcondvar_t *cv;
KASSERT(l->l_wchan != NULL);
KASSERT(lwp_locked(l, l->l_sleepq->sq_mutex));
addr = (uintptr_t)l->l_wchan;
((kcondvar_t *)addr)->cv_waiters--;
cv = (kcondvar_t *)(uintptr_t)l->l_wchan;
KASSERT(cv->cv_wmesg != deadcv && cv->cv_wmesg != NULL);
cv->cv_waiters--;
sleepq_unsleep(l);
}