diff options
Diffstat (limited to 'tools/perf/util/rblist.c')
| -rw-r--r-- | tools/perf/util/rblist.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/tools/perf/util/rblist.c b/tools/perf/util/rblist.c index a16cdd2625ad..0dfe27d99458 100644 --- a/tools/perf/util/rblist.c +++ b/tools/perf/util/rblist.c | |||
| @@ -48,10 +48,12 @@ void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node) | |||
| 48 | rblist->node_delete(rblist, rb_node); | 48 | rblist->node_delete(rblist, rb_node); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | struct rb_node *rblist__find(struct rblist *rblist, const void *entry) | 51 | static struct rb_node *__rblist__findnew(struct rblist *rblist, |
| 52 | const void *entry, | ||
| 53 | bool create) | ||
| 52 | { | 54 | { |
| 53 | struct rb_node **p = &rblist->entries.rb_node; | 55 | struct rb_node **p = &rblist->entries.rb_node; |
| 54 | struct rb_node *parent = NULL; | 56 | struct rb_node *parent = NULL, *new_node = NULL; |
| 55 | 57 | ||
| 56 | while (*p != NULL) { | 58 | while (*p != NULL) { |
| 57 | int rc; | 59 | int rc; |
| @@ -67,7 +69,26 @@ struct rb_node *rblist__find(struct rblist *rblist, const void *entry) | |||
| 67 | return parent; | 69 | return parent; |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | return NULL; | 72 | if (create) { |
| 73 | new_node = rblist->node_new(rblist, entry); | ||
| 74 | if (new_node) { | ||
| 75 | rb_link_node(new_node, parent, p); | ||
| 76 | rb_insert_color(new_node, &rblist->entries); | ||
| 77 | ++rblist->nr_entries; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | return new_node; | ||
| 82 | } | ||
| 83 | |||
| 84 | struct rb_node *rblist__find(struct rblist *rblist, const void *entry) | ||
| 85 | { | ||
| 86 | return __rblist__findnew(rblist, entry, false); | ||
| 87 | } | ||
| 88 | |||
| 89 | struct rb_node *rblist__findnew(struct rblist *rblist, const void *entry) | ||
| 90 | { | ||
| 91 | return __rblist__findnew(rblist, entry, true); | ||
| 71 | } | 92 | } |
| 72 | 93 | ||
| 73 | void rblist__init(struct rblist *rblist) | 94 | void rblist__init(struct rblist *rblist) |
