fix a kmap leak in virtio_console
[linux/fpc-iii.git] / tools / perf / util / strlist.h
blob5c7f87069d9cd7bfa5412c186068840e76822b2e
1 #ifndef __PERF_STRLIST_H
2 #define __PERF_STRLIST_H
4 #include <linux/rbtree.h>
5 #include <stdbool.h>
7 #include "rblist.h"
9 struct str_node {
10 struct rb_node rb_node;
11 const char *s;
14 struct strlist {
15 struct rblist rblist;
16 bool dupstr;
19 struct strlist *strlist__new(bool dupstr, const char *slist);
20 void strlist__delete(struct strlist *slist);
22 void strlist__remove(struct strlist *slist, struct str_node *sn);
23 int strlist__load(struct strlist *slist, const char *filename);
24 int strlist__add(struct strlist *slist, const char *str);
26 struct str_node *strlist__entry(const struct strlist *slist, unsigned int idx);
27 struct str_node *strlist__find(struct strlist *slist, const char *entry);
29 static inline bool strlist__has_entry(struct strlist *slist, const char *entry)
31 return strlist__find(slist, entry) != NULL;
34 static inline bool strlist__empty(const struct strlist *slist)
36 return rblist__empty(&slist->rblist);
39 static inline unsigned int strlist__nr_entries(const struct strlist *slist)
41 return rblist__nr_entries(&slist->rblist);
44 /* For strlist iteration */
45 static inline struct str_node *strlist__first(struct strlist *slist)
47 struct rb_node *rn = rb_first(&slist->rblist.entries);
48 return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
50 static inline struct str_node *strlist__next(struct str_node *sn)
52 struct rb_node *rn;
53 if (!sn)
54 return NULL;
55 rn = rb_next(&sn->rb_node);
56 return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
59 /**
60 * strlist_for_each - iterate over a strlist
61 * @pos: the &struct str_node to use as a loop cursor.
62 * @slist: the &struct strlist for loop.
64 #define strlist__for_each(pos, slist) \
65 for (pos = strlist__first(slist); pos; pos = strlist__next(pos))
67 /**
68 * strlist_for_each_safe - iterate over a strlist safe against removal of
69 * str_node
70 * @pos: the &struct str_node to use as a loop cursor.
71 * @n: another &struct str_node to use as temporary storage.
72 * @slist: the &struct strlist for loop.
74 #define strlist__for_each_safe(pos, n, slist) \
75 for (pos = strlist__first(slist), n = strlist__next(pos); pos;\
76 pos = n, n = strlist__next(n))
78 int strlist__parse_list(struct strlist *slist, const char *s);
79 #endif /* __PERF_STRLIST_H */