提交 404afe5b 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

atomic ops in fs

上级 8d8cc662
......@@ -264,9 +264,7 @@ iget(uint dev, uint inum)
struct inode*
idup(struct inode *ip)
{
acquire(&icache.lock);
ip->ref++;
release(&icache.lock);
__sync_fetch_and_add(&ip->ref, 1);
return ip;
}
......@@ -307,8 +305,9 @@ iunlock(struct inode *ip)
void
iput(struct inode *ip)
{
if(__sync_sub_and_fetch(&ip->ref, 1) == 0) {
acquire(&icache.lock);
if(ip->ref == 1 && ip->nlink == 0){
if (ip->nlink == 0){
// inode is no longer used: truncate and free inode.
if(ip->flags & I_BUSY)
panic("iput busy");
......@@ -326,8 +325,8 @@ iput(struct inode *ip)
ip->flags &= ~I_BUSY;
cv_wakeup(&ip->cv);
}
ip->ref--;
release(&icache.lock);
}
}
// Common idiom: unlock, then put.
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论