2013-02-06 23:43:28 +08:00
|
|
|
/****************************************************************************
|
2014-08-09 06:44:08 +08:00
|
|
|
* sched/task/task_recover.c
|
2013-02-06 23:43:28 +08:00
|
|
|
*
|
2024-09-11 19:45:11 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-02-06 23:43:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-02-06 23:43:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-02-06 23:43:28 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2015-07-24 23:03:21 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
2013-02-06 23:43:28 +08:00
|
|
|
#include <nuttx/arch.h>
|
2014-08-22 01:16:55 +08:00
|
|
|
#include <nuttx/wdog.h>
|
2013-02-06 23:43:28 +08:00
|
|
|
#include <nuttx/sched.h>
|
|
|
|
|
2014-12-14 02:02:25 +08:00
|
|
|
#include "semaphore/semaphore.h"
|
|
|
|
#include "wdog/wdog.h"
|
2014-08-09 02:31:23 +08:00
|
|
|
#include "mqueue/mqueue.h"
|
2022-05-25 13:17:34 +08:00
|
|
|
#include "pthread/pthread.h"
|
2015-07-24 23:03:21 +08:00
|
|
|
#include "sched/sched.h"
|
2014-08-09 06:44:08 +08:00
|
|
|
#include "task/task.h"
|
2013-02-06 23:43:28 +08: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-05 03:42:51 +08:00
|
|
|
* Name: nxtask_recover
|
2013-02-06 23:43:28 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2014-12-14 02:02:25 +08: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 23:43:28 +08:00
|
|
|
*
|
2018-02-02 00:00:02 +08:00
|
|
|
* Input Parameters:
|
2013-02-06 23:43:28 +08:00
|
|
|
* tcb - The TCB of the terminated task or thread
|
|
|
|
*
|
2018-02-02 00:00:02 +08:00
|
|
|
* Returned Value:
|
2013-02-06 23:43:28 +08: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-05 03:42:51 +08:00
|
|
|
void nxtask_recover(FAR struct tcb_s *tcb)
|
2013-02-06 23:43:28 +08:00
|
|
|
{
|
2022-05-25 13:17:34 +08:00
|
|
|
#if !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
|
|
|
|
/* Recover any mutexes still held by the canceled thread */
|
|
|
|
|
|
|
|
pthread_mutex_inconsistent(tcb);
|
|
|
|
#endif
|
|
|
|
|
2014-12-14 02:02:25 +08:00
|
|
|
/* The task is being deleted. Cancel in pending timeout events. */
|
2013-02-06 23:43:28 +08:00
|
|
|
|
2014-12-14 02:02:25 +08:00
|
|
|
wd_recover(tcb);
|
2013-02-06 23:43:28 +08:00
|
|
|
|
2020-03-08 20:51:34 +08:00
|
|
|
/* If the thread holds semaphore counts or is waiting for a semaphore
|
|
|
|
* count, then release the counts.
|
2014-12-14 02:02:25 +08:00
|
|
|
*/
|
2013-02-06 23:43:28 +08:00
|
|
|
|
2017-10-04 02:51:15 +08:00
|
|
|
nxsem_recover(tcb);
|
2013-02-06 23:43:28 +08:00
|
|
|
|
2022-11-16 18:20:31 +08:00
|
|
|
#if !defined(CONFIG_DISABLE_MQUEUE) || !defined(CONFIG_DISABLE_MQUEUE_SYSV)
|
2013-02-06 23:43:28 +08:00
|
|
|
/* Handle cases where the thread was waiting for a message queue event */
|
|
|
|
|
2017-10-09 23:06:46 +08:00
|
|
|
nxmq_recover(tcb);
|
2013-02-06 23:43:28 +08:00
|
|
|
#endif
|
2015-07-24 23:03:21 +08:00
|
|
|
|
2015-07-25 02:27:15 +08:00
|
|
|
#ifdef CONFIG_SCHED_SPORADIC
|
2015-07-24 23:03:21 +08:00
|
|
|
if ((tcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC)
|
|
|
|
{
|
|
|
|
/* Stop current sporadic scheduling */
|
|
|
|
|
2020-05-10 02:40:14 +08:00
|
|
|
DEBUGVERIFY(nxsched_stop_sporadic(tcb));
|
2015-07-24 23:03:21 +08:00
|
|
|
}
|
|
|
|
#endif
|
2013-02-06 23:43:28 +08:00
|
|
|
}
|