提交 813335b8 编写于 作者: D David Ahern 提交者: Arnaldo Carvalho de Melo

perf util: Add findnew method to intlist

Similar to other findnew based methods if the requested object is not
found, add it to the list.

v2: followed format of other findnew methods per acme's request
Signed-off-by: NDavid Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1381289214-24885-2-git-send-email-dsahern@gmail.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 87f91868
......@@ -58,22 +58,36 @@ void intlist__remove(struct intlist *ilist, struct int_node *node)
rblist__remove_node(&ilist->rblist, &node->rb_node);
}
struct int_node *intlist__find(struct intlist *ilist, int i)
static struct int_node *__intlist__findnew(struct intlist *ilist,
int i, bool create)
{
struct int_node *node;
struct int_node *node = NULL;
struct rb_node *rb_node;
if (ilist == NULL)
return NULL;
node = NULL;
rb_node = rblist__find(&ilist->rblist, (void *)((long)i));
if (create)
rb_node = rblist__findnew(&ilist->rblist, (void *)((long)i));
else
rb_node = rblist__find(&ilist->rblist, (void *)((long)i));
if (rb_node)
node = container_of(rb_node, struct int_node, rb_node);
return node;
}
struct int_node *intlist__find(struct intlist *ilist, int i)
{
return __intlist__findnew(ilist, i, false);
}
struct int_node *intlist__findnew(struct intlist *ilist, int i)
{
return __intlist__findnew(ilist, i, true);
}
static int intlist__parse_list(struct intlist *ilist, const char *s)
{
char *sep;
......
......@@ -24,6 +24,7 @@ int intlist__add(struct intlist *ilist, int i);
struct int_node *intlist__entry(const struct intlist *ilist, unsigned int idx);
struct int_node *intlist__find(struct intlist *ilist, int i);
struct int_node *intlist__findnew(struct intlist *ilist, int i);
static inline bool intlist__has_entry(struct intlist *ilist, int i)
{
......
......@@ -48,10 +48,12 @@ void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node)
rblist->node_delete(rblist, rb_node);
}
struct rb_node *rblist__find(struct rblist *rblist, const void *entry)
static struct rb_node *__rblist__findnew(struct rblist *rblist,
const void *entry,
bool create)
{
struct rb_node **p = &rblist->entries.rb_node;
struct rb_node *parent = NULL;
struct rb_node *parent = NULL, *new_node = NULL;
while (*p != NULL) {
int rc;
......@@ -67,7 +69,26 @@ struct rb_node *rblist__find(struct rblist *rblist, const void *entry)
return parent;
}
return NULL;
if (create) {
new_node = rblist->node_new(rblist, entry);
if (new_node) {
rb_link_node(new_node, parent, p);
rb_insert_color(new_node, &rblist->entries);
++rblist->nr_entries;
}
}
return new_node;
}
struct rb_node *rblist__find(struct rblist *rblist, const void *entry)
{
return __rblist__findnew(rblist, entry, false);
}
struct rb_node *rblist__findnew(struct rblist *rblist, const void *entry)
{
return __rblist__findnew(rblist, entry, true);
}
void rblist__init(struct rblist *rblist)
......
......@@ -32,6 +32,7 @@ void rblist__delete(struct rblist *rblist);
int rblist__add_node(struct rblist *rblist, const void *new_entry);
void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node);
struct rb_node *rblist__find(struct rblist *rblist, const void *entry);
struct rb_node *rblist__findnew(struct rblist *rblist, const void *entry);
struct rb_node *rblist__entry(const struct rblist *rblist, unsigned int idx);
static inline bool rblist__empty(const struct rblist *rblist)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册