• 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 /*
18  * 描述:挂起任务
19  */
PRT_TaskSuspend(TskHandle taskPid)20 OS_SEC_L2_TEXT U32 PRT_TaskSuspend(TskHandle taskPid)
21 {
22     uintptr_t intSave;
23     struct TagTskCb *taskCb = NULL;
24 
25     if (taskPid == IDLE_TASK_ID) {
26         return OS_ERRNO_TSK_OPERATE_IDLE;
27     }
28 
29     if (CHECK_TSK_PID_OVERFLOW(taskPid)) {
30         return OS_ERRNO_TSK_ID_INVALID;
31     }
32 
33     taskCb = GET_TCB_HANDLE(taskPid);
34 
35     intSave = OsIntLock();
36 
37     if (taskCb->taskStatus == OS_TSK_UNUSED) {
38         OsIntRestore(intSave);
39 
40         return OS_ERRNO_TSK_NOT_CREATED;
41     }
42 
43     /* If task is suspended then return */
44     if ((OS_TSK_SUSPEND & taskCb->taskStatus) != 0) {
45         OsIntRestore(intSave);
46 
47         return OS_ERRNO_TSK_ALREADY_SUSPENDED;
48     }
49 
50     if (((OS_TSK_RUNNING & taskCb->taskStatus) != 0) && (g_uniTaskLock != 0)) {
51         OsIntRestore(intSave);
52 
53         OS_REPORT_ERROR(OS_ERRNO_TSK_SUSPEND_LOCKED);
54         return OS_ERRNO_TSK_SUSPEND_LOCKED;
55     }
56 
57     /* If task is ready then remove from ready list */
58     if ((OS_TSK_READY & taskCb->taskStatus) != 0) {
59         OsTskReadyDel(taskCb);
60     }
61 
62     taskCb->taskStatus |= OS_TSK_SUSPEND;
63 
64     if ((OS_TSK_RUNNING & taskCb->taskStatus) != 0) {
65         OsTskScheduleFastPs(intSave);
66     }
67 
68     OsIntRestore(intSave);
69     return OS_OK;
70 }
71 
72 /*
73  * 描述解挂任务
74  */
PRT_TaskResume(TskHandle taskPid)75 OS_SEC_L2_TEXT U32 PRT_TaskResume(TskHandle taskPid)
76 {
77     uintptr_t intSave;
78     struct TagTskCb *taskCb = NULL;
79 
80     if (CHECK_TSK_PID_OVERFLOW(taskPid)) {
81         return OS_ERRNO_TSK_ID_INVALID;
82     }
83 
84     taskCb = GET_TCB_HANDLE(taskPid);
85 
86     intSave = OsIntLock();
87 
88     if (TSK_IS_UNUSED(taskCb)) {
89         OsIntRestore(intSave);
90         return OS_ERRNO_TSK_NOT_CREATED;
91     }
92 
93     if (((OS_TSK_RUNNING & taskCb->taskStatus) != 0) && (g_uniTaskLock != 0)) {
94 	OsIntRestore(intSave);
95 	return OS_ERRNO_TSK_ACTIVE_FAILED;
96     }
97 
98     /* If task is not suspended then return */
99     if ((OS_TSK_SUSPEND & taskCb->taskStatus) == 0) {
100         OsIntRestore(intSave);
101         return OS_ERRNO_TSK_NOT_SUSPENDED;
102     }
103 
104     TSK_STATUS_CLEAR(taskCb, OS_TSK_SUSPEND);
105 
106     /* If task is not blocked then move it to ready list */
107     OsMoveTaskToReady(taskCb);
108     OsIntRestore(intSave);
109 
110     return OS_OK;
111 }
112