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 <benjamin.walsh@windriver.com>
This commit is contained in:
Benjamin Walsh 2016-11-08 15:40:42 -05:00 committed by Benjamin Walsh
parent 8450c903be
commit c13fad3bb8
1 changed files with 30 additions and 0 deletions

View File

@ -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)
{