1 #ifndef __NETIFD_UTILS_H
2 #define __NETIFD_UTILS_H
4 #include <libubox/list.h>
5 #include <libubox/avl.h>
7 #define __init __attribute__((constructor))
12 typedef void (*vlist_update_cb)(struct vlist_tree *tree,
13 struct vlist_node *node_new,
14 struct vlist_node *node_old);
19 vlist_update_cb update;
32 void __vlist_init(struct vlist_tree *tree, avl_tree_comp cmp, vlist_update_cb update, int offset);
34 #define vlist_init(tree, cmp, update, type, node, key) \
35 __vlist_init(tree, cmp, update, offsetof(type, key) - offsetof(type, node))
37 #define vlist_find(tree, name, element, node_member) \
38 avl_find_element(&(tree)->avl, name, element, node_member.avl)
40 static inline void vlist_update(struct vlist_tree *tree)
45 void vlist_add(struct vlist_tree *tree, struct vlist_node *node);
46 void vlist_delete(struct vlist_tree *tree, struct vlist_node *node);
47 void vlist_flush(struct vlist_tree *tree);
48 void vlist_flush_all(struct vlist_tree *tree);
50 #define vlist_for_each_element(tree, element, node_member) \
51 avl_for_each_element(&(tree)->avl, element, node_member.avl)
54 static inline int fls(int x)
60 if (!(x & 0xffff0000u)) {
64 if (!(x & 0xff000000u)) {
68 if (!(x & 0xf0000000u)) {
72 if (!(x & 0xc0000000u)) {
76 if (!(x & 0x80000000u)) {
84 int avl_strcmp(const void *k1, const void *k2, void *ptr);