Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __PERF_INTLIST_H
0003 #define __PERF_INTLIST_H
0004 
0005 #include <linux/rbtree.h>
0006 #include <stdbool.h>
0007 
0008 #include "rblist.h"
0009 
0010 struct int_node {
0011     struct rb_node rb_node;
0012     unsigned long i;
0013     void *priv;
0014 };
0015 
0016 struct intlist {
0017     struct rblist rblist;
0018 };
0019 
0020 struct intlist *intlist__new(const char *slist);
0021 void intlist__delete(struct intlist *ilist);
0022 
0023 void intlist__remove(struct intlist *ilist, struct int_node *in);
0024 int intlist__add(struct intlist *ilist, unsigned long i);
0025 
0026 struct int_node *intlist__entry(const struct intlist *ilist, unsigned int idx);
0027 struct int_node *intlist__find(struct intlist *ilist, unsigned long i);
0028 struct int_node *intlist__findnew(struct intlist *ilist, unsigned long i);
0029 
0030 static inline bool intlist__has_entry(struct intlist *ilist, unsigned long i)
0031 {
0032     return intlist__find(ilist, i) != NULL;
0033 }
0034 
0035 static inline bool intlist__empty(const struct intlist *ilist)
0036 {
0037     return rblist__empty(&ilist->rblist);
0038 }
0039 
0040 static inline unsigned int intlist__nr_entries(const struct intlist *ilist)
0041 {
0042     return rblist__nr_entries(&ilist->rblist);
0043 }
0044 
0045 /* For intlist iteration */
0046 static inline struct int_node *intlist__first(struct intlist *ilist)
0047 {
0048     struct rb_node *rn = rb_first_cached(&ilist->rblist.entries);
0049     return rn ? rb_entry(rn, struct int_node, rb_node) : NULL;
0050 }
0051 static inline struct int_node *intlist__next(struct int_node *in)
0052 {
0053     struct rb_node *rn;
0054     if (!in)
0055         return NULL;
0056     rn = rb_next(&in->rb_node);
0057     return rn ? rb_entry(rn, struct int_node, rb_node) : NULL;
0058 }
0059 
0060 /**
0061  * intlist__for_each_entry      - iterate over a intlist
0062  * @pos:    the &struct int_node to use as a loop cursor.
0063  * @ilist:  the &struct intlist for loop.
0064  */
0065 #define intlist__for_each_entry(pos, ilist) \
0066     for (pos = intlist__first(ilist); pos; pos = intlist__next(pos))
0067 
0068 /**
0069  * intlist__for_each_entry_safe - iterate over a intlist safe against removal of
0070  *                         int_node
0071  * @pos:    the &struct int_node to use as a loop cursor.
0072  * @n:      another &struct int_node to use as temporary storage.
0073  * @ilist:  the &struct intlist for loop.
0074  */
0075 #define intlist__for_each_entry_safe(pos, n, ilist) \
0076     for (pos = intlist__first(ilist), n = intlist__next(pos); pos;\
0077          pos = n, n = intlist__next(n))
0078 #endif /* __PERF_INTLIST_H */