From 3dd32b9901d214483bd96c7f0d87084e6e625f6a Mon Sep 17 00:00:00 2001 From: likailong Date: Sat, 26 Dec 2020 10:43:04 +0800 Subject: [PATCH] Description: add protect flag to resource task Reviewed-by: shenwei and zhangfanfan --- kernel/base/core/los_process.c | 1 - kernel/base/core/los_task.c | 14 ++++++++++++-- kernel/base/include/los_task_pri.h | 8 ++++++++ kernel/common/console.c | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/kernel/base/core/los_process.c b/kernel/base/core/los_process.c index d78eec4d..90cce634 100644 --- a/kernel/base/core/los_process.c +++ b/kernel/base/core/los_process.c @@ -610,7 +610,6 @@ STATIC LosProcessCB *OsGetFreePCB(VOID) if (LOS_ListEmpty(&g_freeProcess)) { SCHEDULER_UNLOCK(intSave); PRINT_ERR("No idle PCB in the system!\n"); - __asm__ __volatile__("swi 0"); return NULL; } diff --git a/kernel/base/core/los_task.c b/kernel/base/core/los_task.c index b000f959..99226353 100644 --- a/kernel/base/core/los_task.c +++ b/kernel/base/core/los_task.c @@ -766,7 +766,6 @@ LITE_OS_SEC_TEXT LosTaskCB *OsGetFreeTaskCB(VOID) if (LOS_ListEmpty(&g_losFreeTask)) { SCHEDULER_UNLOCK(intSave); PRINT_ERR("No idle TCB in the system!\n"); - LOS_Panic("**************error***************\n"); return NULL; } @@ -1205,6 +1204,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID) OS_GOTO_ERREND(); } + if ((taskCB->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) || + (taskCB->taskStatus & OS_TASK_FLAG_NO_DELETE)) { + SCHEDULER_UNLOCK(intSave); + OsBackTrace(); + __asm__ __volatile__("swi 0"); + return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK; + } processCB = OS_PCB_FROM_PID(taskCB->processID); if (processCB->threadNumber == 1) { if (processCB == OsCurrProcessGet()) { @@ -1990,7 +1996,11 @@ LITE_OS_SEC_TEXT UINT32 OsCreateResourceFreeTask(VOID) taskInitParam.uwStackSize = OS_TASK_RESOURCE_STATCI_SIZE; taskInitParam.pcName = "ResourcesTask"; taskInitParam.usTaskPrio = OS_TASK_RESOURCE_FREE_PRIORITY; - return LOS_TaskCreate(&taskID, &taskInitParam); + ret = LOS_TaskCreate(&taskID, &taskInitParam); + if (ret == LOS_OK) { + OS_TCB_FROM_TID(taskID)->taskStatus |= OS_TASK_FLAG_NO_DELETE; + } + return ret; } #ifdef __cplusplus diff --git a/kernel/base/include/los_task_pri.h b/kernel/base/include/los_task_pri.h index e45f4bac..88653467 100644 --- a/kernel/base/include/los_task_pri.h +++ b/kernel/base/include/los_task_pri.h @@ -211,6 +211,14 @@ extern SPIN_LOCK_S g_taskSpin; */ #define OS_TASK_FLAG_SPECIFIES_PROCESS 0x4000U +/** + * @ingroup los_task + * Flag that indicates the task property. + * + * The task is system-level task, like ResourcesTask. + */ +#define OS_TASK_FLAG_NO_DELETE 0x8000U + /** * @ingroup los_task * Boundary on which the stack size is aligned. diff --git a/kernel/common/console.c b/kernel/common/console.c index a3bc3b73..24ad7b09 100644 --- a/kernel/common/console.c +++ b/kernel/common/console.c @@ -1626,7 +1626,7 @@ VOID OsWaitConsoleSendTaskPend(UINT32 taskID) UINT32 i; CONSOLE_CB *console = NULL; LosTaskCB *taskCB = NULL; - INT32 waitTime = 30000; /* 30000: 30 seconds*/ + INT32 waitTime = 3000; /* 3000: 3 seconds*/ for (i = 0; i < CONSOLE_NUM; i++) { console = g_console[i];