Move stream data from TCB to task group structure.

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5569 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-01-26 22:25:21 +00:00
parent d5582f35af
commit a71843ef91
23 changed files with 244 additions and 359 deletions

View File

@ -4036,3 +4036,5 @@
task group IN the child task's task group.
* fs/, sched/, include/nuttx/sched.h, and include/nutts/fs/fs.h:
Move file data from TCB to task group structure.
* libc/stdio/, sched/, include/nuttx/lib.h, and include/nutts/fs/fs.h:
Move stream data from TCB to task group structure.

View File

@ -75,7 +75,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
{
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct filelist *filelist;
#if CONFIG_NFILE_STREAMS > 0
FAR struct streamlist *streamlist;
#endif
int i;
#endif
@ -83,40 +87,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0
if (tcb->filelist)
filelist = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
FAR struct filelist *list = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
struct inode *inode = filelist->fl_files[i].f_inode;
if (inode)
{
struct inode *inode = list->fl_files[i].f_inode;
if (inode)
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
}
#endif
#if CONFIG_NFILE_STREAMS > 0
if (tcb->streams)
streamlist = tcb->group->tg_streamlist;
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
sdbg(" streamlist refcount=%d\n",
tcb->streams->sl_crefs);
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
struct file_struct *filep = &streamlist->sl_streams[i];
if (filep->fs_filedes >= 0)
{
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
#else
sdbg(" fd=%d\n", filep->fs_filedes);
sdbg(" fd=%d\n", filep->fs_filedes);
#endif
}
}
}
#endif

View File

@ -75,7 +75,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
{
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct filelist *filelist;
#if CONFIG_NFILE_STREAMS > 0
FAR struct streamlist *streamlist;
#endif
int i;
#endif
@ -83,40 +87,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0
if (tcb->filelist)
filelist = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
FAR struct filelist *list = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
struct inode *inode = filelist->fl_files[i].f_inode;
if (inode)
{
struct inode *inode = list->fl_files[i].f_inode;
if (inode)
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
}
#endif
#if CONFIG_NFILE_STREAMS > 0
if (tcb->streams)
streamlist = tcb->group->tg_streamlist;
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
sdbg(" streamlist refcount=%d\n",
tcb->streams->sl_crefs);
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
struct file_struct *filep = &streamlist->sl_streams[i];
if (filep->fs_filedes >= 0)
{
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
#else
sdbg(" fd=%d\n", filep->fs_filedes);
sdbg(" fd=%d\n", filep->fs_filedes);
#endif
}
}
}
#endif

View File

@ -75,7 +75,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
{
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct filelist *filelist;
#if CONFIG_NFILE_STREAMS > 0
FAR struct streamlist *streamlist;
#endif
int i;
#endif
@ -83,40 +87,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0
if (tcb->filelist)
filelist = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
FAR struct filelist *list = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
struct inode *inode = filelist->fl_files[i].f_inode;
if (inode)
{
struct inode *inode = list->fl_files[i].f_inode;
if (inode)
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
}
#endif
#if CONFIG_NFILE_STREAMS > 0
if (tcb->streams)
streamlist = tcb->group->tg_streamlist;
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
sdbg(" streamlist refcount=%d\n",
tcb->streams->sl_crefs);
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
struct file_struct *filep = &streamlist->sl_streams[i];
if (filep->fs_filedes >= 0)
{
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
#else
sdbg(" fd=%d\n", filep->fs_filedes);
sdbg(" fd=%d\n", filep->fs_filedes);
#endif
}
}
}
#endif

View File

@ -77,7 +77,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
{
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct filelist *filelist;
#if CONFIG_NFILE_STREAMS > 0
FAR struct streamlist *streamlist;
#endif
int i;
#endif
@ -85,40 +89,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0
if (tcb->filelist)
filelist = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
FAR struct filelist *list = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
struct inode *inode = filelist->fl_files[i].f_inode;
if (inode)
{
struct inode *inode = list->fl_files[i].f_inode;
if (inode)
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
}
#endif
#if CONFIG_NFILE_STREAMS > 0
if (tcb->streams)
streamlist = tcb->group->tg_streamlist;
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
sdbg(" streamlist refcount=%d\n",
tcb->streams->sl_crefs);
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
struct file_struct *filep = &streamlist->sl_streams[i];
if (filep->fs_filedes >= 0)
{
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
#else
sdbg(" fd=%d\n", filep->fs_filedes);
sdbg(" fd=%d\n", filep->fs_filedes);
#endif
}
}
}
#endif

View File

@ -76,7 +76,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
{
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct filelist *filelist;
#if CONFIG_NFILE_STREAMS > 0
FAR struct streamlist *streamlist;
#endif
int i;
#endif
@ -84,40 +88,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0
if (tcb->filelist)
filelist = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
FAR struct filelist *list = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
struct inode *inode = filelist->fl_files[i].f_inode;
if (inode)
{
struct inode *inode = list->fl_files[i].f_inode;
if (inode)
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
}
#endif
#if CONFIG_NFILE_STREAMS > 0
if (tcb->streams)
streamlist = tcb->group->tg_streamlist;
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
sdbg(" streamlist refcount=%d\n",
tcb->streams->sl_crefs);
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
struct file_struct *filep = &streamlist->sl_streams[i];
if (filep->fs_filedes >= 0)
{
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
#else
sdbg(" fd=%d\n", filep->fs_filedes);
sdbg(" fd=%d\n", filep->fs_filedes);
#endif
}
}
}
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* common/up_exit.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -75,7 +75,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
{
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct filelist *filelist;
#if CONFIG_NFILE_STREAMS > 0
FAR struct streamlist *streamlist;
#endif
int i;
#endif
@ -83,40 +87,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0
if (tcb->filelist)
filelist = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
FAR struct filelist *list = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
struct inode *inode = filelist->fl_files[i].f_inode;
if (inode)
{
struct inode *inode = list->fl_files[i].f_inode;
if (inode)
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
}
#endif
#if CONFIG_NFILE_STREAMS > 0
if (tcb->streams)
streamlist = tcb->group->tg_streamlist;
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
sdbg(" streamlist refcount=%d\n",
tcb->streams->sl_crefs);
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
struct file_struct *filep = &streamlist->sl_streams[i];
if (filep->fs_filedes >= 0)
{
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
#else
sdbg(" fd=%d\n", filep->fs_filedes);
sdbg(" fd=%d\n", filep->fs_filedes);
#endif
}
}
}
#endif

View File

@ -77,7 +77,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
{
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct filelist *filelist;
#if CONFIG_NFILE_STREAMS > 0
FAR struct streamlist *streamlist;
#endif
int i;
#endif
@ -85,40 +89,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
lldbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0
if (tcb->filelist)
filelist = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
FAR struct filelist *list = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
struct inode *inode = filelist->fl_files[i].f_inode;
if (inode)
{
struct inode *inode = list->fl_files[i].f_inode;
if (inode)
{
lldbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
lldbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
}
#endif
#if CONFIG_NFILE_STREAMS > 0
if (tcb->streams)
streamlist = tcb->group->tg_streamlist;
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
lldbg(" streamlist refcount=%d\n",
tcb->streams->sl_crefs);
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
struct file_struct *filep = &streamlist->sl_streams[i];
if (filep->fs_filedes >= 0)
{
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0
lldbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
lldbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
#else
lldbg(" fd=%d\n", filep->fs_filedes);
lldbg(" fd=%d\n", filep->fs_filedes);
#endif
}
}
}
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* common/up_exit.c
*
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -78,7 +78,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
{
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NFILE_STREAMS > 0
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct filelist *filelist;
#if CONFIG_NFILE_STREAMS > 0
FAR struct streamlist *streamlist;
#endif
int i;
#endif
@ -86,40 +90,32 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg)
lldbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0
if (tcb->filelist)
filelist = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
FAR struct filelist *list = tcb->group->tg_filelist;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
struct inode *inode = filelist->fl_files[i].f_inode;
if (inode)
{
struct inode *inode = list->fl_files[i].f_inode;
if (inode)
{
lldbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
lldbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
}
#endif
#if CONFIG_NFILE_STREAMS > 0
if (tcb->streams)
streamlist = tcb->group->tg_streamlist;
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
lldbg(" streamlist refcount=%d\n",
tcb->streams->sl_crefs);
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
struct file_struct *filep = &streamlist->sl_streams[i];
if (filep->fs_filedes >= 0)
{
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0
lldbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
lldbg(" fd=%d nbytes=%d\n",
filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart);
#else
lldbg(" fd=%d\n", filep->fs_filedes);
lldbg(" fd=%d\n", filep->fs_filedes);
#endif
}
}
}
#endif

View File

@ -144,6 +144,7 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb)
{
tcb = sched_self();
}
DEBUGASSERT(tcb && tcb->group);
/* Verify that this is a valid file/socket descriptor and that the
* requested access can be support.
@ -191,9 +192,9 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb)
/* Get the stream list from the TCB */
slist = tcb->streams;
slist = &tcb->group->tg_streamlist;
/* Find an unallocated FILE structure in the stream list */
/* Find an unallocated FILE structure in the stream list */
ret = sem_wait(&slist->sl_sem);
if (ret != OK)

View File

@ -293,7 +293,6 @@ struct file_struct
struct streamlist
{
int sl_crefs; /* Reference count */
sem_t sl_sem; /* For thread safety */
struct file_struct sl_streams[CONFIG_NFILE_STREAMS];
};

View File

@ -2,7 +2,7 @@
* include/nuttx/lib.h
* Non-standard, internal APIs available in lib/.
*
* Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2012-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -67,11 +67,10 @@ extern "C" {
/* Functions contained in lib_init.c ****************************************/
EXTERN void weak_function lib_initialize(void);
void weak_function lib_initialize(void);
#if CONFIG_NFILE_STREAMS > 0
EXTERN FAR struct streamlist *lib_alloclist(void);
EXTERN void lib_addreflist(FAR struct streamlist *list);
EXTERN void lib_releaselist(FAR struct streamlist *list);
void lib_streaminit(FAR struct streamlist *list);
void lib_releaselist(FAR struct streamlist *list);
#endif
#undef EXTERN

View File

@ -81,6 +81,8 @@
# define HAVE_TASK_GROUP 1
# elif CONFIG_NFILE_DESCRIPTORS > 0
# define HAVE_TASK_GROUP 1
# elif CONFIG_NFILE_STREAMS > 0
# define HAVE_TASK_GROUP 1
# endif
#endif
@ -303,7 +305,10 @@ struct task_group_s
#endif
/* FILE streams ***************************************************************/
/* Not yet (see streamlist) */
#if CONFIG_NFILE_STREAMS > 0
struct streamlist tg_streamlist; /* Holds C buffered I/O info */
#endif /* CONFIG_NFILE_STREAMS */
/* Sockets ********************************************************************/
/* Not yet (see struct socketlist) */
@ -445,12 +450,6 @@ struct _TCB
int pterrno; /* Current per-thread errno */
/* File system support ********************************************************/
#if CONFIG_NFILE_STREAMS > 0
FAR struct streamlist *streams; /* Holds C buffered I/O info */
#endif
/* Network socket *************************************************************/
#if CONFIG_NSOCKET_DESCRIPTORS > 0

View File

@ -1,7 +1,7 @@
/************************************************************
* libc/misc/lib_init.c
*
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -76,69 +76,35 @@ void weak_const_function lib_initialize(void)
}
#if CONFIG_NFILE_STREAMS > 0
/* The following function is called when a new TCB is allocated. It
* creates the streamlist instance that is stored in the TCB.
/* The following function is called when a new task is allocated. It
* intializes the streamlist instance that is stored in the task group.
*/
FAR struct streamlist *lib_alloclist(void)
void lib_streaminit(FAR struct streamlist *list)
{
FAR struct streamlist *list;
list = (FAR struct streamlist*)lib_zalloc(sizeof(struct streamlist));
if (list)
{
int i;
int i;
/* Start with a reference count of one */
/* Initialize the list access mutex */
list->sl_crefs = 1;
(void)sem_init(&list->sl_sem, 0, 1);
/* Initialize the list access mutex */
/* Initialize each FILE structure */
(void)sem_init(&list->sl_sem, 0, 1);
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
/* Clear the IOB */
/* Initialize each FILE structure */
memset(&list->sl_streams[i], 0, sizeof(FILE));
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
/* Clear the IOB */
/* Indicate not opened */
memset(&list->sl_streams[i], 0, sizeof(FILE));
list->sl_streams[i].fs_filedes = -1;
/* Indicate not opened */
/* Initialize the stream semaphore to one to support one-at-
* a-time access to private data sets.
*/
list->sl_streams[i].fs_filedes = -1;
/* Initialize the stream semaphore to one to support one-at-
* a-time access to private data sets.
*/
lib_sem_initialize(&list->sl_streams[i]);
}
}
return list;
}
/* This function is called when a TCB is closed (such as with
* pthread_create(). It increases the reference count on the stream
* list.
*/
void lib_addreflist(FAR struct streamlist *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->sl_crefs++;
irqrestore(flags);
lib_sem_initialize(&list->sl_streams[i]);
}
}
@ -149,57 +115,33 @@ void lib_addreflist(FAR struct streamlist *list)
void lib_releaselist(FAR struct streamlist *list)
{
int crefs;
if (list)
#if CONFIG_STDIO_BUFFER_SIZE > 0
int i;
#endif
DEBUGASSERT(list);
/* Destroy the semaphore and release the filelist */
(void)sem_destroy(&list->sl_sem);
/* Release each stream in the list */
#if CONFIG_STDIO_BUFFER_SIZE > 0
for (i = 0; i < CONFIG_NFILE_STREAMS; 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.
*/
/* Destroy the semaphore that protects the IO buffer */
register irqstate_t flags = irqsave();
crefs = --(list->sl_crefs);
irqrestore(flags);
(void)sem_destroy(&list->sl_streams[i].fs_sem);
/* 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.
*/
/* Release the IO buffer */
if (crefs <= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0
int i;
if (list->sl_streams[i].fs_bufstart)
{
sched_free(list->sl_streams[i].fs_bufstart);
}
}
#endif
/* Destroy the semaphore and release the filelist */
(void)sem_destroy(&list->sl_sem);
/* Release each stream in the list */
#if CONFIG_STDIO_BUFFER_SIZE > 0
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
/* Destroy the semaphore that protects the IO buffer */
(void)sem_destroy(&list->sl_streams[i].fs_sem);
/* Release the IO buffer */
if (list->sl_streams[i].fs_bufstart)
{
sched_free(list->sl_streams[i].fs_bufstart);
}
}
#endif
/* Finally, release the list itself */
sched_free(list);
}
}
}
#endif /* CONFIG_NFILE_STREAMS */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* libc/stdio/lib_libflushall.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without

View File

@ -86,28 +86,11 @@ void group_leave(FAR _TCB *tcb);
FAR struct task_group_s *group_find(gid_t gid);
int group_addmember(FAR struct task_group_s *group, pid_t pid);
int group_removemember(FAR struct task_group_s *group, pid_t pid);
#else
# define group_find(gid) (NULL)
# define group_addmember(group,pid) (0)
# define group_removemember(group,pid) (1)
#endif
#ifndef CONFIG_DISABLE_SIGNALS
int group_signal(FAR struct task_group_s *group, FAR siginfo_t *info);
#else
# define group_signal(tcb,info) (0)
#endif
#else
# define group_allocate(tcb) (0)
# define group_initialize(tcb) (0)
# define group_bind(tcb) (0)
# define group_join(tcb) (0)
# define group_leave(tcb)
# define group_find(gid) (NULL)
# define group_addmember(group,pid) (0)
# define group_removemember(group,pid) (1)
# define group_signal(tcb,info) (0)
#endif /* HAVE_TASK_GROUP */
/* Parent/child data management */
@ -127,15 +110,13 @@ FAR struct child_status_s *group_removechild(FAR struct task_group_s *group,
pid_t pid);
void group_removechildren(FAR struct task_group_s *group);
/* File/network resources */
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
int group_releasefiles(FAR _TCB *tcb);
#else
# define group_releasefiles(t) (OK)
#endif
#endif /* CONFIG_SCHED_CHILD_STATUS */
#endif /* CONFIG_SCHED_HAVE_PARENT */
/* File/network resources */
#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
int group_releasefiles(FAR _TCB *tcb);
#endif
#endif /* __SCHED_GROUP_INERNAL_H */

View File

@ -165,6 +165,7 @@ static inline void group_release(FAR _TCB *tcb,
env_release(tcb);
#endif
#ifdef HAVE_GROUP_MEMBERS
/* Remove the group from the list of groups */
group_remove(group);
@ -176,6 +177,7 @@ static inline void group_release(FAR _TCB *tcb,
sched_free(group->tg_members);
group->tg_members = NULL;
}
#endif
/* Release the group container itself */

View File

@ -80,7 +80,9 @@ int group_releasefiles(_TCB *tcb)
#if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct task_group_s *group = tcb->group;
DEBUGASSERT(group);
#endif
#if CONFIG_NFILE_DESCRIPTORS > 0
/* Free resources used by the file descriptor list */
files_releaselist(&group->tg_filelist);
@ -88,11 +90,8 @@ int group_releasefiles(_TCB *tcb)
#if CONFIG_NFILE_STREAMS > 0
/* Free the stream list */
if (tcb->streams)
{
lib_releaselist(tcb->streams);
tcb->streams = NULL;
}
lib_releaselist(&group->tg_streamlist);
#endif /* CONFIG_NFILE_STREAMS */
#endif /* CONFIG_NFILE_DESCRIPTORS */

View File

@ -1,7 +1,7 @@
/************************************************************************
* sched/sched_getfiles.c
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched_getstreams.c
*
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2008, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -70,7 +70,10 @@
FAR struct streamlist *sched_getstreams(void)
{
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
return rtcb->streams;
FAR struct task_group_s *group = rtcb->group;
DEBUGASSERT(group);
return &group->tg_streamlist;
}
#endif /* CONFIG_NFILE_DESCRIPTORS && CONFIG_NFILE_STREAMS */

View File

@ -77,8 +77,6 @@
int sched_setuppthreadfiles(FAR _TCB *tcb)
{
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
#if CONFIG_NSOCKET_DESCRIPTORS > 0
/* The child thread inherits the parent socket descriptors */
@ -87,13 +85,6 @@ int sched_setuppthreadfiles(FAR _TCB *tcb)
#endif /* CONFIG_NSOCKET_DESCRIPTORS */
#if CONFIG_NFILE_STREAMS > 0
/* The child thread inherits the parent streams */
tcb->streams = rtcb->streams;
lib_addreflist(tcb->streams);
#endif /* CONFIG_NFILE_STREAMS */
return OK;
}

View File

@ -72,24 +72,23 @@
int sched_setupstreams(FAR _TCB *tcb)
{
/* Allocate file streams for the TCB */
DEBUGASSERT(tcb && tcb->group);
tcb->streams = lib_alloclist();
if (tcb->streams)
{
/* fdopen to get the stdin, stdout and stderr streams.
* The following logic depends on the fact that the library
* layer will allocate FILEs in order.
*
* fd = 0 is stdin (read-only)
* fd = 1 is stdout (write-only, append)
* fd = 2 is stderr (write-only, append)
*/
/* Initialize file streams for the task group */
(void)fs_fdopen(0, O_RDONLY, tcb);
(void)fs_fdopen(1, O_WROK|O_CREAT, tcb);
(void)fs_fdopen(2, O_WROK|O_CREAT, tcb);
}
lib_streaminit(&tcb->group->tg_streamlist);
/* fdopen to get the stdin, stdout and stderr streams. The following logic
* depends on the fact that the library layer will allocate FILEs in order.
*
* fd = 0 is stdin (read-only)
* fd = 1 is stdout (write-only, append)
* fd = 2 is stderr (write-only, append)
*/
(void)fs_fdopen(0, O_RDONLY, tcb);
(void)fs_fdopen(1, O_WROK|O_CREAT, tcb);
(void)fs_fdopen(2, O_WROK|O_CREAT, tcb);
return OK;
}

View File

@ -543,7 +543,7 @@ void task_exithook(FAR _TCB *tcb, int status)
*/
#if CONFIG_NFILE_STREAMS > 0
(void)lib_flushall(tcb->streams);
(void)lib_flushall(&tcb->group->tg_streamlist);
#endif
/* Leave the task group. Perhaps discarding any un-reaped child