From c13fad3bb874387b89b04a8648a713526079414e Mon Sep 17 00:00:00 2001 From: Benjamin Walsh Date: Tue, 8 Nov 2016 15:40:42 -0500 Subject: [PATCH] kernel: add utility functions to compare thread priorities Since lower-numbered thread priorities are higher, the code can be misleading when comparing priorities, and often require the same type of comments. Instead, use utility inline functions that does the comparisons. _is_prio_higher already existed, but add comparisons for "lower than", "higher than or equal to" and "lower than or equal to". Change-Id: I8b58fe9a3dd0eb70e224e970fe851a2575ad468b Signed-off-by: Benjamin Walsh --- kernel/unified/include/ksched.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/kernel/unified/include/ksched.h b/kernel/unified/include/ksched.h index 0073dc7edb4..e629a739d82 100644 --- a/kernel/unified/include/ksched.h +++ b/kernel/unified/include/ksched.h @@ -50,6 +50,16 @@ extern int32_t _ms_to_ticks(int32_t ms); * like overkill. */ +static inline int _is_prio1_higher_than_or_equal_to_prio2(int prio1, int prio2) +{ + return prio1 <= prio2; +} + +static inline int _is_prio_higher_or_equal(int prio1, int prio2) +{ + return _is_prio1_higher_than_or_equal_to_prio2(prio1, prio2); +} + static inline int _is_prio1_higher_than_prio2(int prio1, int prio2) { return prio1 < prio2; @@ -60,6 +70,26 @@ static inline int _is_prio_higher(int prio, int test_prio) return _is_prio1_higher_than_prio2(prio, test_prio); } +static inline int _is_prio1_lower_than_or_equal_to_prio2(int prio1, int prio2) +{ + return prio1 >= prio2; +} + +static inline int _is_prio_lower_or_equal(int prio1, int prio2) +{ + return _is_prio1_lower_than_or_equal_to_prio2(prio1, prio2); +} + +static inline int _is_prio1_lower_than_prio2(int prio1, int prio2) +{ + return prio1 > prio2; +} + +static inline int _is_prio_lower(int prio1, int prio2) +{ + return _is_prio1_lower_than_prio2(prio1, prio2); +} + static inline int _is_t1_higher_prio_than_t2(struct k_thread *t1, struct k_thread *t2) {