2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2007-04-28 19:39:18 +00:00
|
|
|
* common/up_exit.c
|
|
|
|
*
|
2018-11-24 18:20:57 -06:00
|
|
|
* Copyright (C) 2007-2009, 201-2014, 2017-2018 Gregory Nutt. All rights
|
|
|
|
* reserved.
|
2012-01-31 20:32:49 +00:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2008-01-01 14:54:10 +00:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-04-28 19:39:18 +00:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2007-04-28 19:39:18 +00:00
|
|
|
* Included Files
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-16 20:05:51 +00:00
|
|
|
|
2007-04-28 19:39:18 +00:00
|
|
|
#include <sched.h>
|
|
|
|
#include <debug.h>
|
2009-05-19 20:14:44 +00:00
|
|
|
|
2017-01-13 11:08:24 -06:00
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/irq.h>
|
2007-04-28 19:39:18 +00:00
|
|
|
#ifdef CONFIG_DUMP_ON_EXIT
|
2017-01-13 11:08:24 -06:00
|
|
|
# include <nuttx/fs/fs.h>
|
2007-04-28 19:39:18 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-08 16:44:08 -06:00
|
|
|
#include "task/task.h"
|
2014-08-08 17:53:55 -06:00
|
|
|
#include "sched/sched.h"
|
2014-08-27 16:31:02 -06:00
|
|
|
#include "group/group.h"
|
2016-11-24 13:33:43 -06:00
|
|
|
#include "irq/irq.h"
|
2014-08-08 16:44:08 -06:00
|
|
|
#include "up_internal.h"
|
|
|
|
|
2016-06-17 15:21:07 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_DEBUG_SCHED_INFO
|
|
|
|
# undef CONFIG_DUMP_ON_EXIT
|
|
|
|
#endif
|
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2008-01-30 18:49:31 +00:00
|
|
|
* Private Functions
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2007-04-28 19:39:18 +00:00
|
|
|
* Name: _up_dumponexit
|
|
|
|
*
|
|
|
|
* Description:
|
2008-01-30 18:49:31 +00:00
|
|
|
* Dump the state of all tasks whenever on task exits. This is debug
|
|
|
|
* instrumentation that was added to check file-related reference counting
|
|
|
|
* but could be useful again sometime in the future.
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2016-06-17 15:21:07 -06:00
|
|
|
#ifdef CONFIG_DUMP_ON_EXIT
|
2013-02-04 18:46:28 +00:00
|
|
|
static void _up_dumponexit(FAR struct tcb_s *tcb, FAR void *arg)
|
2007-04-28 19:39:18 +00:00
|
|
|
{
|
2013-01-26 22:25:21 +00:00
|
|
|
FAR struct filelist *filelist;
|
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
|
|
|
FAR struct streamlist *streamlist;
|
|
|
|
#endif
|
2007-04-28 19:39:18 +00:00
|
|
|
int i;
|
2007-11-23 21:16:43 +00:00
|
|
|
|
2016-06-17 15:21:07 -06:00
|
|
|
sinfo(" TCB=%p name=%s pid=%d\n", tcb, tcb->argv[0], tcb->pid);
|
|
|
|
sinfo(" priority=%d state=%d\n", tcb->sched_priority, tcb->task_state);
|
2007-11-20 20:32:33 +00:00
|
|
|
|
2013-01-26 22:25:21 +00:00
|
|
|
filelist = tcb->group->tg_filelist;
|
|
|
|
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
|
2007-04-28 19:39:18 +00:00
|
|
|
{
|
2013-01-26 22:25:21 +00:00
|
|
|
struct inode *inode = filelist->fl_files[i].f_inode;
|
|
|
|
if (inode)
|
2007-04-28 19:39:18 +00:00
|
|
|
{
|
2016-06-17 15:21:07 -06:00
|
|
|
sinfo(" fd=%d refcount=%d\n",
|
2018-11-10 14:01:21 -06:00
|
|
|
i, inode->i_crefs);
|
2007-04-28 19:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-20 20:32:33 +00:00
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
2013-01-26 22:25:21 +00:00
|
|
|
streamlist = tcb->group->tg_streamlist;
|
|
|
|
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
|
2007-04-28 19:39:18 +00:00
|
|
|
{
|
2013-01-26 22:25:21 +00:00
|
|
|
struct file_struct *filep = &streamlist->sl_streams[i];
|
2013-09-28 16:50:07 -06:00
|
|
|
if (filep->fs_fd >= 0)
|
2007-04-28 19:39:18 +00:00
|
|
|
{
|
2017-02-09 09:24:44 -06:00
|
|
|
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
|
|
|
if (filep->fs_bufstart != NULL)
|
|
|
|
{
|
|
|
|
sinfo(" fd=%d nbytes=%d\n",
|
|
|
|
filep->fs_fd,
|
|
|
|
filep->fs_bufpos - filep->fs_bufstart);
|
|
|
|
}
|
|
|
|
else
|
2017-02-09 20:38:15 +00:00
|
|
|
#endif
|
2017-02-09 09:24:44 -06:00
|
|
|
{
|
|
|
|
sinfo(" fd=%d\n", filep->fs_fd);
|
|
|
|
}
|
2007-04-28 19:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-20 20:32:33 +00:00
|
|
|
#endif
|
2007-04-28 19:39:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2008-01-01 14:54:10 +00:00
|
|
|
/****************************************************************************
|
2007-04-28 19:39:18 +00:00
|
|
|
* Name: _exit
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function causes the currently executing task to cease
|
2008-01-30 18:49:31 +00:00
|
|
|
* to exist. This is a special case of task_delete() where the task to
|
|
|
|
* be deleted is the currently executing task. It is more complex because
|
2009-06-25 17:44:35 +00:00
|
|
|
* a context switch must be perform to the next ready to run task.
|
2007-04-28 19:39:18 +00:00
|
|
|
*
|
2008-01-01 14:54:10 +00:00
|
|
|
****************************************************************************/
|
2007-04-28 19:39:18 +00:00
|
|
|
|
|
|
|
void _exit(int status)
|
|
|
|
{
|
2018-11-24 18:20:57 -06:00
|
|
|
struct tcb_s *tcb = this_task();
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2017-01-13 11:08:24 -06:00
|
|
|
/* Make sure that we are in a critical section with local interrupts.
|
|
|
|
* The IRQ state will be restored when the next task is started.
|
2007-04-28 19:39:18 +00:00
|
|
|
*/
|
|
|
|
|
2017-01-13 11:08:24 -06:00
|
|
|
(void)enter_critical_section();
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2018-11-24 18:20:57 -06:00
|
|
|
sinfo("TCB=%p exiting\n", tcb);
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2016-06-17 15:21:07 -06:00
|
|
|
#ifdef CONFIG_DUMP_ON_EXIT
|
2016-06-20 11:59:15 -06:00
|
|
|
sinfo("Other tasks:\n");
|
2007-04-28 19:39:18 +00:00
|
|
|
sched_foreach(_up_dumponexit, NULL);
|
|
|
|
#endif
|
|
|
|
|
2018-11-24 18:20:57 -06:00
|
|
|
/* Update scheduler parameters */
|
|
|
|
|
|
|
|
sched_suspend_scheduler(tcb);
|
|
|
|
|
2008-01-30 18:49:31 +00:00
|
|
|
/* Destroy the task at the head of the ready to run list. */
|
2007-04-28 19:39:18 +00:00
|
|
|
|
This commit renames all internal OS functions defined under sched/task so that they begin with the prefix. For example, nxtask_exit() vs. task_exit().
Squashed commit of the following:
Trivial, cosmetic
sched/, arch/, and include: Rename task_vforkstart() as nxtask_vforkstart()
sched/, arch/, and include: Rename task_vforkabort() as nxtask_vforkabort()
sched/, arch/, and include: Rename task_vforksetup() as nxtask_vfork_setup()
sched/: Rename notify_cancellation() as nxnotify_cancellation()
sched/: Rename task_recover() to nxtask_recover()
sched/task, sched/pthread/, Documentation/: Rename task_argsetup() and task_terminate() to nxtask_argsetup() and nxtask_terminate(), respectively.
sched/task: Rename task_schedsetup() to nxtask_schedsetup()
sched/ (plus some binfmt/, include/, and arch/): Rename task_start() and task_starthook() to nxtask_start() and nxtask_starthook().
arch/ and sched/: Rename task_exit() and task_exithook() to nxtask_exit() and nxtask_exithook(), respectively.
sched/task: Rename all internal, static, functions to begin with the nx prefix.
2019-02-04 13:42:51 -06:00
|
|
|
(void)nxtask_exit();
|
2007-04-28 19:39:18 +00:00
|
|
|
|
|
|
|
/* Now, perform the context switch to the new ready-to-run task at the
|
|
|
|
* head of the list.
|
|
|
|
*/
|
|
|
|
|
2016-02-06 13:41:28 -06:00
|
|
|
tcb = this_task();
|
2007-04-28 19:39:18 +00:00
|
|
|
|
2014-08-27 16:31:02 -06:00
|
|
|
#ifdef CONFIG_ARCH_ADDRENV
|
|
|
|
/* Make sure that the address environment for the previously running
|
|
|
|
* task is closed down gracefully (data caches dump, MMU flushed) and
|
|
|
|
* set up the address environment for the new thread at the head of
|
|
|
|
* the ready-to-run list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(void)group_addrenv(tcb);
|
|
|
|
#endif
|
|
|
|
|
2018-11-24 18:20:57 -06:00
|
|
|
/* Reset scheduler parameters */
|
|
|
|
|
|
|
|
sched_resume_scheduler(tcb);
|
|
|
|
|
2007-04-28 19:39:18 +00:00
|
|
|
/* Then switch contexts */
|
|
|
|
|
|
|
|
up_fullcontextrestore(tcb->xcp.regs);
|
|
|
|
}
|