• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: Task schedule implementation
14  */
15 #include "prt_task_internal.h"
16 
17 #if defined(OS_OPTION_TASK_DELETE)
18 
OsTaskDeleteResInit(struct TagTskCb * taskCb)19 OS_SEC_L4_TEXT void OsTaskDeleteResInit(struct TagTskCb *taskCb)
20 {
21 
22     if (((OS_TSK_PEND | OS_TSK_QUEUE_PEND) & taskCb->taskStatus) != 0) {
23         ListDelete(&taskCb->pendList);
24     }
25 
26     if (((OS_TSK_DELAY | OS_TSK_TIMEOUT) & taskCb->taskStatus) != 0) {
27         ListDelete(&taskCb->timerList);
28     }
29 
30     if ((OS_TSK_READY & taskCb->taskStatus) != 0) {
31         OsTskReadyDel(taskCb);
32     }
33 
34     taskCb->taskStatus &= (~(OS_TSK_SUSPEND));
35     taskCb->taskStatus |= OS_TSK_UNUSED;
36 
37     return;
38 }
39 
40 /*
41  * 描述:删除一个任务线程
42  */
OsTaskDelete(TskHandle taskPid)43 OS_SEC_L4_TEXT U32 OsTaskDelete(TskHandle taskPid)
44 {
45     U32 ret;
46     uintptr_t intSave;
47     struct TagTskCb *taskCb = NULL;
48 
49     if (taskPid == IDLE_TASK_ID) {
50         return OS_ERRNO_TSK_OPERATE_IDLE;
51     }
52 
53     if (CHECK_TSK_PID_OVERFLOW(taskPid)) {
54         return OS_ERRNO_TSK_ID_INVALID;
55     }
56 
57     intSave = OsIntLock();
58 
59     taskCb = GET_TCB_HANDLE(taskPid);
60     if (TSK_IS_UNUSED(taskCb)) {
61         OsIntRestore(intSave);
62         return OS_ERRNO_TSK_NOT_CREATED;
63     }
64 
65     ret = OsTaskDelStatusCheck(taskCb);
66     if (ret != OS_OK) {
67         OsIntRestore(intSave);
68         return ret;
69     }
70 
71     OsTaskDeleteResInit(taskCb);
72 
73     OsTskHighestSet();
74 
75     if ((OS_TSK_RUNNING & taskCb->taskStatus) != 0) {
76         UNI_FLAG |= OS_FLG_TSK_REQ;
77 
78         ListTailAdd(&taskCb->pendList, &g_tskRecyleList);
79 
80         RUNNING_TASK = OS_PST_ZOMBIE_TASK;
81         RUNNING_TASK->taskPid = taskPid;
82         RUNNING_TASK->taskStatus = taskCb->taskStatus;
83 
84         taskCb->taskStatus = OS_TSK_UNUSED;
85 
86         if (OS_INT_INACTIVE) {
87             OsTaskTrap();
88             OsIntRestore(intSave);
89 
90             return OS_OK;
91         }
92     } else {
93         taskCb->taskStatus = OS_TSK_UNUSED;
94         ListAdd(&taskCb->pendList, &g_tskCbFreeList);
95         OsTskResRecycle(taskCb);
96     }
97 
98     OsIntRestore(intSave);
99 
100     /* if deleteing current task this is unreachable. */
101     return OS_OK;
102 }
103 
104 #endif
105 
106