summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-26 22:25:21 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-26 22:25:21 +0000
commit75f185244fbd0892fdb26443eda666ce21c417ec (patch)
tree7b706cce24489ea8e025a9802d3daf3078428e19
parent801ce1b6a68a593f0aef2d059d9279b0d0824e54 (diff)
downloadnuttx-75f185244fbd0892fdb26443eda666ce21c417ec.tar.gz
nuttx-75f185244fbd0892fdb26443eda666ce21c417ec.tar.bz2
nuttx-75f185244fbd0892fdb26443eda666ce21c417ec.zip
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
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/arch/arm/src/common/up_exit.c42
-rw-r--r--nuttx/arch/avr/src/common/up_exit.c42
-rw-r--r--nuttx/arch/hc/src/common/up_exit.c42
-rw-r--r--nuttx/arch/mips/src/common/up_exit.c42
-rw-r--r--nuttx/arch/sh/src/common/up_exit.c42
-rw-r--r--nuttx/arch/x86/src/common/up_exit.c44
-rw-r--r--nuttx/arch/z16/src/common/up_exit.c42
-rw-r--r--nuttx/arch/z80/src/common/up_exit.c44
-rw-r--r--nuttx/fs/fs_fdopen.c5
-rw-r--r--nuttx/include/nuttx/fs/fs.h1
-rw-r--r--nuttx/include/nuttx/lib.h9
-rw-r--r--nuttx/include/nuttx/sched.h13
-rw-r--r--nuttx/libc/misc/lib_init.c134
-rw-r--r--nuttx/libc/stdio/lib_libflushall.c2
-rw-r--r--nuttx/sched/group_internal.h27
-rw-r--r--nuttx/sched/group_leave.c2
-rw-r--r--nuttx/sched/group_releasefiles.c9
-rw-r--r--nuttx/sched/sched_getfiles.c2
-rw-r--r--nuttx/sched/sched_getstreams.c7
-rw-r--r--nuttx/sched/sched_setuppthreadfiles.c9
-rw-r--r--nuttx/sched/sched_setupstreams.c35
-rw-r--r--nuttx/sched/task_exithook.c2
23 files changed, 242 insertions, 357 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index ae7105b89..b5933f620 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -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.
diff --git a/nuttx/arch/arm/src/common/up_exit.c b/nuttx/arch/arm/src/common/up_exit.c
index 5b469fd03..16f5c4442 100644
--- a/nuttx/arch/arm/src/common/up_exit.c
+++ b/nuttx/arch/arm/src/common/up_exit.c
@@ -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
diff --git a/nuttx/arch/avr/src/common/up_exit.c b/nuttx/arch/avr/src/common/up_exit.c
index 0813754a0..68e33fde7 100644
--- a/nuttx/arch/avr/src/common/up_exit.c
+++ b/nuttx/arch/avr/src/common/up_exit.c
@@ -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
diff --git a/nuttx/arch/hc/src/common/up_exit.c b/nuttx/arch/hc/src/common/up_exit.c
index 5313a1172..1c46875f8 100644
--- a/nuttx/arch/hc/src/common/up_exit.c
+++ b/nuttx/arch/hc/src/common/up_exit.c
@@ -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
diff --git a/nuttx/arch/mips/src/common/up_exit.c b/nuttx/arch/mips/src/common/up_exit.c
index 5a7b68a99..e112364b4 100644
--- a/nuttx/arch/mips/src/common/up_exit.c
+++ b/nuttx/arch/mips/src/common/up_exit.c
@@ -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
diff --git a/nuttx/arch/sh/src/common/up_exit.c b/nuttx/arch/sh/src/common/up_exit.c
index af270b335..705f49852 100644
--- a/nuttx/arch/sh/src/common/up_exit.c
+++ b/nuttx/arch/sh/src/common/up_exit.c
@@ -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
diff --git a/nuttx/arch/x86/src/common/up_exit.c b/nuttx/arch/x86/src/common/up_exit.c
index 6a98c7dd0..dee6f7d49 100644
--- a/nuttx/arch/x86/src/common/up_exit.c
+++ b/nuttx/arch/x86/src/common/up_exit.c
@@ -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
diff --git a/nuttx/arch/z16/src/common/up_exit.c b/nuttx/arch/z16/src/common/up_exit.c
index ad0c55eed..20b808360 100644
--- a/nuttx/arch/z16/src/common/up_exit.c
+++ b/nuttx/arch/z16/src/common/up_exit.c
@@ -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
diff --git a/nuttx/arch/z80/src/common/up_exit.c b/nuttx/arch/z80/src/common/up_exit.c
index 50289f52b..603a0bfbe 100644
--- a/nuttx/arch/z80/src/common/up_exit.c
+++ b/nuttx/arch/z80/src/common/up_exit.c
@@ -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
diff --git a/nuttx/fs/fs_fdopen.c b/nuttx/fs/fs_fdopen.c
index 629083c77..d8a370482 100644
--- a/nuttx/fs/fs_fdopen.c
+++ b/nuttx/fs/fs_fdopen.c
@@ -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)
diff --git a/nuttx/include/nuttx/fs/fs.h b/nuttx/include/nuttx/fs/fs.h
index 02855460c..93ca2a334 100644
--- a/nuttx/include/nuttx/fs/fs.h
+++ b/nuttx/include/nuttx/fs/fs.h
@@ -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];
};
diff --git a/nuttx/include/nuttx/lib.h b/nuttx/include/nuttx/lib.h
index 220af2030..3bc581e18 100644
--- a/nuttx/include/nuttx/lib.h
+++ b/nuttx/include/nuttx/lib.h
@@ -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
diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h
index 1580a80d3..a084d50ba 100644
--- a/nuttx/include/nuttx/sched.h
+++ b/nuttx/include/nuttx/sched.h
@@ -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
diff --git a/nuttx/libc/misc/lib_init.c b/nuttx/libc/misc/lib_init.c
index 6a120f7b1..434c46505 100644
--- a/nuttx/libc/misc/lib_init.c
+++ b/nuttx/libc/misc/lib_init.c
@@ -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;
-
- /* Start with a reference count of one */
-
- list->sl_crefs = 1;
+ int i;
- /* Initialize the list access mutex */
+ /* Initialize the list access mutex */
- (void)sem_init(&list->sl_sem, 0, 1);
+ (void)sem_init(&list->sl_sem, 0, 1);
- /* Initialize each FILE structure */
+ /* Initialize each FILE structure */
- for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
- {
- /* Clear the IOB */
+ for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
+ {
+ /* Clear the IOB */
- memset(&list->sl_streams[i], 0, sizeof(FILE));
+ memset(&list->sl_streams[i], 0, sizeof(FILE));
- /* Indicate not opened */
+ /* Indicate not opened */
- list->sl_streams[i].fs_filedes = -1;
+ 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;
+ /* Initialize the stream semaphore to one to support one-at-
+ * a-time access to private data sets.
+ */
-}
-
-/* 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)
- {
- /* 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->sl_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)
- {
#if CONFIG_STDIO_BUFFER_SIZE > 0
- int i;
+ int i;
#endif
- /* Destroy the semaphore and release the filelist */
- (void)sem_destroy(&list->sl_sem);
+ DEBUGASSERT(list);
+
+ /* Destroy the semaphore and release the filelist */
- /* Release each stream in the list */
+ (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 */
+ for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
+ {
+ /* Destroy the semaphore that protects the IO buffer */
- sched_free(list);
- }
- }
+ (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
}
#endif /* CONFIG_NFILE_STREAMS */
diff --git a/nuttx/libc/stdio/lib_libflushall.c b/nuttx/libc/stdio/lib_libflushall.c
index 7ac3da7e0..22baed968 100644
--- a/nuttx/libc/stdio/lib_libflushall.c
+++ b/nuttx/libc/stdio/lib_libflushall.c
@@ -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
diff --git a/nuttx/sched/group_internal.h b/nuttx/sched/group_internal.h
index 39d0a2b7c..e6e0dfd16 100644
--- a/nuttx/sched/group_internal.h
+++ b/nuttx/sched/group_internal.h
@@ -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);
+#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);
-#else
-# define group_releasefiles(t) (OK)
+int group_releasefiles(FAR _TCB *tcb);
#endif
-#endif /* CONFIG_SCHED_CHILD_STATUS */
-#endif /* CONFIG_SCHED_HAVE_PARENT */
-
#endif /* __SCHED_GROUP_INERNAL_H */
diff --git a/nuttx/sched/group_leave.c b/nuttx/sched/group_leave.c
index 158ba30b5..70ef93666 100644
--- a/nuttx/sched/group_leave.c
+++ b/nuttx/sched/group_leave.c
@@ -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 */
diff --git a/nuttx/sched/group_releasefiles.c b/nuttx/sched/group_releasefiles.c
index 40bf373b4..b33415c76 100644
--- a/nuttx/sched/group_releasefiles.c
+++ b/nuttx/sched/group_releasefiles.c
@@ -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 */
diff --git a/nuttx/sched/sched_getfiles.c b/nuttx/sched/sched_getfiles.c
index eca4ba3ff..17ca2bbf6 100644
--- a/nuttx/sched/sched_getfiles.c
+++ b/nuttx/sched/sched_getfiles.c
@@ -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
diff --git a/nuttx/sched/sched_getstreams.c b/nuttx/sched/sched_getstreams.c
index f7c21ab4c..dab406e66 100644
--- a/nuttx/sched/sched_getstreams.c
+++ b/nuttx/sched/sched_getstreams.c
@@ -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 */
diff --git a/nuttx/sched/sched_setuppthreadfiles.c b/nuttx/sched/sched_setuppthreadfiles.c
index 78d6cbfec..91d72fa7f 100644
--- a/nuttx/sched/sched_setuppthreadfiles.c
+++ b/nuttx/sched/sched_setuppthreadfiles.c
@@ -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;
}
diff --git a/nuttx/sched/sched_setupstreams.c b/nuttx/sched/sched_setupstreams.c
index 22895b047..fb2e4d0be 100644
--- a/nuttx/sched/sched_setupstreams.c
+++ b/nuttx/sched/sched_setupstreams.c
@@ -72,24 +72,23 @@
int sched_setupstreams(FAR _TCB *tcb)
{
- /* Allocate file streams for the TCB */
-
- 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)
- */
-
- (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);
- }
+ DEBUGASSERT(tcb && tcb->group);
+
+ /* Initialize file streams for the task group */
+
+ 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;
}
diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c
index 5a2b9e57e..889df25e0 100644
--- a/nuttx/sched/task_exithook.c
+++ b/nuttx/sched/task_exithook.c
@@ -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