Move file data from TCB to task group

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5567 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2013-01-26 20:17:29 +00:00
parent a1aa13f628
commit 5b6482a22b
22 changed files with 297 additions and 345 deletions
+5 -3
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/fs_fdopen.c
*
* Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -68,9 +68,11 @@ static inline int fs_checkfd(FAR _TCB *tcb, int fd, int oflags)
FAR struct filelist *flist;
FAR struct inode *inode;
/* Get the file list from the TCB */
DEBUGASSERT(tcb && tcb->group);
flist = tcb->filelist;
/* Get the file list from the task group */
flist = &tcb->group->tg_filelist;
/* Get the inode associated with the file descriptor. This should
* normally be the case if fd >= 0. But not in the case where the
+21 -84
View File
@@ -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 */
DEBUGASSERT(list);
list->fl_crefs = 1;
/* Initialize the list access mutex */
/* Initialize the list access mutex */
(void)sem_init(&list->fl_sem, 0, 1);
}
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)
int i;
DEBUGASSERT(list);
/* 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.
*/
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
/* 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;
/* 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
*/
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
(void)_files_close(&list->fl_files[i]);
}
/* Destroy the semaphore and release the filelist */
(void)sem_destroy(&list->fl_sem);
sched_free(list);
}
(void)_files_close(&list->fl_files[i]);
}
return OK;
/* Destroy the semaphore */
(void)sem_destroy(&list->fl_sem);
}
/****************************************************************************