Go to the documentation of this file. 2 #ifndef _PERF_RESORT_RB_H_ 3 #define _PERF_RESORT_RB_H_ 55 #define DEFINE_RESORT_RB(__name, __comp, ...) \ 56 struct __name##_sorted_entry { \ 57 struct rb_node rb_node; \ 60 static void __name##_sorted__init_entry(struct rb_node *nd, \ 61 struct __name##_sorted_entry *entry); \ 63 static int __name##_sorted__cmp(struct rb_node *nda, struct rb_node *ndb) \ 65 struct __name##_sorted_entry *a, *b; \ 66 a = rb_entry(nda, struct __name##_sorted_entry, rb_node); \ 67 b = rb_entry(ndb, struct __name##_sorted_entry, rb_node); \ 71 struct __name##_sorted { \ 72 struct rb_root entries; \ 73 struct __name##_sorted_entry nd[0]; \ 76 static void __name##_sorted__insert(struct __name##_sorted *sorted, \ 77 struct rb_node *sorted_nd) \ 79 struct rb_node **p = &sorted->entries.rb_node, *parent = NULL; \ 80 while (*p != NULL) { \ 82 if (__name##_sorted__cmp(sorted_nd, parent)) \ 85 p = &(*p)->rb_right; \ 87 rb_link_node(sorted_nd, parent, p); \ 88 rb_insert_color(sorted_nd, &sorted->entries); \ 91 static void __name##_sorted__sort(struct __name##_sorted *sorted, \ 92 struct rb_root *entries) \ 96 for (nd = rb_first(entries); nd; nd = rb_next(nd)) { \ 97 struct __name##_sorted_entry *snd = &sorted->nd[i++]; \ 98 __name##_sorted__init_entry(nd, snd); \ 99 __name##_sorted__insert(sorted, &snd->rb_node); \ 103 static struct __name##_sorted *__name##_sorted__new(struct rb_root *entries, \ 106 struct __name##_sorted *sorted; \ 107 sorted = malloc(sizeof(*sorted) + sizeof(sorted->nd[0]) * nr_entries); \ 109 sorted->entries = RB_ROOT; \ 110 __name##_sorted__sort(sorted, entries); \ 115 static void __name##_sorted__delete(struct __name##_sorted *sorted) \ 120 static void __name##_sorted__init_entry(struct rb_node *nd, \ 121 struct __name##_sorted_entry *entry) 123 #define DECLARE_RESORT_RB(__name) \ 124 struct __name##_sorted_entry *__name##_entry; \ 125 struct __name##_sorted *__name = __name##_sorted__new 127 #define resort_rb__for_each_entry(__nd, __name) \ 128 for (__nd = rb_first(&__name->entries); \ 129 __name##_entry = rb_entry(__nd, struct __name##_sorted_entry, \ 131 __nd = rb_next(__nd)) 133 #define resort_rb__delete(__name) \ 134 __name##_sorted__delete(__name), __name = NULL 142 #define DECLARE_RESORT_RB_INTLIST(__name, __ilist) \ 143 DECLARE_RESORT_RB(__name)(&__ilist->rblist.entries, \ 144 __ilist->rblist.nr_entries) 147 #define DECLARE_RESORT_RB_MACHINE_THREADS(__name, __machine, hash_bucket) \ 148 DECLARE_RESORT_RB(__name)(&__machine->threads[hash_bucket].entries, \ 149 __machine->threads[hash_bucket].nr)