[smart] split out part of lwp_new() to lwp_create()

Prev implementation of lwp_new() including the create of lwp object
and the pid allocation. But not every lwp object need a pid.
So this patch split out the business of lwp_new() to improve the
maintainability.

Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
Shell
2023-09-25 16:12:49 +08:00
committed by guo
parent 261f5bee67
commit a300cef2a8
7 changed files with 49 additions and 56 deletions

View File

@@ -2083,7 +2083,7 @@ sysret_t _sys_fork(void)
void *user_stack = RT_NULL;
/* new lwp */
lwp = lwp_new();
lwp = lwp_create(LWP_CREATE_FLAG_ALLOC_PID);
if (!lwp)
{
SET_ERRNO(ENOMEM);
@@ -2685,15 +2685,13 @@ sysret_t sys_execve(const char *path, char *const argv[], char *const envp[])
}
/* alloc new lwp to operation */
new_lwp = (struct rt_lwp *)rt_malloc(sizeof(struct rt_lwp));
new_lwp = lwp_create(LWP_CREATE_FLAG_NONE);
if (!new_lwp)
{
SET_ERRNO(ENOMEM);
goto quit;
}
rt_memset(new_lwp, 0, sizeof(struct rt_lwp));
new_lwp->ref = 1;
lwp_user_object_lock_init(new_lwp);
ret = lwp_user_space_init(new_lwp, 0);
if (ret != 0)
{
@@ -2788,10 +2786,6 @@ sysret_t sys_execve(const char *path, char *const argv[], char *const envp[])
rt_hw_interrupt_enable(level);
/* setup the signal, timer_list for the dummy lwp, so that is can be smoothly recycled */
lwp_signal_init(&new_lwp->signal);
rt_list_init(&new_lwp->timer);
lwp_ref_dec(new_lwp);
arch_start_umode(lwp->args,
lwp->text_entry,