1 /*
2  * Copyright (C) 2020-2021 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __POSIX_INTERNAL_SCHED_H
6 #define __POSIX_INTERNAL_SCHED_H
7 
8 #include <sched.h>
9 #include <pthread.h>
10 #include <k_api.h>
11 
12 /* Convert the schedule policy of posix to rhino. */
sched_policy_posix2rhino(int policy)13 static inline int sched_policy_posix2rhino(int policy)
14 {
15     switch (policy) {
16         case SCHED_FIFO:
17             return KSCHED_FIFO;
18         case SCHED_RR:
19             return KSCHED_RR;
20         case SCHED_CFS:
21             return KSCHED_CFS;
22         default:
23             return -1;
24     }
25 }
26 
27 /* Convert the schedule policy of rhino to posix. */
sched_policy_rhino2posix(int policy)28 static inline int sched_policy_rhino2posix(int policy)
29 {
30     switch (policy) {
31         case KSCHED_FIFO:
32             return SCHED_FIFO;
33         case KSCHED_RR:
34             return SCHED_RR;
35         case KSCHED_CFS:
36             return SCHED_CFS;
37         default:
38             return -1;
39     }
40 }
41 
42 /* In rhino: lower priority value means higher priority.
43  * In posix standard: higher priority value means higher priority.
44  */
sched_priority_posix2rhino(int policy,int priority)45 static inline int sched_priority_posix2rhino(int policy, int priority)
46 {
47     return aos_sched_get_priority_max(policy) - priority;
48 }
49 
50 #define sched_priority_rhino2posix sched_priority_posix2rhino
51 
52 #endif /*__POSIX_INTERNAL_SCHED_H*/
53