2013-02-06 16:43:28 +01:00
|
|
|
/****************************************************************************
|
2014-08-09 00:44:08 +02:00
|
|
|
* sched/task/task_recover.c
|
2013-02-06 16:43:28 +01:00
|
|
|
*
|
2014-08-21 19:16:55 +02:00
|
|
|
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
|
2013-02-06 16:43:28 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2015-07-24 17:03:21 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2013-02-06 16:43:28 +01:00
|
|
|
#include <nuttx/arch.h>
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/wdog.h>
|
2013-02-06 16:43:28 +01:00
|
|
|
#include <nuttx/sched.h>
|
|
|
|
|
2014-12-13 19:02:25 +01:00
|
|
|
#include "semaphore/semaphore.h"
|
|
|
|
#include "wdog/wdog.h"
|
2014-08-08 20:31:23 +02:00
|
|
|
#include "mqueue/mqueue.h"
|
2015-07-24 17:03:21 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-09 00:44:08 +02:00
|
|
|
#include "task/task.h"
|
2013-02-06 16:43:28 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
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 20:42:51 +01:00
|
|
|
* Name: nxtask_recover
|
2013-02-06 16:43:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2014-12-13 19:02:25 +01:00
|
|
|
* This function is called when a task is deleted via task_delete() or
|
|
|
|
* via pthread_cancel. I checks checks for semaphores, message queue, and
|
|
|
|
* watchdog timer resources stranded in bad conditions.
|
2013-02-06 16:43:28 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2013-02-06 16:43:28 +01:00
|
|
|
* tcb - The TCB of the terminated task or thread
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-02-06 16:43:28 +01:00
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function is called from task deletion logic in a safe context.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
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 20:42:51 +01:00
|
|
|
void nxtask_recover(FAR struct tcb_s *tcb)
|
2013-02-06 16:43:28 +01:00
|
|
|
{
|
2014-12-13 19:02:25 +01:00
|
|
|
/* The task is being deleted. Cancel in pending timeout events. */
|
2013-02-06 16:43:28 +01:00
|
|
|
|
2014-12-13 19:02:25 +01:00
|
|
|
wd_recover(tcb);
|
2013-02-06 16:43:28 +01:00
|
|
|
|
2020-03-08 13:51:34 +01:00
|
|
|
/* If the thread holds semaphore counts or is waiting for a semaphore
|
|
|
|
* count, then release the counts.
|
2014-12-13 19:02:25 +01:00
|
|
|
*/
|
2013-02-06 16:43:28 +01:00
|
|
|
|
2017-10-03 20:51:15 +02:00
|
|
|
nxsem_recover(tcb);
|
2013-02-06 16:43:28 +01:00
|
|
|
|
2014-12-13 19:02:25 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2013-02-06 16:43:28 +01:00
|
|
|
/* Handle cases where the thread was waiting for a message queue event */
|
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
nxmq_recover(tcb);
|
2013-02-06 16:43:28 +01:00
|
|
|
#endif
|
2015-07-24 17:03:21 +02:00
|
|
|
|
2015-07-24 20:27:15 +02:00
|
|
|
#ifdef CONFIG_SCHED_SPORADIC
|
2015-07-24 17:03:21 +02:00
|
|
|
if ((tcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC)
|
|
|
|
{
|
|
|
|
/* Stop current sporadic scheduling */
|
|
|
|
|
2020-05-09 20:40:14 +02:00
|
|
|
DEBUGVERIFY(nxsched_stop_sporadic(tcb));
|
2015-07-24 17:03:21 +02:00
|
|
|
}
|
|
|
|
#endif
|
2013-02-06 16:43:28 +01:00
|
|
|
}
|