summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShell <[email protected]>2023-09-09 09:35:33 +0800
committerGitHub <[email protected]>2023-09-09 09:35:33 +0800
commitb8e332fa2d22ebf47ad2cbe1d744b7327289e0ea (patch)
tree83b66633bcf2ebf002b0eb168c3d0af3f5493199
parent4462106a6159e9406201b80da0776bc0cbdbe887 (diff)
[smart] add waitpid(-1) support (#8020)
Signed-off-by: shell <[email protected]>
-rw-r--r--components/lwp/lwp_pid.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/components/lwp/lwp_pid.c b/components/lwp/lwp_pid.c
index 38d068ee0a..7c00174762 100644
--- a/components/lwp/lwp_pid.c
+++ b/components/lwp/lwp_pid.c
@@ -648,21 +648,33 @@ pid_t waitpid(pid_t pid, int *status, int options)
rt_base_t level;
struct rt_thread *thread;
struct rt_lwp *lwp;
- struct rt_lwp *lwp_self;
+ struct rt_lwp *this_lwp;
- level = rt_hw_interrupt_disable();
- lwp = lwp_from_pid(pid);
- if (!lwp)
+ this_lwp = lwp_self();
+ if (!this_lwp)
{
goto quit;
}
- lwp_self = (struct rt_lwp *)rt_thread_self()->lwp;
- if (!lwp_self)
+ level = rt_hw_interrupt_disable();
+ if (pid == -1)
{
- goto quit;
+ lwp = this_lwp->first_child;
+ if (!lwp)
+ goto quit;
+ else
+ pid = lwp->pid;
}
- if (lwp->parent != lwp_self)
+ else
+ {
+ lwp = lwp_from_pid(pid);
+ if (!lwp)
+ {
+ goto quit;
+ }
+ }
+
+ if (lwp->parent != this_lwp)
{
goto quit;
}
@@ -693,7 +705,7 @@ pid_t waitpid(pid_t pid, int *status, int options)
struct rt_lwp **lwp_node;
*status = lwp->lwp_ret;
- lwp_node = &lwp_self->first_child;
+ lwp_node = &this_lwp->first_child;
while (*lwp_node != lwp)
{
RT_ASSERT(*lwp_node != RT_NULL);