mirror of https://github.com/RT-Thread/rt-thread
[smart] add waitpid(-1) support (#8020)
Signed-off-by: shell <wangxiaoyao@rt-thread.com>
This commit is contained in:
parent
4462106a61
commit
b8e332fa2d
|
@ -648,21 +648,33 @@ pid_t waitpid(pid_t pid, int *status, int options)
|
||||||
rt_base_t level;
|
rt_base_t level;
|
||||||
struct rt_thread *thread;
|
struct rt_thread *thread;
|
||||||
struct rt_lwp *lwp;
|
struct rt_lwp *lwp;
|
||||||
struct rt_lwp *lwp_self;
|
struct rt_lwp *this_lwp;
|
||||||
|
|
||||||
|
this_lwp = lwp_self();
|
||||||
|
if (!this_lwp)
|
||||||
|
{
|
||||||
|
goto quit;
|
||||||
|
}
|
||||||
|
|
||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
|
if (pid == -1)
|
||||||
|
{
|
||||||
|
lwp = this_lwp->first_child;
|
||||||
|
if (!lwp)
|
||||||
|
goto quit;
|
||||||
|
else
|
||||||
|
pid = lwp->pid;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
lwp = lwp_from_pid(pid);
|
lwp = lwp_from_pid(pid);
|
||||||
if (!lwp)
|
if (!lwp)
|
||||||
{
|
{
|
||||||
goto quit;
|
goto quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
lwp_self = (struct rt_lwp *)rt_thread_self()->lwp;
|
|
||||||
if (!lwp_self)
|
|
||||||
{
|
|
||||||
goto quit;
|
|
||||||
}
|
}
|
||||||
if (lwp->parent != lwp_self)
|
|
||||||
|
if (lwp->parent != this_lwp)
|
||||||
{
|
{
|
||||||
goto quit;
|
goto quit;
|
||||||
}
|
}
|
||||||
|
@ -693,7 +705,7 @@ pid_t waitpid(pid_t pid, int *status, int options)
|
||||||
struct rt_lwp **lwp_node;
|
struct rt_lwp **lwp_node;
|
||||||
|
|
||||||
*status = lwp->lwp_ret;
|
*status = lwp->lwp_ret;
|
||||||
lwp_node = &lwp_self->first_child;
|
lwp_node = &this_lwp->first_child;
|
||||||
while (*lwp_node != lwp)
|
while (*lwp_node != lwp)
|
||||||
{
|
{
|
||||||
RT_ASSERT(*lwp_node != RT_NULL);
|
RT_ASSERT(*lwp_node != RT_NULL);
|
||||||
|
|
Loading…
Reference in New Issue