diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index e3d7b60ceb..42cd054759 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -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) { diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index d9aa023b83..1ef5dba359 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -49,6 +49,7 @@ #include #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -491,6 +492,7 @@ struct file struct filelist { + spinlock_t fl_lock; /* Manage access to the file list */ uint8_t fl_rows; /* The number of rows of fl_files array */ uint8_t fl_crefs; /* The references to filelist */ FAR struct file **fl_files; /* The pointer of two layer file descriptors array */