standardize usage of refcount
This commit is contained in:
parent
04b4889b31
commit
6b54ac354f
|
@ -90,7 +90,10 @@ struct dfs_dentry * dfs_dentry_ref(struct dfs_dentry *dentry)
|
|||
RT_ASSERT(dentry);
|
||||
|
||||
rt_atomic_add(&(dentry->ref_count), 1);
|
||||
|
||||
if (dentry->vnode)
|
||||
{
|
||||
rt_atomic_add(&(dentry->vnode->ref_count), 1); // TODO: dont add vnode's ref
|
||||
}
|
||||
return dentry;
|
||||
}
|
||||
|
||||
|
@ -98,17 +101,12 @@ struct dfs_dentry *dfs_dentry_unref(struct dfs_dentry *dentry)
|
|||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
|
||||
RT_ASSERT(dentry);
|
||||
RT_ASSERT(dentry && (dentry->flags & DENTRY_IS_ALLOCED));
|
||||
|
||||
ret = dfs_file_lock();
|
||||
if (ret == RT_EOK)
|
||||
{
|
||||
if (dentry->flags & DENTRY_IS_ALLOCED)
|
||||
{
|
||||
rt_atomic_sub(&(dentry->ref_count), 1);
|
||||
}
|
||||
|
||||
if (rt_atomic_load(&(dentry->ref_count)) == 0)
|
||||
if (rt_atomic_dec_and_test(&(dentry->ref_count)))
|
||||
{
|
||||
DLOG(msg, "dentry", "dentry", DLOG_MSG, "free dentry, ref_count=0");
|
||||
if (dentry->flags & DENTRY_IS_ADDHASH)
|
||||
|
|
|
@ -201,6 +201,14 @@ void dfs_file_deinit(struct dfs_file *file)
|
|||
{
|
||||
RT_ASSERT(file);
|
||||
|
||||
if (file->fops && file->fops->close)
|
||||
{
|
||||
if (file->fops->close(file) != RT_EOK)
|
||||
{
|
||||
LOG_E("file %p close error", file);
|
||||
}
|
||||
}
|
||||
|
||||
rt_mutex_detach(&file->pos_lock);
|
||||
|
||||
if (file->dentry)
|
||||
|
@ -210,7 +218,7 @@ void dfs_file_deinit(struct dfs_file *file)
|
|||
|
||||
if (file->vnode)
|
||||
{
|
||||
dfs_vnode_unref(file->vnode);
|
||||
//dfs_vnode_unref(file->vnode);
|
||||
}
|
||||
|
||||
if (file->mmap_context)
|
||||
|
|
|
@ -233,11 +233,10 @@ struct dfs_mnt *dfs_mnt_lookup(const char *fullpath)
|
|||
|
||||
struct dfs_mnt* dfs_mnt_ref(struct dfs_mnt* mnt)
|
||||
{
|
||||
if (mnt)
|
||||
{
|
||||
rt_atomic_add(&(mnt->ref_count), 1);
|
||||
DLOG(note, "mnt", "mnt(%s),ref_count=%d", mnt->fs_ops->name, rt_atomic_load(&(mnt->ref_count)));
|
||||
}
|
||||
RT_ASSERT(mnt);
|
||||
|
||||
rt_atomic_add(&(mnt->ref_count), 1);
|
||||
DLOG(note, "mnt", "mnt(%s),ref_count=%d", mnt->fs_ops->name, rt_atomic_load(&(mnt->ref_count)));
|
||||
|
||||
return mnt;
|
||||
}
|
||||
|
@ -248,9 +247,7 @@ int dfs_mnt_unref(struct dfs_mnt* mnt)
|
|||
|
||||
if (mnt)
|
||||
{
|
||||
rt_atomic_sub(&(mnt->ref_count), 1);
|
||||
|
||||
if (rt_atomic_load(&(mnt->ref_count)) == 0)
|
||||
if (rt_atomic_dec_and_test(&(mnt->ref_count)))
|
||||
{
|
||||
dfs_lock();
|
||||
|
||||
|
|
|
@ -721,9 +721,7 @@ static void dfs_page_unref(struct dfs_page *page)
|
|||
|
||||
dfs_aspace_lock(aspace);
|
||||
|
||||
rt_atomic_sub(&(page->ref_count), 1);
|
||||
|
||||
if (rt_atomic_load(&(page->ref_count)) == 0)
|
||||
if (rt_atomic_dec_and_test(&(page->ref_count)))
|
||||
{
|
||||
dfs_page_unmap(page);
|
||||
|
||||
|
|
Loading…
Reference in New Issue