1 /*
2  * Copyright (c) 2023 Meta
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_LIB_POSIX_POSIX_PTHREAD_SCHED_H_
8 #define ZEPHYR_LIB_POSIX_POSIX_PTHREAD_SCHED_H_
9 
10 #include <errno.h>
11 #include <stdbool.h>
12 
13 #include <zephyr/posix/sched.h>
14 
valid_posix_policy(int policy)15 static inline bool valid_posix_policy(int policy)
16 {
17 	return policy == SCHED_FIFO || policy == SCHED_RR || policy == SCHED_OTHER;
18 }
19 
posix_sched_priority_min(int policy)20 static inline int posix_sched_priority_min(int policy)
21 {
22 	if (!valid_posix_policy(policy)) {
23 		errno = EINVAL;
24 		return -1;
25 	}
26 
27 	return 0;
28 }
29 
posix_sched_priority_max(int policy)30 static inline int posix_sched_priority_max(int policy)
31 {
32 	if (IS_ENABLED(CONFIG_COOP_ENABLED) && policy == SCHED_FIFO) {
33 		return CONFIG_NUM_COOP_PRIORITIES - 1;
34 	} else if (IS_ENABLED(CONFIG_PREEMPT_ENABLED) &&
35 		   (policy == SCHED_RR || policy == SCHED_OTHER)) {
36 		return CONFIG_NUM_PREEMPT_PRIORITIES - 1;
37 	}
38 
39 	errno = EINVAL;
40 	return -1;
41 }
42 
43 #endif
44