fix: 修复pthread_create相关问题

1. 系统调度未起时,调用pthread_create失败
  系统调度未起时,系统无运行任务,获取当前线程失败
2. 先创建任务再给任务赋值name,且未加锁保护,和shell存在静态

Close #I4P78J

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I2570dcf90953ced06400a0a22193cc81719fb546
This commit is contained in:
zhushengle 2022-01-04 10:22:44 +08:00
parent 67f8149640
commit cd949ddae0
1 changed files with 6 additions and 4 deletions

View File

@ -98,12 +98,14 @@ static int PthreadCreateAttrInit(const pthread_attr_t *attr, void *(*startRoutin
taskInitParam->uwStackSize = threadAttr->stacksize;
if (threadAttr->inheritsched == PTHREAD_EXPLICIT_SCHED) {
taskInitParam->usTaskPrio = (UINT16)threadAttr->schedparam.sched_priority;
} else {
} else if (IsPthread(pthread_self())) {
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
if (ret != 0) {
return ret;
}
taskInitParam->usTaskPrio = (UINT16)schedParam.sched_priority;
} else {
taskInitParam->usTaskPrio = (UINT16)threadAttr->schedparam.sched_priority;
}
PthreadData *pthreadData = (PthreadData *)malloc(sizeof(PthreadData));
@ -140,6 +142,9 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
return ret;
}
/* set pthread default name */
(void)sprintf_s(taskInitParam.pcName, PTHREAD_NAMELEN, "pthread%u", taskID);
if (LOS_TaskCreateOnly(&taskID, &taskInitParam) != LOS_OK) {
free((VOID *)(UINTPTR)taskInitParam.uwArg);
return EINVAL;
@ -154,9 +159,6 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
LOS_ListAdd(&g_pthreadListHead, &pthreadData->threadList);
LOS_IntRestore(intSave);
/* set pthread default name */
(void)sprintf_s(taskInitParam.pcName, PTHREAD_NAMELEN, "pthread%u", taskID);
(void)LOS_TaskResume(taskID);
*thread = (pthread_t)taskID;