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

atomic ops in fs

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