From: Thomas Veerman Date: Fri, 9 Dec 2011 14:46:10 +0000 (+0000) Subject: Change asserts with side effects into panics X-Git-Tag: v3.2.0~189 X-Git-Url: http://zhaoyanbai.com/repos/icons/debian/static/datamaps.china.min.js?a=commitdiff_plain;h=5cbbfc69e739cc6d40b96c8022a5177d07d0cdc0;p=minix.git Change asserts with side effects into panics --- diff --git a/servers/avfs/filedes.c b/servers/avfs/filedes.c index c6482d2e8..83a432c1b 100644 --- a/servers/avfs/filedes.c +++ b/servers/avfs/filedes.c @@ -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"); } /*===========================================================================* diff --git a/servers/avfs/main.c b/servers/avfs/main.c index ecf9c639f..6426202c0 100644 --- a/servers/avfs/main.c +++ b/servers/avfs/main.c @@ -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; diff --git a/servers/avfs/path.c b/servers/avfs/path.c index 9ed1540f8..80fe01889 100644 --- a/servers/avfs/path.c +++ b/servers/avfs/path.c @@ -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); } diff --git a/servers/avfs/read.c b/servers/avfs/read.c index 46ee497cb..fd97cc37d 100644 --- a/servers/avfs/read.c +++ b/servers/avfs/read.c @@ -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"); } /*===========================================================================* diff --git a/servers/avfs/worker.c b/servers/avfs/worker.c index f17989276..ba56e6b0d 100644 --- a/servers/avfs/worker.c +++ b/servers/avfs/worker.c @@ -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"); } /*===========================================================================*