anchao commented on code in PR #11841:
URL: https://github.com/apache/nuttx/pull/11841#discussion_r1512137014
##########
fs/inode/fs_files.c:
##########
@@ -375,64 +394,54 @@ int file_allocate_from_tcb(FAR struct tcb_s *tcb, FAR
struct inode *inode,
int oflags, off_t pos, FAR void *priv, int minfd,
bool addref)
{
+ int i = minfd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
+ int j = minfd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
FAR struct filelist *list;
FAR struct file *filep;
+ irqstate_t flags;
int ret;
- int i;
- int j;
/* Get the file descriptor list. It should not be NULL in this context. */
list = nxsched_get_files_from_tcb(tcb);
- /* Calculate minfd whether is in list->fl_files.
- * if not, allocate a new filechunk.
- */
+ /* Find free file */
+
+ flags = spin_lock_irqsave(&list->fl_lock);
- i = minfd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
- if (i >= list->fl_rows)
+ for (; ; i++, j = 0)
{
- ret = files_extend(list, i + 1);
- if (ret < 0)
+ if (i >= list->fl_rows)
{
- return ret;
- }
- }
+ spin_unlock_irqrestore(&list->fl_lock, flags);
- /* Find free file */
+ ret = files_extend(list, i + 1);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ flags = spin_lock_irqsave(&list->fl_lock);
+ }
- j = minfd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
- do
- {
do
{
- filep = files_fget_by_index(list, i, j);
+ filep = &list->fl_files[i][j];
if (filep->f_inode == NULL)
{
+ filep->f_oflags = oflags;
+ filep->f_pos = pos;
+ filep->f_inode = inode;
Review Comment:
keep `filep->f_inode = inode;` here and move f_oflags/f_pos/f_priv assign
to line 445
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]