Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __PERF_RBLIST_H
0003 #define __PERF_RBLIST_H
0004 
0005 #include <linux/rbtree.h>
0006 #include <stdbool.h>
0007 
0008 /*
0009  * create node structs of the form:
0010  * struct my_node {
0011  *     struct rb_node rb_node;
0012  *     ... my data ...
0013  * };
0014  *
0015  * create list structs of the form:
0016  * struct mylist {
0017  *     struct rblist rblist;
0018  *     ... my data ...
0019  * };
0020  */
0021 
0022 struct rblist {
0023     struct rb_root_cached entries;
0024     unsigned int   nr_entries;
0025 
0026     int (*node_cmp)(struct rb_node *rbn, const void *entry);
0027     struct rb_node *(*node_new)(struct rblist *rlist, const void *new_entry);
0028     void (*node_delete)(struct rblist *rblist, struct rb_node *rb_node);
0029 };
0030 
0031 void rblist__init(struct rblist *rblist);
0032 void rblist__exit(struct rblist *rblist);
0033 void rblist__delete(struct rblist *rblist);
0034 int rblist__add_node(struct rblist *rblist, const void *new_entry);
0035 void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node);
0036 struct rb_node *rblist__find(struct rblist *rblist, const void *entry);
0037 struct rb_node *rblist__findnew(struct rblist *rblist, const void *entry);
0038 struct rb_node *rblist__entry(const struct rblist *rblist, unsigned int idx);
0039 
0040 static inline bool rblist__empty(const struct rblist *rblist)
0041 {
0042     return rblist->nr_entries == 0;
0043 }
0044 
0045 static inline unsigned int rblist__nr_entries(const struct rblist *rblist)
0046 {
0047     return rblist->nr_entries;
0048 }
0049 
0050 #endif /* __PERF_RBLIST_H */