1 /*
2  * Copyright (c) 2018,2024 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <ksched.h>
9 #include <zephyr/sys/math_extras.h>
10 #include <zephyr/sys/dlist.h>
11 
z_priq_rb_lessthan(struct rbnode * a,struct rbnode * b)12 bool z_priq_rb_lessthan(struct rbnode *a, struct rbnode *b)
13 {
14 	struct k_thread *thread_a, *thread_b;
15 	int32_t cmp;
16 
17 	thread_a = CONTAINER_OF(a, struct k_thread, base.qnode_rb);
18 	thread_b = CONTAINER_OF(b, struct k_thread, base.qnode_rb);
19 
20 	cmp = z_sched_prio_cmp(thread_a, thread_b);
21 
22 	if (cmp > 0) {
23 		return true;
24 	} else if (cmp < 0) {
25 		return false;
26 	} else {
27 		return thread_a->base.order_key < thread_b->base.order_key
28 			? 1 : 0;
29 	}
30 }
31