[lwp] Fix a bug when lwp_pid_get_locked cannot find pid.Same thing with tid.

This commit is contained in:
yby 2023-10-31 01:20:14 +08:00
parent 7066761510
commit c17f205119
2 changed files with 36 additions and 6 deletions

View File

@ -80,11 +80,13 @@ static pid_t lwp_pid_get_locked(void)
{ {
struct lwp_avl_struct *p; struct lwp_avl_struct *p;
pid_t pid = 0; pid_t pid = 0;
int head_recover_flag = 0;
p = lwp_pid_free_head; p = lwp_pid_free_head;
if (p) if (p)
{ {
lwp_pid_free_head = (struct lwp_avl_struct *)p->avl_right; lwp_pid_free_head = (struct lwp_avl_struct *)p->avl_right;
head_recover_flag = 1;
} }
else if (lwp_pid_ary_alloced < RT_LWP_MAX_NR) else if (lwp_pid_ary_alloced < RT_LWP_MAX_NR)
{ {
@ -115,10 +117,23 @@ static pid_t lwp_pid_get_locked(void)
} }
} }
} }
if (found_noused == 1)
{
p->avl_key = pid; p->avl_key = pid;
lwp_avl_insert(p, &lwp_pid_root); lwp_avl_insert(p, &lwp_pid_root);
current_pid = pid; current_pid = pid;
} }
else
{
pid = 0;
if (head_recover_flag == 1)
{
/* recover lwp_pid_free_head */
lwp_pid_free_head = p;
}
}
}
return pid; return pid;
} }

View File

@ -46,12 +46,14 @@ int lwp_tid_get(void)
{ {
struct lwp_avl_struct *p; struct lwp_avl_struct *p;
int tid = 0; int tid = 0;
int head_recover_flag = 0;
lwp_mutex_take_safe(&tid_lock, RT_WAITING_FOREVER, 0); lwp_mutex_take_safe(&tid_lock, RT_WAITING_FOREVER, 0);
p = lwp_tid_free_head; p = lwp_tid_free_head;
if (p) if (p)
{ {
lwp_tid_free_head = (struct lwp_avl_struct *)p->avl_right; lwp_tid_free_head = (struct lwp_avl_struct *)p->avl_right;
head_recover_flag = 1;
} }
else if (lwp_tid_ary_alloced < LWP_TID_MAX_NR) else if (lwp_tid_ary_alloced < LWP_TID_MAX_NR)
{ {
@ -82,10 +84,23 @@ int lwp_tid_get(void)
} }
} }
} }
if (found_noused == 1)
{
p->avl_key = tid; p->avl_key = tid;
lwp_avl_insert(p, &lwp_tid_root); lwp_avl_insert(p, &lwp_tid_root);
current_tid = tid; current_tid = tid;
} }
else
{
tid = 0;
if (head_recover_flag == 1)
{
/* recover lwp_tid_free_head */
lwp_tid_free_head = p;
}
}
}
lwp_mutex_release_safe(&tid_lock); lwp_mutex_release_safe(&tid_lock);
return tid; return tid;
} }