Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/rbtree.h
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* In linux all of the comparisons are done by the caller. | * In linux all of the comparisons are done by the caller. | ||||
*/ | */ | ||||
int panic_cmp(struct rb_node *one, struct rb_node *two); | int panic_cmp(struct rb_node *one, struct rb_node *two); | ||||
RB_HEAD(linux_root, rb_node); | RB_HEAD(linux_root, rb_node); | ||||
RB_PROTOTYPE(linux_root, rb_node, __entry, panic_cmp); | RB_PROTOTYPE(linux_root, rb_node, __entry, panic_cmp); | ||||
#define rb_parent(r) RB_PARENT(r, __entry) | |||||
#define rb_color(r) RB_COLOR(r, __entry) | |||||
#define rb_is_red(r) (rb_color(r) == RB_RED) | |||||
#define rb_is_black(r) (rb_color(r) == RB_BLACK) | |||||
#define rb_set_parent(r, p) rb_parent((r)) = (p) | |||||
#define rb_set_color(r, c) rb_color((r)) = (c) | |||||
#define rb_entry(ptr, type, member) container_of(ptr, type, member) | #define rb_entry(ptr, type, member) container_of(ptr, type, member) | ||||
#define RB_EMPTY_ROOT(root) RB_EMPTY((struct linux_root *)root) | #define RB_EMPTY_ROOT(root) RB_EMPTY((struct linux_root *)root) | ||||
#define RB_EMPTY_NODE(node) (rb_parent(node) == node) | #define RB_EMPTY_NODE(node) (RB_PARENT(node, __entry) == node) | ||||
#define RB_CLEAR_NODE(node) (rb_set_parent(node, node)) | #define RB_CLEAR_NODE(node) (RB_SET_PARENT(node, node, __entry)) | ||||
#define rb_insert_color(node, root) \ | #define rb_insert_color(node, root) \ | ||||
linux_root_RB_INSERT_COLOR((struct linux_root *)(root), (node)) | linux_root_RB_INSERT_COLOR((struct linux_root *)(root), (node)) | ||||
#define rb_erase(node, root) \ | #define rb_erase(node, root) \ | ||||
linux_root_RB_REMOVE((struct linux_root *)(root), (node)) | linux_root_RB_REMOVE((struct linux_root *)(root), (node)) | ||||
#define rb_next(node) RB_NEXT(linux_root, NULL, (node)) | #define rb_next(node) RB_NEXT(linux_root, NULL, (node)) | ||||
#define rb_prev(node) RB_PREV(linux_root, NULL, (node)) | #define rb_prev(node) RB_PREV(linux_root, NULL, (node)) | ||||
#define rb_first(root) RB_MIN(linux_root, (struct linux_root *)(root)) | #define rb_first(root) RB_MIN(linux_root, (struct linux_root *)(root)) | ||||
#define rb_last(root) RB_MAX(linux_root, (struct linux_root *)(root)) | #define rb_last(root) RB_MAX(linux_root, (struct linux_root *)(root)) | ||||
static inline void | static inline void | ||||
rb_link_node(struct rb_node *node, struct rb_node *parent, | rb_link_node(struct rb_node *node, struct rb_node *parent, | ||||
struct rb_node **rb_link) | struct rb_node **rb_link) | ||||
{ | { | ||||
rb_set_parent(node, parent); | RB_SET(node, parent, __entry); | ||||
rb_set_color(node, RB_RED); | |||||
node->__entry.rbe_left = node->__entry.rbe_right = NULL; | |||||
*rb_link = node; | *rb_link = node; | ||||
} | } | ||||
static inline void | static inline void | ||||
rb_replace_node(struct rb_node *victim, struct rb_node *new, | rb_replace_node(struct rb_node *victim, struct rb_node *new, | ||||
struct rb_root *root) | struct rb_root *root) | ||||
{ | { | ||||
struct rb_node *p; | |||||
p = rb_parent(victim); | RB_SWAP_CHILD((struct linux_root *)root, victim, new, __entry); | ||||
if (p) { | |||||
if (p->rb_left == victim) | |||||
p->rb_left = new; | |||||
else | |||||
p->rb_right = new; | |||||
} else | |||||
root->rb_node = new; | |||||
if (victim->rb_left) | if (victim->rb_left) | ||||
rb_set_parent(victim->rb_left, new); | RB_SET_PARENT(victim->rb_left, new, __entry); | ||||
if (victim->rb_right) | if (victim->rb_right) | ||||
rb_set_parent(victim->rb_right, new); | RB_SET_PARENT(victim->rb_right, new, __entry); | ||||
*new = *victim; | *new = *victim; | ||||
} | } | ||||
#undef RB_ROOT | #undef RB_ROOT | ||||
#define RB_ROOT (struct rb_root) { NULL } | #define RB_ROOT (struct rb_root) { NULL } | ||||
#endif /* _LINUX_RBTREE_H_ */ | #endif /* _LINUX_RBTREE_H_ */ |