aboutsummaryrefslogtreecommitdiff
path: root/nuttx/fs/fs_files.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/fs/fs_files.c')
-rw-r--r--nuttx/fs/fs_files.c101
1 files changed, 19 insertions, 82 deletions
diff --git a/nuttx/fs/fs_files.c b/nuttx/fs/fs_files.c
index 06addb1ef..c68ec7e73 100644
--- a/nuttx/fs/fs_files.c
+++ b/nuttx/fs/fs_files.c
@@ -155,56 +155,19 @@ void files_initialize(void)
}
/****************************************************************************
- * Name: files_alloclist
+ * Name: files_initlist
*
- * Description: Allocate a list of files for a new task
+ * Description: Initializes the list of files for a new task
*
****************************************************************************/
-FAR struct filelist *files_alloclist(void)
+void files_initlist(FAR struct filelist *list)
{
- FAR struct filelist *list;
- list = (FAR struct filelist*)kzalloc(sizeof(struct filelist));
- if (list)
- {
- /* Start with a reference count of one */
-
- list->fl_crefs = 1;
-
- /* Initialize the list access mutex */
+ DEBUGASSERT(list);
- (void)sem_init(&list->fl_sem, 0, 1);
- }
+ /* Initialize the list access mutex */
- return list;
-}
-
-/****************************************************************************
- * Name: files_addreflist
- *
- * Description:
- * Increase the reference count on a file list
- *
- ****************************************************************************/
-
-int files_addreflist(FAR struct filelist *list)
-{
- if (list)
- {
- /* Increment the reference count on the list.
- * NOTE: that we disable interrupts to do this
- * (vs. taking the list semaphore). We do this
- * because file cleanup operations often must be
- * done from the IDLE task which cannot wait
- * on semaphores.
- */
-
- register irqstate_t flags = irqsave();
- list->fl_crefs++;
- irqrestore(flags);
- }
-
- return OK;
+ (void)sem_init(&list->fl_sem, 0, 1);
}
/****************************************************************************
@@ -215,51 +178,25 @@ int files_addreflist(FAR struct filelist *list)
*
****************************************************************************/
-int files_releaselist(FAR struct filelist *list)
+void files_releaselist(FAR struct filelist *list)
{
- int crefs;
- if (list)
- {
- /* Decrement the reference count on the list.
- * NOTE: that we disable interrupts to do this
- * (vs. taking the list semaphore). We do this
- * because file cleanup operations often must be
- * done from the IDLE task which cannot wait
- * on semaphores.
- */
-
- register irqstate_t flags = irqsave();
- crefs = --(list->fl_crefs);
- irqrestore(flags);
-
- /* If the count decrements to zero, then there is no reference
- * to the structure and it should be deallocated. Since there
- * are references, it would be an error if any task still held
- * a reference to the list's semaphore.
- */
-
- if (crefs <= 0)
- {
- int i;
+ int i;
- /* Close each file descriptor .. Normally, you would need
- * take the list semaphore, but it is safe to ignore the
- * semaphore in this context because there are no references
- */
+ DEBUGASSERT(list);
- for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
- {
- (void)_files_close(&list->fl_files[i]);
- }
-
- /* Destroy the semaphore and release the filelist */
+ /* Close each file descriptor .. Normally, you would need take the list
+ * semaphore, but it is safe to ignore the semaphore in this context because
+ * there should not be any references in this context.
+ */
- (void)sem_destroy(&list->fl_sem);
- sched_free(list);
- }
+ for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
+ {
+ (void)_files_close(&list->fl_files[i]);
}
- return OK;
+ /* Destroy the semaphore */
+
+ (void)sem_destroy(&list->fl_sem);
}
/****************************************************************************