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
|
|
|
*
|
2021-02-08 16:33:58 +01: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 16:43:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-02-06 16:43:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01: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 16:43:28 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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"
|
2022-05-25 07:17:34 +02:00
|
|
|
#include "pthread/pthread.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
|
|
|
{
|
2022-05-25 07:17:34 +02: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-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
|
|
|
|
2022-11-16 11:20:31 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MQUEUE) || !defined(CONFIG_DISABLE_MQUEUE_SYSV)
|
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
|
|
|
}
|