Move stream data from TCB to task group structure.

git-svn-id: http://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 3bec164b3a
commit b82c36961a
23 changed files with 244 additions and 359 deletions
+2
View File
@@ -4036,3 +4036,5 @@
task group IN the child task's task group. task group IN the child task's task group.
* fs/, sched/, include/nuttx/sched.h, and include/nutts/fs/fs.h: * fs/, sched/, include/nuttx/sched.h, and include/nutts/fs/fs.h:
Move file data from TCB to task group structure. 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.
+19 -23
View File
@@ -75,7 +75,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) 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; int i;
#endif #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); sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0 #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; struct inode *inode = filelist->fl_files[i].f_inode;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) if (inode)
{ {
struct inode *inode = list->fl_files[i].f_inode; sdbg(" fd=%d refcount=%d\n",
if (inode) i, inode->i_crefs);
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
} }
} }
#endif #endif
#if CONFIG_NFILE_STREAMS > 0 #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", struct file_struct *filep = &streamlist->sl_streams[i];
tcb->streams->sl_crefs); if (filep->fs_filedes >= 0)
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{ {
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0 #if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n", sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes, filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart); filep->fs_bufpos - filep->fs_bufstart);
#else #else
sdbg(" fd=%d\n", filep->fs_filedes); sdbg(" fd=%d\n", filep->fs_filedes);
#endif #endif
}
} }
} }
#endif #endif
+19 -23
View File
@@ -75,7 +75,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) 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; int i;
#endif #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); sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0 #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; struct inode *inode = filelist->fl_files[i].f_inode;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) if (inode)
{ {
struct inode *inode = list->fl_files[i].f_inode; sdbg(" fd=%d refcount=%d\n",
if (inode) i, inode->i_crefs);
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
} }
} }
#endif #endif
#if CONFIG_NFILE_STREAMS > 0 #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", struct file_struct *filep = &streamlist->sl_streams[i];
tcb->streams->sl_crefs); if (filep->fs_filedes >= 0)
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{ {
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0 #if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n", sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes, filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart); filep->fs_bufpos - filep->fs_bufstart);
#else #else
sdbg(" fd=%d\n", filep->fs_filedes); sdbg(" fd=%d\n", filep->fs_filedes);
#endif #endif
}
} }
} }
#endif #endif
+19 -23
View File
@@ -75,7 +75,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) 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; int i;
#endif #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); sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0 #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; struct inode *inode = filelist->fl_files[i].f_inode;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) if (inode)
{ {
struct inode *inode = list->fl_files[i].f_inode; sdbg(" fd=%d refcount=%d\n",
if (inode) i, inode->i_crefs);
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
} }
} }
#endif #endif
#if CONFIG_NFILE_STREAMS > 0 #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", struct file_struct *filep = &streamlist->sl_streams[i];
tcb->streams->sl_crefs); if (filep->fs_filedes >= 0)
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{ {
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0 #if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n", sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes, filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart); filep->fs_bufpos - filep->fs_bufstart);
#else #else
sdbg(" fd=%d\n", filep->fs_filedes); sdbg(" fd=%d\n", filep->fs_filedes);
#endif #endif
}
} }
} }
#endif #endif
+19 -23
View File
@@ -77,7 +77,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) 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; int i;
#endif #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); sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0 #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; struct inode *inode = filelist->fl_files[i].f_inode;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) if (inode)
{ {
struct inode *inode = list->fl_files[i].f_inode; sdbg(" fd=%d refcount=%d\n",
if (inode) i, inode->i_crefs);
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
} }
} }
#endif #endif
#if CONFIG_NFILE_STREAMS > 0 #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", struct file_struct *filep = &streamlist->sl_streams[i];
tcb->streams->sl_crefs); if (filep->fs_filedes >= 0)
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{ {
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0 #if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n", sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes, filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart); filep->fs_bufpos - filep->fs_bufstart);
#else #else
sdbg(" fd=%d\n", filep->fs_filedes); sdbg(" fd=%d\n", filep->fs_filedes);
#endif #endif
}
} }
} }
#endif #endif
+19 -23
View File
@@ -76,7 +76,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) 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; int i;
#endif #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); sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0 #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; struct inode *inode = filelist->fl_files[i].f_inode;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) if (inode)
{ {
struct inode *inode = list->fl_files[i].f_inode; sdbg(" fd=%d refcount=%d\n",
if (inode) i, inode->i_crefs);
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
} }
} }
#endif #endif
#if CONFIG_NFILE_STREAMS > 0 #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", struct file_struct *filep = &streamlist->sl_streams[i];
tcb->streams->sl_crefs); if (filep->fs_filedes >= 0)
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{ {
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0 #if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n", sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes, filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart); filep->fs_bufpos - filep->fs_bufstart);
#else #else
sdbg(" fd=%d\n", filep->fs_filedes); sdbg(" fd=%d\n", filep->fs_filedes);
#endif #endif
}
} }
} }
#endif #endif
+20 -24
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* common/up_exit.c * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -75,7 +75,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) 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; int i;
#endif #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); sdbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0 #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; struct inode *inode = filelist->fl_files[i].f_inode;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) if (inode)
{ {
struct inode *inode = list->fl_files[i].f_inode; sdbg(" fd=%d refcount=%d\n",
if (inode) i, inode->i_crefs);
{
sdbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
} }
} }
#endif #endif
#if CONFIG_NFILE_STREAMS > 0 #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", struct file_struct *filep = &streamlist->sl_streams[i];
tcb->streams->sl_crefs); if (filep->fs_filedes >= 0)
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{ {
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0 #if CONFIG_STDIO_BUFFER_SIZE > 0
sdbg(" fd=%d nbytes=%d\n", sdbg(" fd=%d nbytes=%d\n",
filep->fs_filedes, filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart); filep->fs_bufpos - filep->fs_bufstart);
#else #else
sdbg(" fd=%d\n", filep->fs_filedes); sdbg(" fd=%d\n", filep->fs_filedes);
#endif #endif
}
} }
} }
#endif #endif
+19 -23
View File
@@ -77,7 +77,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) 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; int i;
#endif #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); lldbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0 #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; struct inode *inode = filelist->fl_files[i].f_inode;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) if (inode)
{ {
struct inode *inode = list->fl_files[i].f_inode; lldbg(" fd=%d refcount=%d\n",
if (inode) i, inode->i_crefs);
{
lldbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
} }
} }
#endif #endif
#if CONFIG_NFILE_STREAMS > 0 #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", struct file_struct *filep = &streamlist->sl_streams[i];
tcb->streams->sl_crefs); if (filep->fs_filedes >= 0)
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{ {
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0 #if CONFIG_STDIO_BUFFER_SIZE > 0
lldbg(" fd=%d nbytes=%d\n", lldbg(" fd=%d nbytes=%d\n",
filep->fs_filedes, filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart); filep->fs_bufpos - filep->fs_bufstart);
#else #else
lldbg(" fd=%d\n", filep->fs_filedes); lldbg(" fd=%d\n", filep->fs_filedes);
#endif #endif
}
} }
} }
#endif #endif
+20 -24
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* common/up_exit.c * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -78,7 +78,11 @@
#if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG)
static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) 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; int i;
#endif #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); lldbg(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
#if CONFIG_NFILE_DESCRIPTORS > 0 #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; struct inode *inode = filelist->fl_files[i].f_inode;
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) if (inode)
{ {
struct inode *inode = list->fl_files[i].f_inode; lldbg(" fd=%d refcount=%d\n",
if (inode) i, inode->i_crefs);
{
lldbg(" fd=%d refcount=%d\n",
i, inode->i_crefs);
}
} }
} }
#endif #endif
#if CONFIG_NFILE_STREAMS > 0 #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", struct file_struct *filep = &streamlist->sl_streams[i];
tcb->streams->sl_crefs); if (filep->fs_filedes >= 0)
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{ {
struct file_struct *filep = &tcb->streams->sl_streams[i];
if (filep->fs_filedes >= 0)
{
#if CONFIG_STDIO_BUFFER_SIZE > 0 #if CONFIG_STDIO_BUFFER_SIZE > 0
lldbg(" fd=%d nbytes=%d\n", lldbg(" fd=%d nbytes=%d\n",
filep->fs_filedes, filep->fs_filedes,
filep->fs_bufpos - filep->fs_bufstart); filep->fs_bufpos - filep->fs_bufstart);
#else #else
lldbg(" fd=%d\n", filep->fs_filedes); lldbg(" fd=%d\n", filep->fs_filedes);
#endif #endif
}
} }
} }
#endif #endif
+3 -2
View File
@@ -144,6 +144,7 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb)
{ {
tcb = sched_self(); tcb = sched_self();
} }
DEBUGASSERT(tcb && tcb->group);
/* Verify that this is a valid file/socket descriptor and that the /* Verify that this is a valid file/socket descriptor and that the
* requested access can be support. * 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 */ /* 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); ret = sem_wait(&slist->sl_sem);
if (ret != OK) if (ret != OK)
-1
View File
@@ -293,7 +293,6 @@ struct file_struct
struct streamlist struct streamlist
{ {
int sl_crefs; /* Reference count */
sem_t sl_sem; /* For thread safety */ sem_t sl_sem; /* For thread safety */
struct file_struct sl_streams[CONFIG_NFILE_STREAMS]; struct file_struct sl_streams[CONFIG_NFILE_STREAMS];
}; };
+4 -5
View File
@@ -2,7 +2,7 @@
* include/nuttx/lib.h * include/nuttx/lib.h
* Non-standard, internal APIs available in lib/. * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -67,11 +67,10 @@ extern "C" {
/* Functions contained in lib_init.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 #if CONFIG_NFILE_STREAMS > 0
EXTERN FAR struct streamlist *lib_alloclist(void); void lib_streaminit(FAR struct streamlist *list);
EXTERN void lib_addreflist(FAR struct streamlist *list); void lib_releaselist(FAR struct streamlist *list);
EXTERN void lib_releaselist(FAR struct streamlist *list);
#endif #endif
#undef EXTERN #undef EXTERN
+6 -7
View File
@@ -81,6 +81,8 @@
# define HAVE_TASK_GROUP 1 # define HAVE_TASK_GROUP 1
# elif CONFIG_NFILE_DESCRIPTORS > 0 # elif CONFIG_NFILE_DESCRIPTORS > 0
# define HAVE_TASK_GROUP 1 # define HAVE_TASK_GROUP 1
# elif CONFIG_NFILE_STREAMS > 0
# define HAVE_TASK_GROUP 1
# endif # endif
#endif #endif
@@ -303,7 +305,10 @@ struct task_group_s
#endif #endif
/* FILE streams ***************************************************************/ /* 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 ********************************************************************/ /* Sockets ********************************************************************/
/* Not yet (see struct socketlist) */ /* Not yet (see struct socketlist) */
@@ -445,12 +450,6 @@ struct _TCB
int pterrno; /* Current per-thread errno */ 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 *************************************************************/ /* Network socket *************************************************************/
#if CONFIG_NSOCKET_DESCRIPTORS > 0 #if CONFIG_NSOCKET_DESCRIPTORS > 0
+40 -98
View File
@@ -1,7 +1,7 @@
/************************************************************ /************************************************************
* libc/misc/lib_init.c * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * 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 #if CONFIG_NFILE_STREAMS > 0
/* The following function is called when a new TCB is allocated. It /* The following function is called when a new task is allocated. It
* creates the streamlist instance that is stored in the TCB. * 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; int i;
list = (FAR struct streamlist*)lib_zalloc(sizeof(struct streamlist));
if (list)
{
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++) /* Indicate not opened */
{
/* Clear the IOB */
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; lib_sem_initialize(&list->sl_streams[i]);
/* 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);
} }
} }
@@ -149,57 +115,33 @@ void lib_addreflist(FAR struct streamlist *list)
void lib_releaselist(FAR struct streamlist *list) void lib_releaselist(FAR struct streamlist *list)
{ {
int crefs; #if CONFIG_STDIO_BUFFER_SIZE > 0
if (list) 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. /* Destroy the semaphore that protects the IO buffer */
* 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(); (void)sem_destroy(&list->sl_streams[i].fs_sem);
crefs = --(list->sl_crefs);
irqrestore(flags);
/* If the count decrements to zero, then there is no reference /* Release the IO buffer */
* 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) if (list->sl_streams[i].fs_bufstart)
{ {
#if CONFIG_STDIO_BUFFER_SIZE > 0 sched_free(list->sl_streams[i].fs_bufstart);
int i; }
}
#endif #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 */ #endif /* CONFIG_NFILE_STREAMS */
+1 -1
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* libc/stdio/lib_libflushall.c * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
+6 -25
View File
@@ -86,28 +86,11 @@ void group_leave(FAR _TCB *tcb);
FAR struct task_group_s *group_find(gid_t gid); FAR struct task_group_s *group_find(gid_t gid);
int group_addmember(FAR struct task_group_s *group, pid_t pid); int group_addmember(FAR struct task_group_s *group, pid_t pid);
int group_removemember(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 #endif
#ifndef CONFIG_DISABLE_SIGNALS #ifndef CONFIG_DISABLE_SIGNALS
int group_signal(FAR struct task_group_s *group, FAR siginfo_t *info); int group_signal(FAR struct task_group_s *group, FAR siginfo_t *info);
#else
# define group_signal(tcb,info) (0)
#endif #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 */ #endif /* HAVE_TASK_GROUP */
/* Parent/child data management */ /* Parent/child data management */
@@ -127,15 +110,13 @@ FAR struct child_status_s *group_removechild(FAR struct task_group_s *group,
pid_t pid); pid_t pid);
void group_removechildren(FAR struct task_group_s *group); 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_CHILD_STATUS */
#endif /* CONFIG_SCHED_HAVE_PARENT */ #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 */ #endif /* __SCHED_GROUP_INERNAL_H */
+2
View File
@@ -165,6 +165,7 @@ static inline void group_release(FAR _TCB *tcb,
env_release(tcb); env_release(tcb);
#endif #endif
#ifdef HAVE_GROUP_MEMBERS
/* Remove the group from the list of groups */ /* Remove the group from the list of groups */
group_remove(group); group_remove(group);
@@ -176,6 +177,7 @@ static inline void group_release(FAR _TCB *tcb,
sched_free(group->tg_members); sched_free(group->tg_members);
group->tg_members = NULL; group->tg_members = NULL;
} }
#endif
/* Release the group container itself */ /* Release the group container itself */
+4 -5
View File
@@ -80,7 +80,9 @@ int group_releasefiles(_TCB *tcb)
#if CONFIG_NFILE_DESCRIPTORS > 0 #if CONFIG_NFILE_DESCRIPTORS > 0
FAR struct task_group_s *group = tcb->group; FAR struct task_group_s *group = tcb->group;
DEBUGASSERT(group); DEBUGASSERT(group);
#endif
#if CONFIG_NFILE_DESCRIPTORS > 0
/* Free resources used by the file descriptor list */ /* Free resources used by the file descriptor list */
files_releaselist(&group->tg_filelist); files_releaselist(&group->tg_filelist);
@@ -88,11 +90,8 @@ int group_releasefiles(_TCB *tcb)
#if CONFIG_NFILE_STREAMS > 0 #if CONFIG_NFILE_STREAMS > 0
/* Free the stream list */ /* Free the stream list */
if (tcb->streams) lib_releaselist(&group->tg_streamlist);
{
lib_releaselist(tcb->streams);
tcb->streams = NULL;
}
#endif /* CONFIG_NFILE_STREAMS */ #endif /* CONFIG_NFILE_STREAMS */
#endif /* CONFIG_NFILE_DESCRIPTORS */ #endif /* CONFIG_NFILE_DESCRIPTORS */
+1 -1
View File
@@ -1,7 +1,7 @@
/************************************************************************ /************************************************************************
* sched/sched_getfiles.c * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
+5 -2
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* sched/sched_getstreams.c * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -70,7 +70,10 @@
FAR struct streamlist *sched_getstreams(void) FAR struct streamlist *sched_getstreams(void)
{ {
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; 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 */ #endif /* CONFIG_NFILE_DESCRIPTORS && CONFIG_NFILE_STREAMS */
-9
View File
@@ -77,8 +77,6 @@
int sched_setuppthreadfiles(FAR _TCB *tcb) int sched_setuppthreadfiles(FAR _TCB *tcb)
{ {
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
#if CONFIG_NSOCKET_DESCRIPTORS > 0 #if CONFIG_NSOCKET_DESCRIPTORS > 0
/* The child thread inherits the parent socket descriptors */ /* The child thread inherits the parent socket descriptors */
@@ -87,13 +85,6 @@ int sched_setuppthreadfiles(FAR _TCB *tcb)
#endif /* CONFIG_NSOCKET_DESCRIPTORS */ #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; return OK;
} }
+15 -16
View File
@@ -72,24 +72,23 @@
int sched_setupstreams(FAR _TCB *tcb) int sched_setupstreams(FAR _TCB *tcb)
{ {
/* Allocate file streams for the TCB */ DEBUGASSERT(tcb && tcb->group);
tcb->streams = lib_alloclist(); /* Initialize file streams for the task group */
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)
*/
(void)fs_fdopen(0, O_RDONLY, tcb); lib_streaminit(&tcb->group->tg_streamlist);
(void)fs_fdopen(1, O_WROK|O_CREAT, tcb);
(void)fs_fdopen(2, O_WROK|O_CREAT, tcb); /* 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; return OK;
} }
+1 -1
View File
@@ -543,7 +543,7 @@ void task_exithook(FAR _TCB *tcb, int status)
*/ */
#if CONFIG_NFILE_STREAMS > 0 #if CONFIG_NFILE_STREAMS > 0
(void)lib_flushall(tcb->streams); (void)lib_flushall(&tcb->group->tg_streamlist);
#endif #endif
/* Leave the task group. Perhaps discarding any un-reaped child /* Leave the task group. Perhaps discarding any un-reaped child