From 7cb1f3b3c008e4d16861b9ee214c7c8c5d445fbe Mon Sep 17 00:00:00 2001 From: chao an Date: Tue, 5 Mar 2024 10:23:30 +0800 Subject: [PATCH] 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 --- sched/group/CMakeLists.txt | 1 - sched/group/Make.defs | 2 +- sched/group/group.h | 10 ----- sched/group/group_create.c | 18 -------- sched/group/group_find.c | 87 ------------------------------------- sched/group/group_leave.c | 65 --------------------------- sched/signal/sig_dispatch.c | 2 +- sched/task/task_exithook.c | 2 +- sched/task/task_getgroup.c | 3 +- sched/task/task_reparent.c | 4 +- 10 files changed, 6 insertions(+), 188 deletions(-) delete mode 100644 sched/group/group_find.c diff --git a/sched/group/CMakeLists.txt b/sched/group/CMakeLists.txt index 0f6bc8b22a..3ec2de2a9e 100644 --- a/sched/group/CMakeLists.txt +++ b/sched/group/CMakeLists.txt @@ -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 diff --git a/sched/group/Make.defs b/sched/group/Make.defs index 7115c6fa29..e7f773de34 100644 --- a/sched/group/Make.defs +++ b/sched/group/Make.defs @@ -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 diff --git a/sched/group/group.h b/sched/group/group.h index 839e4e2710..cfb3436808 100644 --- a/sched/group/group.h +++ b/sched/group/group.h @@ -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); diff --git a/sched/group/group_create.c b/sched/group/group_create.c index 735d39b72e..c14660f6c7 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -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 } diff --git a/sched/group/group_find.c b/sched/group/group_find.c deleted file mode 100644 index 822ee91d31..0000000000 --- a/sched/group/group_find.c +++ /dev/null @@ -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 - -#include -#include -#include -#include - -#include -#include -#include - -#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 diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index 6dfef6c1cc..89f8e6ee68 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -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 */ diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index d910fb0904..e261b52b3c 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -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? */ diff --git a/sched/task/task_exithook.c b/sched/task/task_exithook.c index ca1a7ef2da..b8afa5e977 100644 --- a/sched/task/task_exithook.c +++ b/sched/task/task_exithook.c @@ -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 diff --git a/sched/task/task_getgroup.c b/sched/task/task_getgroup.c index dbf003d9ba..cd79cc4f96 100644 --- a/sched/task/task_getgroup.c +++ b/sched/task/task_getgroup.c @@ -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. * ****************************************************************************/ diff --git a/sched/task/task_reparent.c b/sched/task/task_reparent.c index e6c725332e..60662a1b31 100644 --- a/sched/task/task_reparent.c +++ b/sched/task/task_reparent.c @@ -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 {