mirror of
https://github.com/apache/nuttx.git
synced 2026-09-12 13:40:14 +00:00
sched: Remove all group id related stuff
it is wrong to define a new grpid_t, but not reuse pid_t, because it make getpid(parent) == getppid(child) impossible. Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
0a797f1e8b
commit
90be95bb89
13 changed files with 43 additions and 294 deletions
|
|
@ -62,18 +62,6 @@
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* See include/nuttx/sched.h: */
|
|
||||||
|
|
||||||
#undef HAVE_GROUPID
|
|
||||||
|
|
||||||
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
|
|
||||||
# define HAVE_GROUPID 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_DISABLE_PTHREAD
|
|
||||||
# undef HAVE_GROUPID
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Determines the size of an intermediate buffer that must be large enough
|
/* Determines the size of an intermediate buffer that must be large enough
|
||||||
* to handle the longest line generated by this logic.
|
* to handle the longest line generated by this logic.
|
||||||
*/
|
*/
|
||||||
|
|
@ -453,9 +441,7 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile,
|
||||||
FAR struct tcb_s *tcb, FAR char *buffer,
|
FAR struct tcb_s *tcb, FAR char *buffer,
|
||||||
size_t buflen, off_t offset)
|
size_t buflen, off_t offset)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
FAR struct task_group_s *group;
|
FAR struct task_group_s *group;
|
||||||
#endif
|
|
||||||
FAR const char *policy;
|
FAR const char *policy;
|
||||||
FAR const char *name;
|
FAR const char *name;
|
||||||
size_t remaining;
|
size_t remaining;
|
||||||
|
|
@ -504,18 +490,11 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile,
|
||||||
return totalsize;
|
return totalsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
group = tcb->group;
|
group = tcb->group;
|
||||||
DEBUGASSERT(group != NULL);
|
DEBUGASSERT(group != NULL);
|
||||||
|
|
||||||
#ifdef HAVE_GROUPID
|
|
||||||
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n",
|
|
||||||
"Group:", group->tg_pgrpid);
|
|
||||||
#else
|
|
||||||
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "PPID:",
|
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "PPID:",
|
||||||
group->tg_ppid);
|
group->tg_ppid);
|
||||||
#endif
|
|
||||||
|
|
||||||
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
|
||||||
&offset);
|
&offset);
|
||||||
|
|
||||||
|
|
@ -527,7 +506,6 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile,
|
||||||
{
|
{
|
||||||
return totalsize;
|
return totalsize;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_SMP
|
#ifdef CONFIG_SMP
|
||||||
if (tcb->task_state >= FIRST_ASSIGNED_STATE &&
|
if (tcb->task_state >= FIRST_ASSIGNED_STATE &&
|
||||||
|
|
@ -946,11 +924,8 @@ static ssize_t proc_groupstatus(FAR struct proc_file_s *procfile,
|
||||||
remaining = buflen;
|
remaining = buflen;
|
||||||
totalsize = 0;
|
totalsize = 0;
|
||||||
|
|
||||||
/* Show the group IDs */
|
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
|
||||||
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n",
|
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n",
|
||||||
"Group ID:", group->tg_grpid);
|
"Main task:", group->tg_pid);
|
||||||
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
||||||
remaining, &offset);
|
remaining, &offset);
|
||||||
|
|
||||||
|
|
@ -963,37 +938,6 @@ static ssize_t proc_groupstatus(FAR struct proc_file_s *procfile,
|
||||||
return totalsize;
|
return totalsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n",
|
|
||||||
"Parent ID:", group->tg_pgrpid);
|
|
||||||
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
||||||
remaining, &offset);
|
|
||||||
|
|
||||||
totalsize += copysize;
|
|
||||||
buffer += copysize;
|
|
||||||
remaining -= copysize;
|
|
||||||
|
|
||||||
if (totalsize >= buflen)
|
|
||||||
{
|
|
||||||
return totalsize;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SCHED_HAVE_PARENT)
|
|
||||||
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n",
|
|
||||||
"Main task:", group->tg_task);
|
|
||||||
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
|
||||||
remaining, &offset);
|
|
||||||
|
|
||||||
totalsize += copysize;
|
|
||||||
buffer += copysize;
|
|
||||||
remaining -= copysize;
|
|
||||||
|
|
||||||
if (totalsize >= buflen)
|
|
||||||
{
|
|
||||||
return totalsize;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s0x%02x\n",
|
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s0x%02x\n",
|
||||||
"Flags:", group->tg_flags);
|
"Flags:", group->tg_flags);
|
||||||
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
||||||
|
|
|
||||||
|
|
@ -362,12 +362,6 @@ struct pthread_cleanup_s
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* type grpid_t *****************************************************************/
|
|
||||||
|
|
||||||
/* The task group ID */
|
|
||||||
|
|
||||||
typedef int16_t grpid_t;
|
|
||||||
|
|
||||||
/* struct dspace_s **************************************************************/
|
/* struct dspace_s **************************************************************/
|
||||||
|
|
||||||
/* This structure describes a reference counted D-Space region. This must be a
|
/* This structure describes a reference counted D-Space region. This must be a
|
||||||
|
|
@ -466,14 +460,9 @@ struct task_group_s
|
||||||
{
|
{
|
||||||
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
||||||
struct task_group_s *flink; /* Supports a singly linked list */
|
struct task_group_s *flink; /* Supports a singly linked list */
|
||||||
grpid_t tg_grpid; /* The ID of this task group */
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
|
||||||
grpid_t tg_pgrpid; /* The ID of the parent task group */
|
|
||||||
#endif
|
|
||||||
#if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SCHED_HAVE_PARENT)
|
|
||||||
pid_t tg_task; /* The ID of the task within the group */
|
|
||||||
#endif
|
#endif
|
||||||
|
pid_t tg_pid; /* The ID of the task within the group */
|
||||||
|
pid_t tg_ppid; /* This is the ID of the parent thread */
|
||||||
uint8_t tg_flags; /* See GROUP_FLAG_* definitions */
|
uint8_t tg_flags; /* See GROUP_FLAG_* definitions */
|
||||||
|
|
||||||
/* User identity **************************************************************/
|
/* User identity **************************************************************/
|
||||||
|
|
@ -508,16 +497,9 @@ struct task_group_s
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_CHILD_STATUS
|
#ifdef CONFIG_SCHED_CHILD_STATUS
|
||||||
FAR struct child_status_s *tg_children; /* Head of a list of child status */
|
FAR struct child_status_s *tg_children; /* Head of a list of child status */
|
||||||
|
#else
|
||||||
|
uint16_t tg_nchildren; /* This is the number active children */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_GROUP_MEMBERS
|
|
||||||
/* REVISIT: What if parent thread exits? Should use tg_pgrpid. */
|
|
||||||
|
|
||||||
pid_t tg_ppid; /* This is the ID of the parent thread */
|
|
||||||
#ifndef CONFIG_SCHED_CHILD_STATUS
|
|
||||||
uint16_t tg_nchildren; /* This is the number active children */
|
|
||||||
#endif
|
|
||||||
#endif /* HAVE_GROUP_MEMBERS */
|
|
||||||
#endif /* CONFIG_SCHED_HAVE_PARENT */
|
#endif /* CONFIG_SCHED_HAVE_PARENT */
|
||||||
|
|
||||||
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
|
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,6 @@
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
#include <nuttx/sched.h>
|
#include <nuttx/sched.h>
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* Any negative GRPID is invalid. */
|
|
||||||
|
|
||||||
#define INVALID_GROUP_ID (pid_t)-1
|
|
||||||
#define IS_INVALID_GRPID(grpid) ((int)(grpid) < 0)
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Type Definitions
|
* Public Type Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
@ -61,14 +52,14 @@ extern FAR struct task_group_s *g_grouphead;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_ADDRENV
|
#ifdef CONFIG_ARCH_ADDRENV
|
||||||
/* This variable holds the group ID of the current task group. This ID is
|
/* This variable holds the PID of the current task group. This ID is
|
||||||
* zero if the current task is a kernel thread that has no address
|
* zero if the current task is a kernel thread that has no address
|
||||||
* environment (other than the kernel context).
|
* environment (other than the kernel context).
|
||||||
*
|
*
|
||||||
* This must only be accessed with interrupts disabled.
|
* This must only be accessed with interrupts disabled.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern grpid_t g_grpid_current;
|
extern pid_t g_pid_current;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|
@ -94,11 +85,10 @@ void group_del_waiter(FAR struct task_group_s *group);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
||||||
FAR struct task_group_s *group_findby_grpid(grpid_t grpid);
|
FAR struct task_group_s *group_findbypid(pid_t pid);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
#ifdef HAVE_GROUP_MEMBERS
|
||||||
FAR struct task_group_s *group_findbypid(pid_t pid);
|
|
||||||
int group_foreachchild(FAR struct task_group_s *group,
|
int group_foreachchild(FAR struct task_group_s *group,
|
||||||
foreachchild_t handler, FAR void *arg);
|
foreachchild_t handler, FAR void *arg);
|
||||||
int group_kill_children(FAR struct tcb_s *tcb);
|
int group_kill_children(FAR struct tcb_s *tcb);
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,14 @@
|
||||||
* Public Data
|
* Public Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* This variable holds the group ID of the current task group. This ID is
|
/* This variable holds the PID of the current task group. This ID is
|
||||||
* zero if the current task is a kernel thread that has no address
|
* zero if the current task is a kernel thread that has no address
|
||||||
* environment (other than the kernel context).
|
* environment (other than the kernel context).
|
||||||
*
|
*
|
||||||
* This must only be accessed with interrupts disabled.
|
* This must only be accessed with interrupts disabled.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
grpid_t g_grpid_current;
|
pid_t g_pid_current = INVALID_PROCESS_ID;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
|
|
@ -84,7 +84,7 @@ int group_addrenv(FAR struct tcb_s *tcb)
|
||||||
FAR struct task_group_s *group;
|
FAR struct task_group_s *group;
|
||||||
FAR struct task_group_s *oldgroup;
|
FAR struct task_group_s *oldgroup;
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
grpid_t grpid;
|
pid_t pid;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* NULL for the tcb means to use the TCB of the task at the head of the
|
/* NULL for the tcb means to use the TCB of the task at the head of the
|
||||||
|
|
@ -110,23 +110,23 @@ int group_addrenv(FAR struct tcb_s *tcb)
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the ID of the group that needs the address environment */
|
/* Get the PID of the group that needs the address environment */
|
||||||
|
|
||||||
grpid = group->tg_grpid;
|
pid = group->tg_pid;
|
||||||
DEBUGASSERT(grpid != 0);
|
DEBUGASSERT(pid != INVALID_PROCESS_ID);
|
||||||
|
|
||||||
/* Are we going to change address environments? */
|
/* Are we going to change address environments? */
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
if (grpid != g_grpid_current)
|
if (pid != g_pid_current)
|
||||||
{
|
{
|
||||||
/* Yes.. Is there a current address environment in place? */
|
/* Yes.. Is there a current address environment in place? */
|
||||||
|
|
||||||
if (g_grpid_current != 0)
|
if (g_pid_current != INVALID_PROCESS_ID)
|
||||||
{
|
{
|
||||||
/* Find the old group with this ID. */
|
/* Find the old group with this ID. */
|
||||||
|
|
||||||
oldgroup = group_findby_grpid(g_grpid_current);
|
oldgroup = group_findbypid(g_pid_current);
|
||||||
DEBUGASSERT(oldgroup &&
|
DEBUGASSERT(oldgroup &&
|
||||||
(oldgroup->tg_flags & GROUP_FLAG_ADDRENV) != 0);
|
(oldgroup->tg_flags & GROUP_FLAG_ADDRENV) != 0);
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ int group_addrenv(FAR struct tcb_s *tcb)
|
||||||
|
|
||||||
/* Save the new, current group */
|
/* Save the new, current group */
|
||||||
|
|
||||||
g_grpid_current = grpid;
|
g_pid_current = pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
|
|
|
||||||
|
|
@ -46,16 +46,6 @@
|
||||||
|
|
||||||
#define GROUP_INITIAL_MEMBERS 4
|
#define GROUP_INITIAL_MEMBERS 4
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* This is counter that is used to generate unique task group IDs */
|
|
||||||
|
|
||||||
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
|
||||||
static grpid_t g_grpid_counter;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
@ -70,68 +60,6 @@ FAR struct task_group_s *g_grouphead;
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: group_assign_grpid
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Create a unique group ID.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* tcb - The tcb in need of the task group.
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* None
|
|
||||||
*
|
|
||||||
* Assumptions:
|
|
||||||
* Called during task creation in a safe context. No special precautions
|
|
||||||
* are required here.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
|
||||||
static void group_assign_grpid(FAR struct task_group_s *group)
|
|
||||||
{
|
|
||||||
irqstate_t flags;
|
|
||||||
grpid_t grpid;
|
|
||||||
|
|
||||||
/* Pre-emption should already be disabled, but let's be paranoid careful */
|
|
||||||
|
|
||||||
sched_lock();
|
|
||||||
|
|
||||||
/* Loop until we create a unique ID */
|
|
||||||
|
|
||||||
for (; ; )
|
|
||||||
{
|
|
||||||
/* Increment the ID counter. It is global data so be extra paranoid. */
|
|
||||||
|
|
||||||
flags = enter_critical_section();
|
|
||||||
grpid = ++g_grpid_counter;
|
|
||||||
|
|
||||||
/* Check for overflow */
|
|
||||||
|
|
||||||
if (grpid <= 0)
|
|
||||||
{
|
|
||||||
g_grpid_counter = 1; /* One is the IDLE group */
|
|
||||||
leave_critical_section(flags);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Does a task group with this ID already exist? */
|
|
||||||
|
|
||||||
leave_critical_section(flags);
|
|
||||||
if (group_findby_grpid(grpid) == NULL)
|
|
||||||
{
|
|
||||||
/* No.. Assign this ID to the new group and return */
|
|
||||||
|
|
||||||
group->tg_grpid = grpid;
|
|
||||||
sched_unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* HAVE_GROUP_MEMBERS */
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: group_inherit_identity
|
* Name: group_inherit_identity
|
||||||
*
|
*
|
||||||
|
|
@ -243,14 +171,6 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype)
|
||||||
|
|
||||||
tcb->cmn.group = group;
|
tcb->cmn.group = group;
|
||||||
|
|
||||||
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
|
||||||
/* Assign the group a unique ID. If g_grpid_counter were to wrap before we
|
|
||||||
* finish with task creation, that would be a problem.
|
|
||||||
*/
|
|
||||||
|
|
||||||
group_assign_grpid(group);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Inherit the user identity from the parent task group */
|
/* Inherit the user identity from the parent task group */
|
||||||
|
|
||||||
group_inherit_identity(group);
|
group_inherit_identity(group);
|
||||||
|
|
@ -349,7 +269,6 @@ int group_initialize(FAR struct task_tcb_s *tcb)
|
||||||
group->flink = g_grouphead;
|
group->flink = g_grouphead;
|
||||||
g_grouphead = group;
|
g_grouphead = group;
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Save the ID of the main task within the group of threads. This needed
|
/* Save the ID of the main task within the group of threads. This needed
|
||||||
|
|
@ -358,9 +277,7 @@ int group_initialize(FAR struct task_tcb_s *tcb)
|
||||||
* task has exited.
|
* task has exited.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SCHED_HAVE_PARENT)
|
group->tg_pid = tcb->cmn.pid;
|
||||||
group->tg_task = tcb->cmn.pid;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Mark that there is one member in the group, the main task */
|
/* Mark that there is one member in the group, the main task */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,60 +40,12 @@
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: group_findby_grpid
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Given a group ID, find the group task structure with that ID. IDs are
|
|
||||||
* used instead of pointers to group structures. This is done because a
|
|
||||||
* group can disappear at any time leaving a stale pointer; an ID is
|
|
||||||
* cleaner because if the group disappears, this function will fail
|
|
||||||
* gracefully.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* grpid - The group ID to find.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* group 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) || defined(CONFIG_ARCH_ADDRENV)
|
|
||||||
FAR struct task_group_s *group_findby_grpid(grpid_t grpid)
|
|
||||||
{
|
|
||||||
FAR struct task_group_s *group;
|
|
||||||
irqstate_t flags;
|
|
||||||
|
|
||||||
/* Find the status structure with the matching GID */
|
|
||||||
|
|
||||||
flags = enter_critical_section();
|
|
||||||
for (group = g_grouphead; group; group = group->flink)
|
|
||||||
{
|
|
||||||
if (group->tg_grpid == grpid)
|
|
||||||
{
|
|
||||||
leave_critical_section(flags);
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
leave_critical_section(flags);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: group_findbypid
|
* Name: group_findbypid
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Given a task ID, find the group task structure with was started by that
|
* 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_task and will
|
* 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.
|
* be remember even if the main task thread leaves the group.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
|
|
@ -111,7 +63,7 @@ FAR struct task_group_s *group_findby_grpid(grpid_t grpid)
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
||||||
FAR struct task_group_s *group_findbypid(pid_t pid)
|
FAR struct task_group_s *group_findbypid(pid_t pid)
|
||||||
{
|
{
|
||||||
FAR struct task_group_s *group;
|
FAR struct task_group_s *group;
|
||||||
|
|
@ -122,7 +74,7 @@ FAR struct task_group_s *group_findbypid(pid_t pid)
|
||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
for (group = g_grouphead; group; group = group->flink)
|
for (group = g_grouphead; group; group = group->flink)
|
||||||
{
|
{
|
||||||
if (group->tg_task == pid)
|
if (group->tg_pid == pid)
|
||||||
{
|
{
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
return group;
|
return group;
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ static inline void group_release(FAR struct task_group_s *group)
|
||||||
|
|
||||||
/* Mark no address environment */
|
/* Mark no address environment */
|
||||||
|
|
||||||
g_grpid_current = 0;
|
g_pid_current = INVALID_PROCESS_ID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)
|
||||||
|
|
|
||||||
|
|
@ -168,11 +168,7 @@ int nx_waitid(int idtype, id_t id, FAR siginfo_t *info, int options)
|
||||||
ctcb = nxsched_get_tcb((pid_t)id);
|
ctcb = nxsched_get_tcb((pid_t)id);
|
||||||
if (ctcb != NULL)
|
if (ctcb != NULL)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
if (ctcb->group->tg_ppid != rtcb->group->tg_pid)
|
||||||
if (ctcb->group->tg_pgrpid != rtcb->group->tg_grpid)
|
|
||||||
#else
|
|
||||||
if (ctcb->group->tg_ppid != rtcb->pid)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ret = -ECHILD;
|
ret = -ECHILD;
|
||||||
goto errout;
|
goto errout;
|
||||||
|
|
@ -212,11 +208,7 @@ int nx_waitid(int idtype, id_t id, FAR siginfo_t *info, int options)
|
||||||
|
|
||||||
ctcb = nxsched_get_tcb((pid_t)id);
|
ctcb = nxsched_get_tcb((pid_t)id);
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->group->tg_pid)
|
||||||
if (ctcb == NULL || ctcb->group->tg_pgrpid != rtcb->group->tg_grpid)
|
|
||||||
#else
|
|
||||||
if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ret = -ECHILD;
|
ret = -ECHILD;
|
||||||
goto errout;
|
goto errout;
|
||||||
|
|
|
||||||
|
|
@ -233,11 +233,7 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options)
|
||||||
{
|
{
|
||||||
/* Make sure that the thread it is our child. */
|
/* Make sure that the thread it is our child. */
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
if (ctcb->group->tg_ppid != rtcb->group->tg_pid)
|
||||||
if (ctcb->group->tg_pgrpid != rtcb->group->tg_grpid)
|
|
||||||
#else
|
|
||||||
if (ctcb->group->tg_ppid != rtcb->pid)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ret = -ECHILD;
|
ret = -ECHILD;
|
||||||
goto errout;
|
goto errout;
|
||||||
|
|
@ -277,11 +273,7 @@ pid_t nx_waitpid(pid_t pid, int *stat_loc, int options)
|
||||||
|
|
||||||
ctcb = nxsched_get_tcb(pid);
|
ctcb = nxsched_get_tcb(pid);
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->group->tg_pid)
|
||||||
if (ctcb == NULL || ctcb->group->tg_pgrpid != rtcb->group->tg_grpid)
|
|
||||||
#else
|
|
||||||
if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
ret = -ECHILD;
|
ret = -ECHILD;
|
||||||
goto errout;
|
goto errout;
|
||||||
|
|
|
||||||
|
|
@ -249,7 +249,7 @@ static inline void nxtask_groupexit(FAR struct task_group_s *group)
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
#ifdef CONFIG_SCHED_HAVE_PARENT
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
#ifdef HAVE_GROUP_MEMBERS
|
||||||
static inline void nxtask_sigchild(grpid_t pgrpid, FAR struct tcb_s *ctcb,
|
static inline void nxtask_sigchild(pid_t ppid, FAR struct tcb_s *ctcb,
|
||||||
int status)
|
int status)
|
||||||
{
|
{
|
||||||
FAR struct task_group_s *chgrp = ctcb->group;
|
FAR struct task_group_s *chgrp = ctcb->group;
|
||||||
|
|
@ -263,14 +263,14 @@ static inline void nxtask_sigchild(grpid_t pgrpid, FAR struct tcb_s *ctcb,
|
||||||
* this case, the child task group has been orphaned.
|
* this case, the child task group has been orphaned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pgrp = group_findby_grpid(pgrpid);
|
pgrp = group_findbypid(ppid);
|
||||||
if (!pgrp)
|
if (!pgrp)
|
||||||
{
|
{
|
||||||
/* Set the task group ID to an invalid group ID. The dead parent
|
/* Set the task group ID to an invalid group ID. The dead parent
|
||||||
* task group ID could get reused some time in the future.
|
* task group ID could get reused some time in the future.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
chgrp->tg_pgrpid = INVALID_GROUP_ID;
|
chgrp->tg_ppid = INVALID_PROCESS_ID;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,11 +305,7 @@ static inline void nxtask_sigchild(grpid_t pgrpid, FAR struct tcb_s *ctcb,
|
||||||
info.si_code = CLD_EXITED;
|
info.si_code = CLD_EXITED;
|
||||||
info.si_errno = OK;
|
info.si_errno = OK;
|
||||||
info.si_value.sival_ptr = NULL;
|
info.si_value.sival_ptr = NULL;
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
info.si_pid = chgrp->tg_pid;
|
||||||
info.si_pid = chgrp->tg_task;
|
|
||||||
#else
|
|
||||||
info.si_pid = ctcb->pid;
|
|
||||||
#endif
|
|
||||||
info.si_status = status;
|
info.si_status = status;
|
||||||
|
|
||||||
/* Send the signal to one thread in the group */
|
/* Send the signal to one thread in the group */
|
||||||
|
|
@ -358,11 +354,7 @@ static inline void nxtask_sigchild(FAR struct tcb_s *ptcb,
|
||||||
info.si_code = CLD_EXITED;
|
info.si_code = CLD_EXITED;
|
||||||
info.si_errno = OK;
|
info.si_errno = OK;
|
||||||
info.si_value.sival_ptr = NULL;
|
info.si_value.sival_ptr = NULL;
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
info.si_pid = ctcb->group->tg_pid;
|
||||||
info.si_pid = ctcb->group->tg_task;
|
|
||||||
#else
|
|
||||||
info.si_pid = ctcb->pid;
|
|
||||||
#endif
|
|
||||||
info.si_status = status;
|
info.si_status = status;
|
||||||
|
|
||||||
/* Send the signal. We need to use this internal interface so that we
|
/* Send the signal. We need to use this internal interface so that we
|
||||||
|
|
@ -400,7 +392,7 @@ static inline void nxtask_signalparent(FAR struct tcb_s *ctcb, int status)
|
||||||
|
|
||||||
/* Send SIGCHLD to all members of the parent's task group */
|
/* Send SIGCHLD to all members of the parent's task group */
|
||||||
|
|
||||||
nxtask_sigchild(ctcb->group->tg_pgrpid, ctcb, status);
|
nxtask_sigchild(ctcb->group->tg_ppid, ctcb, status);
|
||||||
sched_unlock();
|
sched_unlock();
|
||||||
#else
|
#else
|
||||||
FAR struct tcb_s *ptcb;
|
FAR struct tcb_s *ptcb;
|
||||||
|
|
|
||||||
|
|
@ -84,11 +84,7 @@ pid_t getppid(void)
|
||||||
* ready-to-run task list
|
* ready-to-run task list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
|
||||||
return rtcb->group->tg_pgrpid;
|
|
||||||
#else
|
|
||||||
return rtcb->group->tg_ppid;
|
return rtcb->group->tg_ppid;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No.. return -ESRCH to indicate this condition */
|
/* No.. return -ESRCH to indicate this condition */
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,8 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||||
FAR struct task_group_s *ogrp;
|
FAR struct task_group_s *ogrp;
|
||||||
FAR struct task_group_s *pgrp;
|
FAR struct task_group_s *pgrp;
|
||||||
FAR struct tcb_s *tcb;
|
FAR struct tcb_s *tcb;
|
||||||
grpid_t ogrpid;
|
|
||||||
grpid_t pgrpid;
|
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
|
pid_t opid;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Disable interrupts so that nothing can change in the relationship of
|
/* Disable interrupts so that nothing can change in the relationship of
|
||||||
|
|
@ -88,13 +87,13 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||||
DEBUGASSERT(tcb->group);
|
DEBUGASSERT(tcb->group);
|
||||||
chgrp = tcb->group;
|
chgrp = tcb->group;
|
||||||
|
|
||||||
/* Get the GID of the old parent task's task group (ogrpid) */
|
/* Get the PID of the old parent task's task group (opid) */
|
||||||
|
|
||||||
ogrpid = chgrp->tg_pgrpid;
|
opid = chgrp->tg_ppid;
|
||||||
|
|
||||||
/* Get the old parent task's task group (ogrp) */
|
/* Get the old parent task's task group (ogrp) */
|
||||||
|
|
||||||
ogrp = group_findby_grpid(ogrpid);
|
ogrp = group_findbypid(opid);
|
||||||
if (!ogrp)
|
if (!ogrp)
|
||||||
{
|
{
|
||||||
ret = -ESRCH;
|
ret = -ESRCH;
|
||||||
|
|
@ -110,8 +109,8 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||||
{
|
{
|
||||||
/* Get the grandparent task's task group (pgrp) */
|
/* Get the grandparent task's task group (pgrp) */
|
||||||
|
|
||||||
pgrpid = ogrp->tg_pgrpid;
|
ppid = ogrp->tg_ppid;
|
||||||
pgrp = group_findby_grpid(pgrpid);
|
pgrp = group_findbypid(ppid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -125,7 +124,7 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||||
}
|
}
|
||||||
|
|
||||||
pgrp = tcb->group;
|
pgrp = tcb->group;
|
||||||
pgrpid = pgrp->tg_grpid;
|
ppid = pgrp->tg_pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pgrp)
|
if (!pgrp)
|
||||||
|
|
@ -139,7 +138,7 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||||
* all members of the child's task group.
|
* all members of the child's task group.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
chgrp->tg_pgrpid = pgrpid;
|
chgrp->tg_ppid = ppid;
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_CHILD_STATUS
|
#ifdef CONFIG_SCHED_CHILD_STATUS
|
||||||
/* Remove the child status entry from old parent task group */
|
/* Remove the child status entry from old parent task group */
|
||||||
|
|
|
||||||
|
|
@ -211,19 +211,12 @@ static inline void nxtask_save_parent(FAR struct tcb_s *tcb, uint8_t ttype)
|
||||||
|
|
||||||
DEBUGASSERT(rtcb != NULL && rtcb->group != NULL);
|
DEBUGASSERT(rtcb != NULL && rtcb->group != NULL);
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
/* Save the PID of the parent tasks' task group in the child's task
|
||||||
/* Save the ID of the parent tasks' task group in the child's task
|
|
||||||
* group. Copy the ID from the parent's task group structure to
|
* group. Copy the ID from the parent's task group structure to
|
||||||
* child's task group.
|
* child's task group.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
tcb->group->tg_pgrpid = rtcb->group->tg_grpid;
|
tcb->group->tg_ppid = rtcb->group->tg_pid;
|
||||||
|
|
||||||
#else
|
|
||||||
/* Save the parent task's ID in the child task's group. */
|
|
||||||
|
|
||||||
tcb->group->tg_ppid = rtcb->pid;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_CHILD_STATUS
|
#ifdef CONFIG_SCHED_CHILD_STATUS
|
||||||
/* Tasks can also suppress retention of their child status by applying
|
/* Tasks can also suppress retention of their child status by applying
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue