[components/lwp] clear ref to parent on waitpid() (#7741)
Signed-off-by: shell <smokewood@qq.com>
This commit is contained in:
parent
eafc773186
commit
0b79bea7cd
|
@ -7,6 +7,8 @@
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2012-09-30 Bernard first version.
|
* 2012-09-30 Bernard first version.
|
||||||
* 2017-11-08 JasonJiaJie fix memory leak issue when close a pipe.
|
* 2017-11-08 JasonJiaJie fix memory leak issue when close a pipe.
|
||||||
|
* 2023-06-28 shell return POLLHUP when writer closed its channel on poll()
|
||||||
|
* fix flag test on pipe_fops_open()
|
||||||
*/
|
*/
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
|
@ -65,12 +67,12 @@ static int pipe_fops_open(struct dfs_file *fd)
|
||||||
|
|
||||||
rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
|
rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
|
||||||
|
|
||||||
if ((fd->flags & O_RDONLY) == O_RDONLY)
|
if ((fd->flags & O_ACCMODE) == O_RDONLY)
|
||||||
{
|
{
|
||||||
pipe->reader = 1;
|
pipe->reader = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd->flags & O_WRONLY) == O_WRONLY)
|
if ((fd->flags & O_ACCMODE) == O_WRONLY)
|
||||||
{
|
{
|
||||||
pipe->writer = 1;
|
pipe->writer = 1;
|
||||||
}
|
}
|
||||||
|
@ -362,6 +364,10 @@ static int pipe_fops_poll(struct dfs_file *fd, rt_pollreq_t *req)
|
||||||
{
|
{
|
||||||
mask |= POLLIN;
|
mask |= POLLIN;
|
||||||
}
|
}
|
||||||
|
else if (pipe->writer == 0)
|
||||||
|
{
|
||||||
|
mask = POLLHUP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode & 2)
|
if (mode & 2)
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2019-10-16 zhangjun first version
|
* 2019-10-16 zhangjun first version
|
||||||
* 2021-02-20 lizhirui fix warning
|
* 2021-02-20 lizhirui fix warning
|
||||||
|
* 2023-06-26 shell clear ref to parent on waitpid()
|
||||||
|
* Remove recycling of lwp on waitpid() and leave it to defunct routine
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
|
@ -672,6 +674,7 @@ pid_t waitpid(pid_t pid, int *status, int options)
|
||||||
|
|
||||||
if (ret != -1)
|
if (ret != -1)
|
||||||
{
|
{
|
||||||
|
/* delete from sibling list of its parent */
|
||||||
struct rt_lwp **lwp_node;
|
struct rt_lwp **lwp_node;
|
||||||
|
|
||||||
*status = lwp->lwp_ret;
|
*status = lwp->lwp_ret;
|
||||||
|
@ -682,9 +685,7 @@ pid_t waitpid(pid_t pid, int *status, int options)
|
||||||
lwp_node = &(*lwp_node)->sibling;
|
lwp_node = &(*lwp_node)->sibling;
|
||||||
}
|
}
|
||||||
(*lwp_node) = lwp->sibling;
|
(*lwp_node) = lwp->sibling;
|
||||||
|
lwp->parent = RT_NULL;
|
||||||
lwp_pid_put(pid);
|
|
||||||
rt_free(lwp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quit:
|
quit:
|
||||||
|
|
Loading…
Reference in New Issue