• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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: 2022-11-15
13  * Description: pthread sched功能实现
14  */
15 
16 #include "pthread.h"
17 #include "sched.h"
18 #include "prt_posix_internal.h"
19 
sched_get_priority_max(int policy)20 int sched_get_priority_max(int policy)
21 {
22     if (policy < 0) {
23         errno = EINVAL;
24         return PTHREAD_OP_FAIL;
25     }
26     errno = OS_OK;
27 
28     return OS_TSK_PRIORITY_HIGHEST;
29 }
30 
sched_get_priority_min(int policy)31 int sched_get_priority_min(int policy)
32 {
33     if (policy < 0) {
34         errno = EINVAL;
35         return PTHREAD_OP_FAIL;
36     }
37     errno = OS_OK;
38 
39     return OS_TSK_PRIORITY_LOWEST - 1;
40 }
41 
sched_yield(void)42 int sched_yield(void)
43 {
44     (void)PRT_TaskDelay(0);
45 
46     return OS_OK;
47 }
48 
pthread_setschedprio(pthread_t thread,int prio)49 int pthread_setschedprio(pthread_t thread, int prio)
50 {
51     U32 ret;
52 
53     /* task 优先级范围 0 <= priority < OS_TSK_PRIORITY_LOWEST */
54     if (prio < OS_TSK_PRIORITY_HIGHEST || prio >= OS_TSK_PRIORITY_LOWEST) {
55         return ENOTSUP;
56     }
57 
58     ret = PRT_TaskSetPriority((TskHandle)thread, (TskPrior)prio);
59     if (ret != OS_OK) {
60         return EINVAL;
61     }
62 
63     return OS_OK;
64 }
65