diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-04-18 11:41:11 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-04-18 11:41:11 -0600 |
commit | 7ed378b0442b21647f3ee1b41a852a7e4e100f8e (patch) | |
tree | 2ab285f5c1cd0fc9d7e91212c49bfcb32664be58 | |
parent | 14ac0fc7e7fd8c1a7c8aeef4bef24ea74fe2774a (diff) | |
download | nuttx-7ed378b0442b21647f3ee1b41a852a7e4e100f8e.tar.gz nuttx-7ed378b0442b21647f3ee1b41a852a7e4e100f8e.tar.bz2 nuttx-7ed378b0442b21647f3ee1b41a852a7e4e100f8e.zip |
Don't flush streams until the final thread of a group exits
-rw-r--r-- | nuttx/sched/task_exithook.c | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c index 3a03e0e77..6372e628a 100644 --- a/nuttx/sched/task_exithook.c +++ b/nuttx/sched/task_exithook.c @@ -541,11 +541,39 @@ static inline void task_exitwakeup(FAR struct tcb_s *tcb, int status) #endif /**************************************************************************** + * Name: task_flushstreams + * + * Description: + * Flush all streams when the final thread of a group exits. + * + ****************************************************************************/ + +#if CONFIG_NFILE_STREAMS > 0 +static inline void task_flushstreams(FAR struct tcb_s *tcb) +{ + FAR struct task_group_s *group = tcb->group; + + /* Have we already left the group? Are we the last thread in the group? */ + + if (group && group->tg_nmembers == 1) + { +#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP) + (void)lib_flushall(tcb->group->tg_streamlist); +#else + (void)lib_flushall(&tcb->group->tg_streamlist); +#endif + } +} +#else +# define task_flushstreams(tcb) +#endif + +/**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: task_hook + * Name: task_exithook * * Description: * This function implements some of the internal logic of exit() and @@ -604,17 +632,11 @@ void task_exithook(FAR struct tcb_s *tcb, int status) task_exitwakeup(tcb, status); - /* Flush all streams (File descriptors will be closed when - * the TCB is deallocated). + /* If this is the last thread in the group, then flush all streams (File + * descriptors will be closed when the TCB is deallocated). */ -#if CONFIG_NFILE_STREAMS > 0 -#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP) - (void)lib_flushall(tcb->group->tg_streamlist); -#else - (void)lib_flushall(&tcb->group->tg_streamlist); -#endif -#endif + task_flushstreams(tcb); /* Leave the task group. Perhaps discarding any un-reaped child * status (no zombies here!) |