• 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 /*
19  * 描述:删除一个任务线程
20  */
OsTaskDelStatusCheck(struct TagTskCb * taskCb)21 OS_SEC_L4_TEXT U32 OsTaskDelStatusCheck(struct TagTskCb *taskCb)
22 {
23     /* If the task is running and scheduler is locked */
24     /* then can not delete it */
25     if ((taskCb == RUNNING_TASK) && (OS_TASK_LOCK_DATA != 0)) {
26         OS_REPORT_ERROR(OS_ERRNO_TSK_DELETE_LOCKED);
27         return OS_ERRNO_TSK_DELETE_LOCKED;
28     }
29 
30     if (TSK_STATUS_TST(taskCb, OS_TSK_QUEUE_BUSY)) {
31         return OS_ERRNO_TSK_QUEUE_DOING;
32     }
33 
34     return OS_OK;
35 }
36 #endif
37 
OsTaskExit(struct TagTskCb * tsk)38 OS_SEC_L4_TEXT void OsTaskExit(struct TagTskCb *tsk)
39 {
40 #if defined(OS_OPTION_TASK_DELETE)
41     /* 如果任务自删除失败就记录错误码,并且上报致命错误 */
42     U32 ret = PRT_TaskDelete(tsk->taskPid);
43     if (ret != OS_OK) {
44         OS_REPORT_ERROR(ret);
45         OS_REPORT_ERROR(OS_ERRNO_TSK_EXIT_WITH_RESOURCE);
46     }
47 #else
48     uintptr_t intSave = OsIntLock();
49 
50     OsTskReadyDel(tsk);
51     OsTskSchedule();
52 
53     OsIntRestore(intSave);
54 #endif
55 }
56 
57 #if defined(OS_OPTION_TASK_DELETE)
58 /*
59  * 描述:删除一个任务线程
60  */
PRT_TaskDelete(TskHandle taskPid)61 OS_SEC_L4_TEXT U32 PRT_TaskDelete(TskHandle taskPid)
62 {
63     return OsTaskDelete(taskPid);
64 }
65 #endif
66