2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2014-08-08 22:06:42 +02:00
|
|
|
* sched/group/group_leave.c
|
2013-01-25 18:23:38 +01:00
|
|
|
*
|
2019-08-02 18:01:30 +02:00
|
|
|
* Copyright (C) 2013-2019 Gregory Nutt. All rights reserved.
|
2013-01-25 18:23:38 +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.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-25 18:23:38 +01:00
|
|
|
* Included Files
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sched.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2013-01-27 00:49:02 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include <nuttx/net/net.h>
|
2016-07-21 22:05:44 +02:00
|
|
|
#include <nuttx/lib/lib.h>
|
2013-01-27 00:49:02 +01:00
|
|
|
|
2018-08-05 16:09:54 +02:00
|
|
|
#ifdef CONFIG_BINFMT_LOADABLE
|
|
|
|
# include <nuttx/binfmt/binfmt.h>
|
|
|
|
#endif
|
|
|
|
|
2014-08-08 21:53:29 +02:00
|
|
|
#include "environ/environ.h"
|
2014-08-08 20:44:44 +02:00
|
|
|
#include "signal/signal.h"
|
2014-08-08 20:55:02 +02:00
|
|
|
#include "pthread/pthread.h"
|
2014-08-08 20:31:23 +02:00
|
|
|
#include "mqueue/mqueue.h"
|
2014-08-08 22:06:42 +02:00
|
|
|
#include "group/group.h"
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-25 18:23:38 +01:00
|
|
|
* Private Functions
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-26 18:28:20 +01:00
|
|
|
* Name: group_remove
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Remove a group from the list of groups.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-01-26 18:28:20 +01:00
|
|
|
* group - The group to be removed.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-01-26 18:28:20 +01:00
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called during task deletion in a safe context. No special precautions
|
|
|
|
* are required here.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2014-08-26 22:54:39 +02:00
|
|
|
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
|
|
|
static void group_remove(FAR struct task_group_s *group)
|
2013-01-26 18:28:20 +01:00
|
|
|
{
|
|
|
|
FAR struct task_group_s *curr;
|
|
|
|
FAR struct task_group_s *prev;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Let's be especially careful while access the global task group list.
|
|
|
|
* This is probably un-necessary.
|
|
|
|
*/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2013-01-26 18:28:20 +01:00
|
|
|
/* Find the task group structure */
|
|
|
|
|
|
|
|
for (prev = NULL, curr = g_grouphead;
|
|
|
|
curr && curr != group;
|
|
|
|
prev = curr, curr = curr->flink);
|
|
|
|
|
|
|
|
/* Did we find it? If so, remove it from the list. */
|
|
|
|
|
|
|
|
if (curr)
|
|
|
|
{
|
|
|
|
/* Do we remove it from mid-list? Or from the head of the list? */
|
|
|
|
|
|
|
|
if (prev)
|
|
|
|
{
|
|
|
|
prev->flink = curr->flink;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_grouphead = curr->flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
curr->flink = NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2013-01-26 18:28:20 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-26 22:01:19 +01:00
|
|
|
* Name: group_release
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release group resources after the last member has left the group.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-01-26 22:01:19 +01:00
|
|
|
* group - The group to be removed.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-01-26 22:01:19 +01:00
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called during task deletion in a safe context. No special precautions
|
|
|
|
* are required here.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-26 22:01:19 +01:00
|
|
|
|
2013-01-27 00:49:02 +01:00
|
|
|
static inline void group_release(FAR struct task_group_s *group)
|
2013-01-26 22:01:19 +01:00
|
|
|
{
|
2019-06-02 19:05:31 +02:00
|
|
|
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
|
2013-01-26 22:01:19 +01:00
|
|
|
/* Free all un-reaped child exit status */
|
|
|
|
|
|
|
|
group_removechildren(group);
|
|
|
|
#endif
|
|
|
|
|
2013-02-05 20:50:37 +01:00
|
|
|
/* Release pending signals */
|
|
|
|
|
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_release(group);
|
2013-02-05 20:50:37 +01:00
|
|
|
|
2013-02-03 17:43:58 +01:00
|
|
|
#ifndef CONFIG_DISABLE_PTHREAD
|
2013-02-03 18:39:54 +01:00
|
|
|
/* Release pthread resources */
|
|
|
|
|
|
|
|
pthread_release(group);
|
2013-02-03 17:43:58 +01:00
|
|
|
#endif
|
|
|
|
|
2013-01-26 22:01:19 +01:00
|
|
|
/* Free all file-related resources now. We really need to close files as
|
|
|
|
* soon as possible while we still have a functioning task.
|
|
|
|
*/
|
|
|
|
|
2013-01-27 00:49:02 +01:00
|
|
|
/* Free resources held by the file descriptor list */
|
|
|
|
|
|
|
|
files_releaselist(&group->tg_filelist);
|
|
|
|
|
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
|
|
|
/* Free resource held by the stream list */
|
|
|
|
|
2014-09-11 16:37:06 +02:00
|
|
|
lib_stream_release(group);
|
2013-01-27 00:49:02 +01:00
|
|
|
#endif /* CONFIG_NFILE_STREAMS */
|
|
|
|
|
2019-02-11 22:47:25 +01:00
|
|
|
#ifdef CONFIG_NET
|
2013-01-27 00:49:02 +01:00
|
|
|
/* Free resource held by the socket list */
|
|
|
|
|
|
|
|
net_releaselist(&group->tg_socketlist);
|
2019-02-11 22:47:25 +01:00
|
|
|
#endif
|
2013-01-26 22:01:19 +01:00
|
|
|
|
2014-08-22 22:49:05 +02:00
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
2013-01-26 22:01:19 +01:00
|
|
|
/* Release all shared environment variables */
|
|
|
|
|
2013-01-27 00:49:02 +01:00
|
|
|
env_release(group);
|
2013-01-26 22:01:19 +01:00
|
|
|
#endif
|
|
|
|
|
2014-08-22 22:49:05 +02:00
|
|
|
#ifndef CONFIG_DISABLE_MQUEUE
|
2013-02-04 17:55:38 +01:00
|
|
|
/* Close message queues opened by members of the group */
|
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
nxmq_release(group);
|
2013-02-04 17:55:38 +01:00
|
|
|
#endif
|
|
|
|
|
2014-09-24 00:04:39 +02:00
|
|
|
#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_MM_SHM)
|
|
|
|
/* Release any resource held by shared memory virtual page allocator */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
shm_group_release(group);
|
2014-09-24 00:04:39 +02:00
|
|
|
#endif
|
|
|
|
|
2014-08-24 14:42:11 +02:00
|
|
|
#ifdef CONFIG_ARCH_ADDRENV
|
2014-08-22 22:49:05 +02:00
|
|
|
/* Destroy the group address environment */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
up_addrenv_destroy(&group->tg_addrenv);
|
2014-08-27 17:37:28 +02:00
|
|
|
|
|
|
|
/* Mark no address environment */
|
|
|
|
|
2019-08-02 18:01:30 +02:00
|
|
|
g_grpid_current = 0;
|
2014-08-22 22:49:05 +02:00
|
|
|
#endif
|
|
|
|
|
2014-08-26 22:54:39 +02:00
|
|
|
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
2013-01-26 22:01:19 +01:00
|
|
|
/* Remove the group from the list of groups */
|
|
|
|
|
|
|
|
group_remove(group);
|
2014-08-26 22:54:39 +02:00
|
|
|
#endif
|
2013-01-26 22:01:19 +01:00
|
|
|
|
2014-08-26 22:54:39 +02:00
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
2013-01-26 22:01:19 +01:00
|
|
|
/* Release the members array */
|
|
|
|
|
|
|
|
if (group->tg_members)
|
|
|
|
{
|
2013-03-10 16:32:33 +01:00
|
|
|
sched_kfree(group->tg_members);
|
2013-01-26 22:01:19 +01:00
|
|
|
group->tg_members = NULL;
|
|
|
|
}
|
2013-01-26 23:25:21 +01:00
|
|
|
#endif
|
2013-01-26 22:01:19 +01:00
|
|
|
|
2014-09-11 23:56:04 +02:00
|
|
|
#if CONFIG_NFILE_STREAMS > 0 && defined(CONFIG_MM_KERNEL_HEAP)
|
2013-03-11 14:21:33 +01:00
|
|
|
/* In a flat, single-heap build. The stream list is part of the
|
2014-09-11 23:56:04 +02:00
|
|
|
* group structure and, hence will be freed when the group structure
|
|
|
|
* is freed. Otherwise, it is separately allocated an must be
|
|
|
|
* freed here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
# if defined(CONFIG_BUILD_PROTECTED)
|
|
|
|
/* In the protected build, the task's stream list is always allocated
|
|
|
|
* and freed from the single, global user allocator.
|
2013-03-11 14:21:33 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
sched_ufree(group->tg_streamlist);
|
2014-09-11 23:56:04 +02:00
|
|
|
|
|
|
|
# elif defined(CONFIG_BUILD_KERNEL)
|
2020-02-23 09:50:23 +01:00
|
|
|
/* In the kernel build, the unprivileged process's stream list will be
|
2014-09-11 23:56:04 +02:00
|
|
|
* allocated from with its per-process, private user heap. But in that
|
|
|
|
* case, there is no reason to do anything here: That allocation resides
|
|
|
|
* in the user heap which which be completely freed when we destroy the
|
2020-02-23 09:50:23 +01:00
|
|
|
* process's address environment.
|
2014-09-11 23:56:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if ((group->tg_flags & GROUP_FLAG_PRIVILEGED) != 0)
|
|
|
|
{
|
|
|
|
/* But kernel threads are different in this build configuration: Their
|
|
|
|
* stream lists were allocated from the common, global kernel heap and
|
|
|
|
* must explicitly freed here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sched_kfree(group->tg_streamlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
# endif
|
2013-03-11 14:21:33 +01:00
|
|
|
#endif
|
|
|
|
|
2018-08-05 16:09:54 +02:00
|
|
|
#ifdef CONFIG_BINFMT_LOADABLE
|
|
|
|
/* If the exiting task was loaded into RAM from a file, then we need to
|
|
|
|
* lease all of the memory resource when the last thread exits the task
|
|
|
|
* group.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (group->tg_bininfo != NULL)
|
|
|
|
{
|
|
|
|
binfmt_exit(group->tg_bininfo);
|
|
|
|
group->tg_bininfo = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-22 18:48:17 +01:00
|
|
|
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
|
|
|
|
/* If there are threads waiting for this group to be freed, then we cannot
|
|
|
|
* yet free the memory resources. Instead just mark the group deleted
|
|
|
|
* and wait for those threads complete their waits.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (group->tg_nwaiters > 0)
|
|
|
|
{
|
|
|
|
group->tg_flags |= GROUP_FLAG_DELETED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Release the group container itself */
|
2013-01-26 22:01:19 +01:00
|
|
|
|
2015-12-22 18:48:17 +01:00
|
|
|
sched_kfree(group);
|
|
|
|
}
|
2013-01-26 22:01:19 +01:00
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-02-05 20:50:37 +01:00
|
|
|
* Name: group_removemember
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Remove a member from a group.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-02-05 20:50:37 +01:00
|
|
|
* group - The group from which to remove the member.
|
|
|
|
* pid - The member to be removed.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-02-05 20:50:37 +01:00
|
|
|
* On success, returns the number of members remaining in the group (>=0).
|
|
|
|
* Can fail only if the member is not found in the group. On failure,
|
|
|
|
* returns -ENOENT
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called during task deletion and also from the reparenting logic, both
|
|
|
|
* in a safe context. No special precautions are required here.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-02-05 20:50:37 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
2013-02-26 01:56:59 +01:00
|
|
|
static inline void group_removemember(FAR struct task_group_s *group, pid_t pid)
|
2013-02-05 20:50:37 +01:00
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DEBUGASSERT(group);
|
|
|
|
|
|
|
|
/* Find the member in the array of members and remove it */
|
|
|
|
|
|
|
|
for (i = 0; i < group->tg_nmembers; i++)
|
|
|
|
{
|
|
|
|
/* Does this member have the matching pid */
|
|
|
|
|
|
|
|
if (group->tg_members[i] == pid)
|
2015-10-08 03:59:14 +02:00
|
|
|
{
|
2013-02-06 16:43:28 +01:00
|
|
|
/* Remove the member from the array of members. This must be an
|
|
|
|
* atomic operation because the member array may be accessed from
|
|
|
|
* interrupt handlers (read-only).
|
2013-02-05 20:50:37 +01:00
|
|
|
*/
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2013-02-06 16:43:28 +01:00
|
|
|
group->tg_members[i] = group->tg_members[group->tg_nmembers - 1];
|
|
|
|
group->tg_nmembers--;
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2013-02-06 16:43:28 +01:00
|
|
|
}
|
2013-02-05 20:50:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_GROUP_MEMBERS */
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-25 18:23:38 +01:00
|
|
|
* Public Functions
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-01-25 18:23:38 +01:00
|
|
|
* Name: group_leave
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release a reference on a group. This function is called when a task or
|
|
|
|
* thread exits. It decrements the reference count on the group. If the
|
|
|
|
* reference count decrements to zero, then it frees the group and all of
|
|
|
|
* resources contained in the group.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-01-25 18:23:38 +01:00
|
|
|
* tcb - The TCB of the task that is exiting.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-01-25 18:23:38 +01:00
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called during task deletion in a safe context. No special precautions
|
|
|
|
* are required here.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2013-01-26 18:28:20 +01:00
|
|
|
#ifdef HAVE_GROUP_MEMBERS
|
2013-02-04 19:46:28 +01:00
|
|
|
void group_leave(FAR struct tcb_s *tcb)
|
2013-01-25 18:23:38 +01:00
|
|
|
{
|
|
|
|
FAR struct task_group_s *group;
|
|
|
|
|
|
|
|
DEBUGASSERT(tcb);
|
|
|
|
|
2013-02-26 01:56:59 +01:00
|
|
|
/* Make sure that we have a group. */
|
2013-01-25 18:23:38 +01:00
|
|
|
|
|
|
|
group = tcb->group;
|
|
|
|
if (group)
|
|
|
|
{
|
2013-02-26 01:56:59 +01:00
|
|
|
/* Remove the member from group. This function may be called
|
|
|
|
* during certain error handling before the PID has been
|
|
|
|
* added to the group. In this case tcb->pid will be uninitialized
|
|
|
|
* group_removemember() will fail.
|
|
|
|
*/
|
2013-01-26 00:21:27 +01:00
|
|
|
|
2013-02-26 01:56:59 +01:00
|
|
|
group_removemember(group, tcb->pid);
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2013-02-26 01:56:59 +01:00
|
|
|
/* Have all of the members left the group? */
|
2013-01-25 20:15:05 +01:00
|
|
|
|
2013-02-26 01:56:59 +01:00
|
|
|
if (group->tg_nmembers == 0)
|
2013-01-25 20:15:05 +01:00
|
|
|
{
|
2013-02-26 01:56:59 +01:00
|
|
|
/* Yes.. Release all of the resource held by the task group */
|
2013-01-26 18:28:20 +01:00
|
|
|
|
2013-01-27 00:49:02 +01:00
|
|
|
group_release(group);
|
2013-01-25 20:15:05 +01:00
|
|
|
}
|
2013-01-26 18:28:20 +01:00
|
|
|
|
|
|
|
/* In any event, we can detach the group from the TCB so that we won't
|
|
|
|
* do this again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tcb->group = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* HAVE_GROUP_MEMBERS */
|
|
|
|
|
2013-02-04 19:46:28 +01:00
|
|
|
void group_leave(FAR struct tcb_s *tcb)
|
2013-01-26 18:28:20 +01:00
|
|
|
{
|
|
|
|
FAR struct task_group_s *group;
|
|
|
|
|
|
|
|
DEBUGASSERT(tcb);
|
|
|
|
|
|
|
|
/* Make sure that we have a group */
|
|
|
|
|
|
|
|
group = tcb->group;
|
|
|
|
if (group)
|
|
|
|
{
|
|
|
|
/* Yes, we have a group.. Is this the last member of the group? */
|
2013-01-25 20:15:05 +01:00
|
|
|
|
|
|
|
if (group->tg_nmembers > 1)
|
|
|
|
{
|
|
|
|
/* No.. just decrement the number of members in the group */
|
|
|
|
|
|
|
|
group->tg_nmembers--;
|
2013-01-25 18:23:38 +01:00
|
|
|
}
|
2013-01-25 20:15:05 +01:00
|
|
|
|
|
|
|
/* Yes.. that was the last member remaining in the group */
|
|
|
|
|
2013-01-25 18:23:38 +01:00
|
|
|
else
|
|
|
|
{
|
2013-01-26 22:01:19 +01:00
|
|
|
/* Release all of the resource held by the task group */
|
2013-01-25 18:23:38 +01:00
|
|
|
|
2013-01-27 00:49:02 +01:00
|
|
|
group_release(group);
|
2013-01-25 18:23:38 +01:00
|
|
|
}
|
2013-01-25 20:15:05 +01:00
|
|
|
|
|
|
|
/* In any event, we can detach the group from the TCB so we won't do
|
|
|
|
* this again.
|
|
|
|
*/
|
2013-01-25 18:23:38 +01:00
|
|
|
|
|
|
|
tcb->group = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-26 18:28:20 +01:00
|
|
|
#endif /* HAVE_GROUP_MEMBERS */
|