2011-05-28 23:42:18 +02:00
|
|
|
/****************************************************************************
|
2014-08-09 00:44:08 +02:00
|
|
|
* sched/task/task_exithook.c
|
2011-05-28 23:42:18 +02: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
|
2011-05-28 23:42:18 +02:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-05-28 23:42:18 +02: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.
|
2011-05-28 23:42:18 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2013-01-12 20:58:45 +01:00
|
|
|
#include <signal.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2011-05-28 23:42:18 +02:00
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2012-09-13 21:33:47 +02:00
|
|
|
#include <nuttx/sched.h>
|
2012-03-21 19:01:07 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
2022-10-28 05:42:13 +02:00
|
|
|
#include <nuttx/mm/mm.h>
|
2011-05-28 23:42:18 +02:00
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-08 22:06:42 +02:00
|
|
|
#include "group/group.h"
|
2014-08-08 20:44:44 +02:00
|
|
|
#include "signal/signal.h"
|
2014-08-09 00:44:08 +02:00
|
|
|
#include "task/task.h"
|
2011-05-28 23:42:18 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-01-26 21:17:29 +01: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 20:42:51 +01:00
|
|
|
* Name: nxtask_exitstatus
|
2013-01-26 21:17:29 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Report exit status when main task of a task group exits
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_CHILD_STATUS
|
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
|
|
|
static inline void nxtask_exitstatus(FAR struct task_group_s *group,
|
|
|
|
int status)
|
2013-01-26 21:17:29 +01:00
|
|
|
{
|
|
|
|
FAR struct child_status_s *child;
|
|
|
|
|
|
|
|
/* Check if the parent task group has suppressed retention of
|
|
|
|
* child exit status information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((group->tg_flags & GROUP_FLAG_NOCLDWAIT) == 0)
|
|
|
|
{
|
|
|
|
/* No.. Find the exit status entry for this task in the parent TCB */
|
|
|
|
|
2022-11-15 07:37:20 +01:00
|
|
|
child = group_find_child(group, gettid());
|
2013-01-26 21:17:29 +01:00
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
/* Save the exit status.. For the case of HAVE_GROUP_MEMBERS,
|
|
|
|
* the child status will be as exited until the last member
|
|
|
|
* of the task group exits.
|
|
|
|
*/
|
|
|
|
|
|
|
|
child->ch_status = status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
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
|
|
|
# define nxtask_exitstatus(group,status)
|
2013-01-26 21:17:29 +01:00
|
|
|
|
|
|
|
#endif /* CONFIG_SCHED_CHILD_STATUS */
|
|
|
|
|
|
|
|
/****************************************************************************
|
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_groupexit
|
2013-01-26 21:17:29 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Mark that the final thread of a child task group as exited.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_CHILD_STATUS
|
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
|
|
|
static inline void nxtask_groupexit(FAR struct task_group_s *group)
|
2013-01-26 21:17:29 +01:00
|
|
|
{
|
|
|
|
FAR struct child_status_s *child;
|
|
|
|
|
|
|
|
/* Check if the parent task group has suppressed retention of child exit
|
|
|
|
* status information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((group->tg_flags & GROUP_FLAG_NOCLDWAIT) == 0)
|
|
|
|
{
|
|
|
|
/* No.. Find the exit status entry for this task in the parent TCB */
|
|
|
|
|
2022-11-15 07:37:20 +01:00
|
|
|
child = group_find_child(group, gettid());
|
2013-01-26 21:17:29 +01:00
|
|
|
if (child)
|
|
|
|
{
|
2014-04-27 19:38:24 +02:00
|
|
|
/* Mark that all members of the child task group has exited */
|
2013-01-26 21:17:29 +01:00
|
|
|
|
|
|
|
child->ch_flags |= CHILD_FLAG_EXITED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
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
|
|
|
# define nxtask_groupexit(group)
|
2013-01-26 21:17:29 +01:00
|
|
|
|
|
|
|
#endif /* CONFIG_SCHED_CHILD_STATUS */
|
|
|
|
|
2013-01-12 20:58:45 +01: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 20:42:51 +01:00
|
|
|
* Name: nxtask_sigchild
|
2013-01-12 20:58:45 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-10-29 01:12:53 +01:00
|
|
|
* Send the SIGCHLD signal to the parent thread
|
2013-01-12 20:58:45 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-04-29 22:52:05 +02:00
|
|
|
#ifdef CONFIG_SCHED_HAVE_PARENT
|
2013-01-26 18:28:20 +01:00
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
2021-03-03 18:11:40 +01:00
|
|
|
static inline void nxtask_sigchild(pid_t ppid, FAR struct tcb_s *ctcb,
|
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
|
|
|
int status)
|
2013-01-26 18:28:20 +01:00
|
|
|
{
|
|
|
|
FAR struct task_group_s *chgrp = ctcb->group;
|
|
|
|
FAR struct task_group_s *pgrp;
|
|
|
|
siginfo_t info;
|
|
|
|
|
|
|
|
DEBUGASSERT(chgrp);
|
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
/* Get the parent task group. It is possible that all of the members of
|
2013-04-24 00:41:43 +02:00
|
|
|
* the parent task group have exited. This would not be an error. In
|
2013-01-26 21:17:29 +01:00
|
|
|
* this case, the child task group has been orphaned.
|
|
|
|
*/
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2021-03-03 18:11:40 +01:00
|
|
|
pgrp = group_findbypid(ppid);
|
2013-01-26 21:17:29 +01:00
|
|
|
if (!pgrp)
|
2013-01-26 18:28:20 +01:00
|
|
|
{
|
2013-01-26 21:17:29 +01:00
|
|
|
/* Set the task group ID to an invalid group ID. The dead parent
|
|
|
|
* task group ID could get reused some time in the future.
|
2013-01-26 18:28:20 +01:00
|
|
|
*/
|
|
|
|
|
2021-03-03 18:11:40 +01:00
|
|
|
chgrp->tg_ppid = INVALID_PROCESS_ID;
|
2013-01-26 21:17:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
/* Save the exit status now if this is the main thread of the task group
|
|
|
|
* that is exiting. Only the exiting main task of a task group carries
|
|
|
|
* interpretable exit Check if this is the main task that is exiting.
|
|
|
|
*/
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
|
|
|
if ((ctcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD)
|
|
|
|
#endif
|
2013-01-26 21:17:29 +01: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 20:42:51 +01:00
|
|
|
nxtask_exitstatus(pgrp, status);
|
2013-01-26 21:17:29 +01:00
|
|
|
}
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
/* But only the final exiting thread in a task group, whatever it is,
|
|
|
|
* should generate SIGCHLD.
|
|
|
|
*/
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2013-01-26 21:17:29 +01:00
|
|
|
if (chgrp->tg_nmembers == 1)
|
|
|
|
{
|
|
|
|
/* Mark that all of the threads in the task group have exited */
|
2013-01-26 18:28:20 +01: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 20:42:51 +01:00
|
|
|
nxtask_groupexit(pgrp);
|
2013-01-26 18:28:20 +01:00
|
|
|
|
|
|
|
/* Create the siginfo structure. We don't actually know the cause.
|
2014-04-27 19:38:24 +02:00
|
|
|
* That is a bug. Let's just say that the child task just exited
|
2013-01-26 18:28:20 +01:00
|
|
|
* for now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
info.si_signo = SIGCHLD;
|
|
|
|
info.si_code = CLD_EXITED;
|
2015-08-14 18:10:32 +02:00
|
|
|
info.si_errno = OK;
|
2013-01-26 18:28:20 +01:00
|
|
|
info.si_value.sival_ptr = NULL;
|
2021-03-03 18:11:40 +01:00
|
|
|
info.si_pid = chgrp->tg_pid;
|
2013-01-26 18:28:20 +01:00
|
|
|
info.si_status = status;
|
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/* Send the signal to one thread in the group */
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
group_signal(pgrp, &info);
|
2013-01-26 18:28:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* HAVE_GROUP_MEMBERS */
|
|
|
|
|
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
|
|
|
static inline void nxtask_sigchild(FAR struct tcb_s *ptcb,
|
|
|
|
FAR struct tcb_s *ctcb, int status)
|
2013-01-12 20:58:45 +01:00
|
|
|
{
|
|
|
|
siginfo_t info;
|
|
|
|
|
2013-01-26 18:28:20 +01:00
|
|
|
/* If task groups are not supported then we will report SIGCHLD when the
|
|
|
|
* task exits. Unfortunately, there could still be threads in the group
|
|
|
|
* that are still running.
|
2013-01-23 23:23:46 +01:00
|
|
|
*/
|
2013-01-12 20:58:45 +01:00
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
|
|
|
if ((ctcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD)
|
|
|
|
#endif
|
2013-01-23 23:23:46 +01:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_SCHED_CHILD_STATUS
|
2013-01-26 21:17:29 +01:00
|
|
|
/* Save the exit status now of the main thread */
|
2013-01-13 19:53:00 +01: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 20:42:51 +01:00
|
|
|
nxtask_exitstatus(ptcb->group, status);
|
2013-01-26 18:28:20 +01:00
|
|
|
|
|
|
|
#else /* CONFIG_SCHED_CHILD_STATUS */
|
2016-09-06 16:28:31 +02:00
|
|
|
/* Exit status is not retained. Just decrement the number of
|
|
|
|
* children from this parent.
|
|
|
|
*/
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2016-09-06 16:28:31 +02:00
|
|
|
DEBUGASSERT(ptcb->group != NULL && ptcb->group->tg_nchildren > 0);
|
|
|
|
ptcb->group->tg_nchildren--;
|
2013-01-26 18:28:20 +01:00
|
|
|
|
|
|
|
#endif /* CONFIG_SCHED_CHILD_STATUS */
|
2013-01-23 23:23:46 +01:00
|
|
|
|
|
|
|
/* Create the siginfo structure. We don't actually know the cause.
|
2014-04-27 19:38:24 +02:00
|
|
|
* That is a bug. Let's just say that the child task just exited
|
2013-01-23 23:23:46 +01:00
|
|
|
* for now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
info.si_signo = SIGCHLD;
|
|
|
|
info.si_code = CLD_EXITED;
|
2015-08-14 18:10:32 +02:00
|
|
|
info.si_errno = OK;
|
2013-01-23 23:23:46 +01:00
|
|
|
info.si_value.sival_ptr = NULL;
|
2021-03-03 18:11:40 +01:00
|
|
|
info.si_pid = ctcb->group->tg_pid;
|
2013-01-23 23:23:46 +01:00
|
|
|
info.si_status = status;
|
|
|
|
|
|
|
|
/* Send the signal. We need to use this internal interface so that we
|
|
|
|
* can provide the correct si_code value with the signal.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsig_tcbdispatch(ptcb, &info);
|
2013-01-25 18:23:38 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-26 18:28:20 +01:00
|
|
|
|
|
|
|
#endif /* HAVE_GROUP_MEMBERS */
|
2019-04-29 22:52:05 +02:00
|
|
|
#else /* CONFIG_SCHED_HAVE_PARENT */
|
2013-01-26 18:28:20 +01: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 20:42:51 +01:00
|
|
|
# define nxtask_sigchild(x,ctcb,status)
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2019-04-29 22:52:05 +02:00
|
|
|
#endif /* CONFIG_SCHED_HAVE_PARENT */
|
2013-01-25 18:23:38 +01: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 20:42:51 +01:00
|
|
|
* Name: nxtask_signalparent
|
2013-01-25 18:23:38 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2020-10-29 01:12:53 +01:00
|
|
|
* Send the SIGCHLD signal to the parent task group
|
2013-01-25 18:23:38 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_HAVE_PARENT
|
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
|
|
|
static inline void nxtask_signalparent(FAR struct tcb_s *ctcb, int status)
|
2013-01-25 18:23:38 +01:00
|
|
|
{
|
2013-01-26 18:28:20 +01:00
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
|
|
|
DEBUGASSERT(ctcb && ctcb->group);
|
|
|
|
|
|
|
|
/* Keep things stationary throughout the following */
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
|
|
|
/* Send SIGCHLD to all members of the parent's task group */
|
|
|
|
|
2021-03-03 18:11:40 +01:00
|
|
|
nxtask_sigchild(ctcb->group->tg_ppid, ctcb, status);
|
2013-01-26 18:28:20 +01:00
|
|
|
sched_unlock();
|
|
|
|
#else
|
2013-02-04 19:46:28 +01:00
|
|
|
FAR struct tcb_s *ptcb;
|
2013-01-25 18:23:38 +01:00
|
|
|
|
|
|
|
/* Keep things stationary throughout the following */
|
|
|
|
|
|
|
|
sched_lock();
|
|
|
|
|
|
|
|
/* Get the TCB of the receiving, parent task. We do this early to
|
2019-08-02 16:49:26 +02:00
|
|
|
* handle multiple calls to nxtask_signalparent.
|
2013-01-25 18:23:38 +01:00
|
|
|
*/
|
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
ptcb = nxsched_get_tcb(ctcb->group->tg_ppid);
|
2016-09-06 16:28:31 +02:00
|
|
|
if (ptcb == NULL)
|
2013-01-25 18:23:38 +01:00
|
|
|
{
|
|
|
|
/* The parent no longer exists... bail */
|
|
|
|
|
2013-01-23 23:23:46 +01:00
|
|
|
sched_unlock();
|
2013-01-25 18:23:38 +01:00
|
|
|
return;
|
2013-01-23 23:23:46 +01:00
|
|
|
}
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2019-08-02 16:49:26 +02:00
|
|
|
/* Send SIGCHLD to all members of the parent's task group. NOTE that the
|
|
|
|
* SIGCHLD signal is only sent once either (1) if this is the final thread
|
|
|
|
* of the task group that is exiting (HAVE_GROUP_MEMBERS) or (2) if the
|
|
|
|
* main thread of the group is exiting (!HAVE_GROUP_MEMBERS).
|
|
|
|
*/
|
2013-01-25 18:23:38 +01: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 20:42:51 +01:00
|
|
|
nxtask_sigchild(ptcb, ctcb, status);
|
2013-01-25 18:23:38 +01:00
|
|
|
sched_unlock();
|
2013-01-26 18:28:20 +01:00
|
|
|
#endif
|
2013-01-12 20:58:45 +01:00
|
|
|
}
|
|
|
|
#else
|
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
|
|
|
# define nxtask_signalparent(ctcb,status)
|
2013-01-12 20:58:45 +01:00
|
|
|
#endif
|
|
|
|
|
2012-08-01 19:47:54 +02: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 20:42:51 +01:00
|
|
|
* Name: nxtask_exitwakeup
|
2012-08-01 19:47:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Wakeup any tasks waiting for this task to exit
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-01-13 19:53:00 +01:00
|
|
|
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
|
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
|
|
|
static inline void nxtask_exitwakeup(FAR struct tcb_s *tcb, int status)
|
2012-08-01 19:47:54 +02:00
|
|
|
{
|
2013-02-04 17:02:20 +01:00
|
|
|
FAR struct task_group_s *group = tcb->group;
|
|
|
|
|
|
|
|
/* Have we already left the group? */
|
2011-05-28 23:42:18 +02:00
|
|
|
|
2013-02-04 17:02:20 +01:00
|
|
|
if (group)
|
2011-05-28 23:42:18 +02:00
|
|
|
{
|
2013-02-04 22:24:00 +01:00
|
|
|
/* Only tasks (and kernel threads) return valid status. Record the
|
|
|
|
* exit status when the task exists. The group, however, may still
|
|
|
|
* be executing.
|
2011-05-28 23:42:18 +02:00
|
|
|
*/
|
|
|
|
|
2013-02-04 22:24:00 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
|
|
|
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD)
|
|
|
|
#endif
|
2011-05-28 23:42:18 +02:00
|
|
|
{
|
2013-02-04 17:02:20 +01:00
|
|
|
/* Report the exit status. We do not nullify tg_statloc here
|
2014-04-27 19:38:24 +02:00
|
|
|
* because we want to prevent other tasks from registering for
|
2013-02-04 17:02:20 +01:00
|
|
|
* the return status. There is only one task per task group,
|
|
|
|
* there for, this logic should execute exactly once in the
|
|
|
|
* lifetime of the task group.
|
|
|
|
*
|
|
|
|
* "If more than one thread is suspended in waitpid() awaiting
|
|
|
|
* termination of the same process, exactly one thread will
|
2013-04-24 00:41:43 +02:00
|
|
|
* return the process status at the time of the target process
|
|
|
|
* termination."
|
2013-02-04 17:02:20 +01:00
|
|
|
*
|
|
|
|
* Hmmm.. what do we return to the others?
|
|
|
|
*/
|
|
|
|
|
2022-04-22 17:14:05 +02:00
|
|
|
if (group->tg_statloc != NULL)
|
2013-02-04 17:02:20 +01:00
|
|
|
{
|
|
|
|
*group->tg_statloc = status << 8;
|
|
|
|
}
|
2011-05-28 23:42:18 +02:00
|
|
|
}
|
|
|
|
|
2013-02-04 17:02:20 +01:00
|
|
|
/* Is this the last thread in the group? */
|
2011-05-28 23:42:18 +02:00
|
|
|
|
2013-02-04 17:02:20 +01:00
|
|
|
if (group->tg_nmembers == 1)
|
|
|
|
{
|
|
|
|
/* Yes.. Wakeup any tasks waiting for this task to exit */
|
|
|
|
|
2018-09-02 21:51:52 +02:00
|
|
|
group->tg_statloc = NULL;
|
|
|
|
group->tg_waitflags = 0;
|
|
|
|
|
2015-10-08 03:59:14 +02:00
|
|
|
while (group->tg_exitsem.semcount < 0)
|
2013-04-24 00:41:43 +02:00
|
|
|
{
|
2013-02-04 17:02:20 +01:00
|
|
|
/* Wake up the thread */
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&group->tg_exitsem);
|
2013-02-04 17:02:20 +01:00
|
|
|
}
|
|
|
|
}
|
2011-05-28 23:42:18 +02:00
|
|
|
}
|
2012-08-01 19:47:54 +02:00
|
|
|
}
|
|
|
|
#else
|
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
|
|
|
# define nxtask_exitwakeup(tcb, status)
|
2011-05-28 23:42:18 +02:00
|
|
|
#endif
|
2012-08-01 19:47:54 +02:00
|
|
|
|
2013-04-18 19:41:11 +02: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 20:42:51 +01:00
|
|
|
* Name: nxtask_flushstreams
|
2013-04-18 19:41:11 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Flush all streams when the final thread of a group exits.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-08-13 12:17:29 +02:00
|
|
|
#ifdef CONFIG_FILE_STREAM
|
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
|
|
|
static inline void nxtask_flushstreams(FAR struct tcb_s *tcb)
|
2013-04-18 19:41:11 +02:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2020-04-29 21:21:23 +02:00
|
|
|
#ifdef CONFIG_MM_KERNEL_HEAP
|
2020-01-02 17:49:34 +01:00
|
|
|
lib_flushall(tcb->group->tg_streamlist);
|
2013-04-18 19:41:11 +02:00
|
|
|
#else
|
2020-01-02 17:49:34 +01:00
|
|
|
lib_flushall(&tcb->group->tg_streamlist);
|
2013-04-18 19:41:11 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
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
|
|
|
# define nxtask_flushstreams(tcb)
|
2013-04-18 19:41:11 +02:00
|
|
|
#endif
|
|
|
|
|
2012-08-01 19:47:54 +02: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_exithook
|
2012-08-01 19:47:54 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function implements some of the internal logic of exit() and
|
2014-04-27 19:38:24 +02:00
|
|
|
* task_delete(). This function performs some clean-up and other actions
|
2013-02-04 16:29:19 +01:00
|
|
|
* required when a task exits:
|
2012-08-01 19:47:54 +02:00
|
|
|
*
|
|
|
|
* - All open streams are flushed and closed.
|
|
|
|
* - All functions registered with atexit() and on_exit() are called, in
|
|
|
|
* the reverse order of their registration.
|
|
|
|
*
|
|
|
|
* When called from exit(), the tcb still resides at the head of the ready-
|
|
|
|
* to-run list. The following logic is safe because we will not be
|
|
|
|
* returning from the exit() call.
|
|
|
|
*
|
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
|
|
|
* When called from nxtask_terminate() we are operating on a different
|
|
|
|
* thread; on the thread that called task_delete(). In this case,
|
|
|
|
* task_delete will have already removed the tcb from the ready-to-run
|
|
|
|
* list to prevent any further action on this task.
|
2012-08-01 19:47:54 +02: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 20:42:51 +01:00
|
|
|
* nonblocking will be set true only when we are called from
|
|
|
|
* nxtask_terminate() via _exit(). In that case, we must be careful to do
|
|
|
|
* nothing that can cause the cause the thread to block.
|
2013-04-24 00:41:43 +02:00
|
|
|
*
|
2012-08-01 19:47:54 +02: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 20:42:51 +01:00
|
|
|
void nxtask_exithook(FAR struct tcb_s *tcb, int status, bool nonblocking)
|
2012-08-01 19:47:54 +02:00
|
|
|
{
|
2020-03-08 13:51:34 +01:00
|
|
|
/* Under certain conditions, nxtask_exithook() can be called multiple
|
|
|
|
* times. A bit in the TCB was set the first time this function was
|
|
|
|
* called. If that bit is set, then just exit doing nothing more..
|
2013-01-26 18:28:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ((tcb->flags & TCB_FLAG_EXIT_PROCESSING) != 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-09 19:01:18 +01:00
|
|
|
#ifdef CONFIG_CANCELLATION_POINTS
|
2017-08-15 01:19:27 +02:00
|
|
|
/* Mark the task as non-cancelable to avoid additional calls to exit()
|
|
|
|
* due to any cancellation point logic that might get kicked off by
|
|
|
|
* actions taken during exit processing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tcb->flags |= TCB_FLAG_NONCANCELABLE;
|
|
|
|
tcb->flags &= ~TCB_FLAG_CANCEL_PENDING;
|
|
|
|
tcb->cpcount = 0;
|
2016-12-09 19:01:18 +01:00
|
|
|
#endif
|
|
|
|
|
2013-04-24 00:41:43 +02:00
|
|
|
if (!nonblocking)
|
|
|
|
{
|
2021-03-02 00:38:58 +01:00
|
|
|
/* If this is the last thread in the group, then flush all streams
|
|
|
|
* (File descriptors will be closed when the TCB is deallocated).
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
* 1. We cannot flush the buffered I/O if nonblocking is requested.
|
|
|
|
* that might cause this logic to block.
|
|
|
|
* 2. This function will only be called with non-blocking == true
|
|
|
|
* only when called through _exit(). _exit() behavior does not
|
|
|
|
* require that the streams be flushed
|
|
|
|
*/
|
|
|
|
|
|
|
|
nxtask_flushstreams(tcb);
|
|
|
|
}
|
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/* If the task was terminated by another task, it may be in an unknown
|
2013-02-06 16:43:28 +01:00
|
|
|
* state. Make some feeble effort to recover the state.
|
2013-02-05 20:50:37 +01: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 20:42:51 +01:00
|
|
|
nxtask_recover(tcb);
|
2013-02-05 20:50:37 +01:00
|
|
|
|
2020-11-12 00:45:36 +01:00
|
|
|
/* NOTE: signal handling needs to be done in a criticl section */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
irqstate_t flags = enter_critical_section();
|
|
|
|
#endif
|
|
|
|
|
2020-10-29 01:12:53 +01:00
|
|
|
/* Send the SIGCHLD signal to the parent task group */
|
2013-01-13 19:53:00 +01: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 20:42:51 +01:00
|
|
|
nxtask_signalparent(tcb, status);
|
2013-01-13 19:53:00 +01:00
|
|
|
|
2012-08-01 19:47:54 +02:00
|
|
|
/* Wakeup any tasks waiting for this task to exit */
|
|
|
|
|
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
|
|
|
nxtask_exitwakeup(tcb, status);
|
2012-08-01 19:47:54 +02:00
|
|
|
|
2013-01-25 18:23:38 +01:00
|
|
|
/* Leave the task group. Perhaps discarding any un-reaped child
|
|
|
|
* status (no zombies here!)
|
|
|
|
*/
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2013-01-25 18:23:38 +01:00
|
|
|
group_leave(tcb);
|
2013-01-23 23:23:46 +01:00
|
|
|
|
2012-02-01 00:39:12 +01:00
|
|
|
/* Deallocate anything left in the TCB's queues */
|
|
|
|
|
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_
This is analogous to similar renaming that was done previously for semaphores.
Squashed commit of the following:
sched/signal: Fix a few compile warnings introduced by naming changes.
sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix.
sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces.
sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
|
|
|
nxsig_cleanup(tcb); /* Deallocate Signal lists */
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2022-10-28 05:42:13 +02:00
|
|
|
#ifdef CONFIG_SCHED_DUMP_LEAK
|
|
|
|
if ((tcb->cmn.flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL)
|
|
|
|
{
|
|
|
|
kmm_memdump(tcb->pid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
umm_memdump(tcb->pid);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-11-12 00:45:36 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
leave_critical_section(flags);
|
|
|
|
#endif
|
|
|
|
|
2013-01-26 18:28:20 +01:00
|
|
|
/* This function can be re-entered in certain cases. Set a flag
|
|
|
|
* bit in the TCB to not that we have already completed this exit
|
|
|
|
* processing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tcb->flags |= TCB_FLAG_EXIT_PROCESSING;
|
2011-05-28 23:42:18 +02:00
|
|
|
}
|