- 论坛徽章:
- 0
|
下面分别是4.4BSD-Lite2和FreeBSD6.0的vrele()函数,单从这个函数来看,还是NetBSD要传统一点。。。
4.4BSD-Lite2
- /*
- * Vnode release.
- * If count drops to zero, call inactive routine and return to freelist.
- */
- void
- vrele(vp)
- struct vnode *vp;
- {
- struct proc *p = curproc; /* XXX */
- #ifdef DIAGNOSTIC
- if (vp == NULL)
- panic("vrele: null vp");
- #endif
- simple_lock(&vp->v_interlock);
- vp->v_usecount--;
- if (vp->v_usecount > 0) {
- simple_unlock(&vp->v_interlock);
- return;
- }
- #ifdef DIAGNOSTIC
- if (vp->v_usecount < 0 || vp->v_writecount != 0) {
- vprint("vrele: bad ref count", vp);
- panic("vrele: ref cnt");
- }
- #endif
- /*
- * insert at tail of LRU list
- */
- simple_lock(&vnode_free_list_slock);
- TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
- simple_unlock(&vnode_free_list_slock);
- if (vn_lock(vp, LK_EXCLUSIVE | LK_INTERLOCK, p) == 0)
- VOP_INACTIVE(vp, p);
- }
复制代码
FreeBSD6.0
- /*
- * Vnode put/release.
- * If count drops to zero, call inactive routine and return to freelist.
- */
- void
- vrele(vp)
- struct vnode *vp;
- {
- struct thread *td = curthread; /* XXX */
- KASSERT(vp != NULL, ("vrele: null vp"));
- VI_LOCK(vp);
- /* Skip this v_writecount check if we're going to panic below. */
- VNASSERT(vp->v_writecount < vp->v_usecount || vp->v_usecount < 1, vp,
- ("vrele: missed vn_close"));
- if (vp->v_usecount > 1 || ((vp->v_iflag & VI_DOINGINACT) &&
- vp->v_usecount == 1)) {
- v_decr_usecount(vp);
- return;
- }
- if (vp->v_usecount != 1) {
- #ifdef DIAGNOSTIC
- vprint("vrele: negative ref count", vp);
- #endif
- VI_UNLOCK(vp);
- panic("vrele: negative ref cnt");
- }
- /*
- * We want to hold the vnode until the inactive finishes to
- * prevent vgone() races. We drop the use count here and the
- * hold count below when we're done.
- */
- v_decr_useonly(vp);
- /*
- * We must call VOP_INACTIVE with the node locked. Mark
- * as VI_DOINGINACT to avoid recursion.
- */
- if (vn_lock(vp, LK_EXCLUSIVE | LK_INTERLOCK, td) == 0) {
- VI_LOCK(vp);
- vinactive(vp, td);
- VOP_UNLOCK(vp, 0, td);
- } else
- VI_LOCK(vp);
- vdropl(vp);
- }
复制代码 |
|