mirror of
https://github.com/apache/nuttx.git
synced 2025-12-12 05:34:38 +08:00
fs: use small lock to protect filelist
Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -72,7 +72,7 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
|
||||
FAR struct file *filep;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&list->fl_lock);
|
||||
|
||||
filep = &list->fl_files[l1][l2];
|
||||
#ifdef CONFIG_FS_REFCOUNT
|
||||
@@ -111,7 +111,7 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
|
||||
}
|
||||
#endif
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&list->fl_lock, flags);
|
||||
return filep;
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ static int files_extend(FAR struct filelist *list, size_t row)
|
||||
}
|
||||
while (++i < row);
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&list->fl_lock);
|
||||
|
||||
/* To avoid race condition, if the file list is updated by other threads
|
||||
* and list rows is greater or equal than temp list,
|
||||
@@ -174,7 +174,7 @@ static int files_extend(FAR struct filelist *list, size_t row)
|
||||
|
||||
if (orig_rows != list->fl_rows && list->fl_rows >= row)
|
||||
{
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&list->fl_lock, flags);
|
||||
|
||||
for (j = orig_rows; j < i; j++)
|
||||
{
|
||||
@@ -196,7 +196,7 @@ static int files_extend(FAR struct filelist *list, size_t row)
|
||||
list->fl_files = files;
|
||||
list->fl_rows = row;
|
||||
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&list->fl_lock, flags);
|
||||
|
||||
if (tmp != NULL && tmp != &list->fl_prefile)
|
||||
{
|
||||
@@ -371,6 +371,7 @@ void files_initlist(FAR struct filelist *list)
|
||||
list->fl_crefs = 1;
|
||||
list->fl_files = &list->fl_prefile;
|
||||
list->fl_prefile = list->fl_prefiles;
|
||||
spin_lock_init(&list->fl_lock);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -589,13 +590,13 @@ int file_allocate_from_tcb(FAR struct tcb_s *tcb, FAR struct inode *inode,
|
||||
|
||||
/* Find free file */
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&list->fl_lock);
|
||||
|
||||
for (; ; i++, j = 0)
|
||||
{
|
||||
if (i >= list->fl_rows)
|
||||
{
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&list->fl_lock, flags);
|
||||
|
||||
ret = files_extend(list, i + 1);
|
||||
if (ret < 0)
|
||||
@@ -603,7 +604,7 @@ int file_allocate_from_tcb(FAR struct tcb_s *tcb, FAR struct inode *inode,
|
||||
return ret;
|
||||
}
|
||||
|
||||
flags = spin_lock_irqsave(NULL);
|
||||
flags = spin_lock_irqsave(&list->fl_lock);
|
||||
}
|
||||
|
||||
do
|
||||
@@ -632,7 +633,7 @@ int file_allocate_from_tcb(FAR struct tcb_s *tcb, FAR struct inode *inode,
|
||||
}
|
||||
|
||||
found:
|
||||
spin_unlock_irqrestore(NULL, flags);
|
||||
spin_unlock_irqrestore(&list->fl_lock, flags);
|
||||
|
||||
if (addref)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user