xiaoxiang781216 commented on code in PR #15163: URL: https://github.com/apache/nuttx/pull/15163#discussion_r1884080425
########## fs/inode/fs_files.c: ########## @@ -76,33 +76,40 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list, filep = &list->fl_files[l1][l2]; #ifdef CONFIG_FS_REFCOUNT + int32_t refs = 0; + if (filep->f_inode != NULL) { /* When the reference count is zero but the inode has not yet been * released, At this point we should return a null pointer */ - if (filep->f_refs == 0) - { - filep = NULL; - } - else + do { - filep->f_refs++; + refs = atomic_read(&filep->f_refs); Review Comment: move before line 89 ########## fs/inode/fs_files.c: ########## @@ -76,33 +76,40 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list, Review Comment: let's create a new patch to remove fl_lock ########## fs/inode/fs_files.c: ########## @@ -76,33 +76,40 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list, filep = &list->fl_files[l1][l2]; #ifdef CONFIG_FS_REFCOUNT + int32_t refs = 0; + if (filep->f_inode != NULL) { /* When the reference count is zero but the inode has not yet been * released, At this point we should return a null pointer */ - if (filep->f_refs == 0) - { - filep = NULL; - } - else + do { - filep->f_refs++; + refs = atomic_read(&filep->f_refs); + if (refs == 0) + { + filep = NULL; + break; + } } + while (!atomic_try_cmpxchg(&filep->f_refs, &refs, refs + 1)); } else if (new == NULL) { filep = NULL; } - else if (filep->f_refs) Review Comment: ``` else if (atomic_fetch_add(&filep->f_refs, 1) == 1) { atomic_fetch_add(&filep->f_refs, 1); *new = true; } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org