File tree Expand file tree Collapse file tree 1 file changed +5
-13
lines changed Expand file tree Collapse file tree 1 file changed +5
-13
lines changed Original file line number Diff line number Diff line change @@ -76,17 +76,15 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
76
76
77
77
filep = & list -> fl_files [l1 ][l2 ];
78
78
#ifdef CONFIG_FS_REFCOUNT
79
- int32_t refs = 0 ;
80
-
81
79
if (filep -> f_inode != NULL )
82
80
{
83
81
/* When the reference count is zero but the inode has not yet been
84
82
* released, At this point we should return a null pointer
85
83
*/
86
84
85
+ int32_t refs = atomic_read (& filep -> f_refs );
87
86
do
88
87
{
89
- refs = atomic_read (& filep -> f_refs );
90
88
if (refs == 0 )
91
89
{
92
90
filep = NULL ;
@@ -99,18 +97,12 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
99
97
{
100
98
filep = NULL ;
101
99
}
102
- else
100
+ else if ( atomic_fetch_add ( & filep -> f_refs , 1 ) == 0 )
103
101
{
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;
113
104
}
105
+
114
106
#else
115
107
if (filep -> f_inode == NULL && new == NULL )
116
108
{
You can’t perform that action at this time.
0 commit comments