Skip to content

Commit 7036098

Browse files
hujun260anchao
authored andcommitted
fs: fix comment in apache#15163
Signed-off-by: hujun5 <[email protected]>
1 parent c7a0288 commit 7036098

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

fs/inode/fs_files.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,15 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
7676

7777
filep = &list->fl_files[l1][l2];
7878
#ifdef CONFIG_FS_REFCOUNT
79-
int32_t refs = 0;
80-
8179
if (filep->f_inode != NULL)
8280
{
8381
/* When the reference count is zero but the inode has not yet been
8482
* released, At this point we should return a null pointer
8583
*/
8684

85+
int32_t refs = atomic_read(&filep->f_refs);
8786
do
8887
{
89-
refs = atomic_read(&filep->f_refs);
9088
if (refs == 0)
9189
{
9290
filep = NULL;
@@ -99,18 +97,12 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
9997
{
10098
filep = NULL;
10199
}
102-
else
100+
else if (atomic_fetch_add(&filep->f_refs, 1) == 0)
103101
{
104-
do
105-
{
106-
if (atomic_cmpxchg(&filep->f_refs, &refs, 2))
107-
{
108-
*new = true;
109-
break;
110-
}
111-
}
112-
while (!atomic_try_cmpxchg(&filep->f_refs, &refs, refs + 1));
102+
atomic_fetch_add(&filep->f_refs, 1);
103+
*new = true;
113104
}
105+
114106
#else
115107
if (filep->f_inode == NULL && new == NULL)
116108
{

0 commit comments

Comments
 (0)