sched/group: replace group_findbypid to task_getgroup
Task group could find from process id, replace group_findbypid to task_getgroup to simplify the search logic Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
parent
dfd1e38b40
commit
7cb1f3b3c0
10 changed files with 6 additions and 188 deletions
|
@ -22,7 +22,6 @@ set(SRCS
|
|||
group_create.c
|
||||
group_join.c
|
||||
group_leave.c
|
||||
group_find.c
|
||||
group_setupidlefiles.c
|
||||
group_setuptaskfiles.c
|
||||
group_foreachchild.c
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#
|
||||
############################################################################
|
||||
|
||||
CSRCS += group_create.c group_join.c group_leave.c group_find.c
|
||||
CSRCS += group_create.c group_join.c group_leave.c
|
||||
CSRCS += group_setupidlefiles.c group_setuptaskfiles.c
|
||||
CSRCS += group_foreachchild.c group_killchildren.c group_signal.c
|
||||
CSRCS += group_argvstr.c
|
||||
|
|
|
@ -44,12 +44,6 @@ typedef int (*foreachchild_t)(pid_t pid, FAR void *arg);
|
|||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(HAVE_GROUP_MEMBERS)
|
||||
/* This is the head of a list of all group members */
|
||||
|
||||
extern FAR struct task_group_s *g_grouphead;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
@ -75,10 +69,6 @@ void group_add_waiter(FAR struct task_group_s *group);
|
|||
void group_del_waiter(FAR struct task_group_s *group);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_GROUP_MEMBERS)
|
||||
FAR struct task_group_s *group_findbypid(pid_t pid);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GROUP_MEMBERS
|
||||
int group_foreachchild(FAR struct task_group_s *group,
|
||||
foreachchild_t handler, FAR void *arg);
|
||||
|
|
|
@ -51,12 +51,6 @@
|
|||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(HAVE_GROUP_MEMBERS)
|
||||
/* This is the head of a list of all group members */
|
||||
|
||||
FAR struct task_group_s *g_grouphead;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
@ -234,9 +228,6 @@ errout_with_group:
|
|||
void group_initialize(FAR struct task_tcb_s *tcb)
|
||||
{
|
||||
FAR struct task_group_s *group;
|
||||
#if defined(HAVE_GROUP_MEMBERS)
|
||||
irqstate_t flags;
|
||||
#endif
|
||||
|
||||
DEBUGASSERT(tcb && tcb->cmn.group);
|
||||
group = tcb->cmn.group;
|
||||
|
@ -263,13 +254,4 @@ void group_initialize(FAR struct task_tcb_s *tcb)
|
|||
/* Mark that there is one member in the group, the main task */
|
||||
|
||||
group->tg_nmembers = 1;
|
||||
|
||||
#if defined(HAVE_GROUP_MEMBERS)
|
||||
/* Add the initialized entry to the list of groups */
|
||||
|
||||
flags = enter_critical_section();
|
||||
group->flink = g_grouphead;
|
||||
g_grouphead = group;
|
||||
leave_critical_section(flags);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
/****************************************************************************
|
||||
* sched/group/group_find.c
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
#include "group/group.h"
|
||||
#include "environ/environ.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: group_findbypid
|
||||
*
|
||||
* Description:
|
||||
* Given a task ID, find the group task structure with was started by that
|
||||
* task ID. That task's ID is retained in the group as tg_pid and will
|
||||
* be remember even if the main task thread leaves the group.
|
||||
*
|
||||
* Input Parameters:
|
||||
* pid - The task ID of the main task thread.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a pointer to the group task structure is returned. This
|
||||
* function can fail only if there is no group that corresponds to the
|
||||
* task ID.
|
||||
*
|
||||
* Assumptions:
|
||||
* Called during when signally tasks in a safe context. No special
|
||||
* precautions should be required here. However, extra care is taken when
|
||||
* accessing the global g_grouphead list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(HAVE_GROUP_MEMBERS)
|
||||
FAR struct task_group_s *group_findbypid(pid_t pid)
|
||||
{
|
||||
FAR struct task_group_s *group;
|
||||
irqstate_t flags;
|
||||
|
||||
/* Find the status structure with the matching PID */
|
||||
|
||||
flags = enter_critical_section();
|
||||
for (group = g_grouphead; group; group = group->flink)
|
||||
{
|
||||
if (group->tg_pid == pid)
|
||||
{
|
||||
leave_critical_section(flags);
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
|
@ -49,65 +49,6 @@
|
|||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: group_remove
|
||||
*
|
||||
* Description:
|
||||
* Remove a group from the list of groups.
|
||||
*
|
||||
* Input Parameters:
|
||||
* group - The group to be removed.
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
* Assumptions:
|
||||
* Called during task deletion in a safe context. No special precautions
|
||||
* are required here.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(HAVE_GROUP_MEMBERS)
|
||||
static void group_remove(FAR struct task_group_s *group)
|
||||
{
|
||||
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.
|
||||
*/
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: group_release
|
||||
*
|
||||
|
@ -164,12 +105,6 @@ static inline void group_release(FAR struct task_group_s *group)
|
|||
|
||||
mm_map_destroy(&group->tg_mm_map);
|
||||
|
||||
#if defined(HAVE_GROUP_MEMBERS)
|
||||
/* Remove the group from the list of groups */
|
||||
|
||||
group_remove(group);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GROUP_MEMBERS
|
||||
/* Release the members array */
|
||||
|
||||
|
|
|
@ -614,7 +614,7 @@ int nxsig_dispatch(pid_t pid, FAR siginfo_t *info)
|
|||
* created the task group. Try looking it up.
|
||||
*/
|
||||
|
||||
group = group_findbypid(pid);
|
||||
group = task_getgroup(pid);
|
||||
}
|
||||
|
||||
/* Did we locate the group? */
|
||||
|
|
|
@ -147,7 +147,7 @@ static inline void nxtask_sigchild(pid_t ppid, FAR struct tcb_s *ctcb,
|
|||
* this case, the child task group has been orphaned.
|
||||
*/
|
||||
|
||||
pgrp = group_findbypid(ppid);
|
||||
pgrp = task_getgroup(ppid);
|
||||
if (!pgrp)
|
||||
{
|
||||
/* Set the task group ID to an invalid group ID. The dead parent
|
||||
|
|
|
@ -50,8 +50,7 @@
|
|||
*
|
||||
* Assumptions:
|
||||
* Called during when signally tasks in a safe context. No special
|
||||
* precautions should be required here. However, extra care is taken when
|
||||
* accessing the global g_grouphead list.
|
||||
* precautions should be required here.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
|||
|
||||
/* Get the old parent task's task group (ogrp) */
|
||||
|
||||
ogrp = group_findbypid(opid);
|
||||
ogrp = task_getgroup(opid);
|
||||
if (!ogrp)
|
||||
{
|
||||
ret = -ESRCH;
|
||||
|
@ -111,7 +111,7 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
|||
/* Get the grandparent task's task group (pgrp) */
|
||||
|
||||
ppid = ogrp->tg_ppid;
|
||||
pgrp = group_findbypid(ppid);
|
||||
pgrp = task_getgroup(ppid);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue