Change asserts with side effects into panics

This commit is contained in:
Thomas Veerman 2011-12-09 14:46:10 +00:00
parent 706873142e
commit 5cbbfc69e7
5 changed files with 44 additions and 20 deletions

View file

@ -262,7 +262,10 @@ tll_access_t locktype;
org_m_in = m_in;
org_fp = fp;
org_self = self;
assert(mutex_lock(&filp->filp_lock) == 0);
if (mutex_lock(&filp->filp_lock) != 0)
panic("unable to obtain lock on filp");
m_in = org_m_in;
fp = org_fp;
self = org_self;
@ -292,7 +295,8 @@ struct filp *filp;
}
filp->filp_softlock = NULL;
assert(mutex_unlock(&filp->filp_lock) == 0);
if (mutex_unlock(&filp->filp_lock) != 0)
panic("unable to release lock on filp");
}
/*===========================================================================*
@ -321,8 +325,10 @@ struct filp *filp2;
filp1->filp_softlock = NULL;
filp2->filp_softlock = NULL;
assert(mutex_unlock(&filp2->filp_lock) == 0);
assert(mutex_unlock(&filp1->filp_lock) == 0);
if (mutex_unlock(&filp2->filp_lock) != 0)
panic("unable to release filp lock on filp2");
if (mutex_unlock(&filp1->filp_lock) != 0)
panic("unable to release filp lock on filp1");
}
/*===========================================================================*

View file

@ -564,7 +564,8 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
/* Initialize event resources for boot procs and locks for all procs */
for (rfp = &fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) {
assert(mutex_init(&rfp->fp_lock, NULL) == 0);
if (mutex_init(&rfp->fp_lock, NULL) != 0)
panic("unable to initialize fproc lock");
#if LOCK_DEBUG
rfp->fp_vp_rdlocks = 0;
rfp->fp_vmnt_rdlocks = 0;
@ -636,7 +637,8 @@ PUBLIC void lock_proc(struct fproc *rfp, int force_lock)
org_m_in = m_in;
org_fp = fp;
org_self = self;
assert(mutex_lock(&rfp->fp_lock) == 0);
if (mutex_lock(&rfp->fp_lock) != 0)
panic("unable to lock fproc lock");
m_in = org_m_in;
fp = org_fp;
self = org_self;

View file

@ -559,8 +559,10 @@ struct fproc *rfp;
put_vnode(dir_vp);
dir_vp = dir_vp->v_vmnt->m_mounted_on;
dir_vmp = dir_vp->v_vmnt;
assert(lock_vmnt(dir_vmp, VMNT_READ) == OK);
assert(lock_vnode(dir_vp, VNODE_READ) == OK);
if (lock_vmnt(dir_vmp, VMNT_READ) != OK)
panic("failed to lock vmnt");
if (lock_vnode(dir_vp, VNODE_READ) != OK)
panic("failed to lock vnode");
dup_vnode(dir_vp);
}

View file

@ -49,7 +49,10 @@ PUBLIC void lock_bsf(void)
org_m_in = m_in;
org_fp = fp;
org_self = self;
assert(mutex_lock(&bsf_lock) == 0);
if (mutex_lock(&bsf_lock) != 0)
panic("unable to lock block special file lock");
m_in = org_m_in;
fp = org_fp;
self = org_self;
@ -60,7 +63,8 @@ PUBLIC void lock_bsf(void)
*===========================================================================*/
PUBLIC void unlock_bsf(void)
{
assert(mutex_unlock(&bsf_lock) == 0);
if (mutex_unlock(&bsf_lock) != 0)
panic("failed to unlock block special file lock");
}
/*===========================================================================*

View file

@ -33,7 +33,8 @@ PUBLIC void worker_init(struct worker_thread *wp)
/* Initialize worker thread */
if (!init) {
threads_init();
assert(mthread_attr_init(&tattr) == 0);
if (mthread_attr_init(&tattr) != 0)
panic("failed to initialize attribute");
if (mthread_attr_setstacksize(&tattr, TH_STACKSIZE) != 0)
panic("couldn't set default thread stack size");
if (mthread_attr_setdetachstate(&tattr, MTHREAD_CREATE_DETACHED) != 0)
@ -46,9 +47,12 @@ PUBLIC void worker_init(struct worker_thread *wp)
wp->w_job.j_func = NULL; /* Mark not in use */
wp->w_next = NULL;
assert(mutex_init(&wp->w_event_mutex, NULL) == 0);
assert(cond_init(&wp->w_event, NULL) == 0);
assert(mthread_create(&wp->w_tid, &tattr, worker_main, (void *) wp) == 0);
if (mutex_init(&wp->w_event_mutex, NULL) != 0)
panic("failed to initialize mutex");
if (cond_init(&wp->w_event, NULL) != 0)
panic("failed to initialize conditional variable");
if (mthread_create(&wp->w_tid, &tattr, worker_main, (void *) wp) != 0)
panic("unable to start thread");
yield();
}
@ -247,9 +251,12 @@ PRIVATE void worker_sleep(struct worker_thread *worker)
{
ASSERTW(worker);
assert(self == worker);
assert(mutex_lock(&worker->w_event_mutex) == 0);
assert(cond_wait(&worker->w_event, &worker->w_event_mutex) == 0);
assert(mutex_unlock(&worker->w_event_mutex) == 0);
if (mutex_lock(&worker->w_event_mutex) != 0)
panic("unable to lock event mutex");
if (cond_wait(&worker->w_event, &worker->w_event_mutex) != 0)
panic("could not wait on conditional variable");
if (mutex_unlock(&worker->w_event_mutex) != 0)
panic("unable to unlock event mutex");
self = worker;
}
@ -260,9 +267,12 @@ PRIVATE void worker_wake(struct worker_thread *worker)
{
/* Signal a worker to wake up */
ASSERTW(worker);
assert(mutex_lock(&worker->w_event_mutex) == 0);
assert(cond_signal(&worker->w_event) == 0);
assert(mutex_unlock(&worker->w_event_mutex) == 0);
if (mutex_lock(&worker->w_event_mutex) != 0)
panic("unable to lock event mutex");
if (cond_signal(&worker->w_event) != 0)
panic("unable to signal conditional variable");
if (mutex_unlock(&worker->w_event_mutex) != 0)
panic("unable to unlock event mutex");
}
/*===========================================================================*