PSEUDOCODE
struct vopnode {
int von_flag;
/*
* Other file system specific data.
*/
...;
};
#define VON_LOCKED 1
#define VON_WANTED 2
#define VTOVON(vp) ((struct vopnode *) (vp)->v_data)
int
vop_lock(struct vnode *vp)
{
struct vopnode* vop;
start:
while (vp->v_flag & VXLOCK) {
vp->v_flag |= VXWANT;
tsleep((caddr_t)vp, PINOD, "voplk1", 0);
}
if (vp->v_tag == VT_NON)
return ENOENT;
vop = VTOVON(vp);
if (vop->von_flag & VON_LOCKED) {
vop->von_flag |= VON_WANTED;
tsleep((caddr_t) vop, PINOD, "voplk2", 0);
goto start;
}
vop->von_flag |= VON_LOCKED;
return 0;
}
int
vop_unlock(struct vnode *vp)
{
struct vopnode *vop = VTOVON(vp);
if ((vop->von_flag & VON_LOCKED) == 0) {
panic("vop_unlock not locked");
}
vop->von_flag &= ~VON_LOCKED;
if (vop->von_flag & VON_WANTED) {
vop->von_flag &= ~VON_WANTED;
wakeup((caddr_t) vop);
}
return 0;
}
int
vop_islocked(struct vnode *vp)
{
struct vopnode *vop = VTOVON(vp);
if (vop->von_flag & VON_LOCKED)
return 1;
else
return 0;
}
SEE ALSO
vnode(9)
AUTHORS