mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-16 23:45:31 +08:00
33fec3e393
Currently we have a rblist__delete() which is used to delete a rblist. While rblist__delete() will free the pointer of rblist at the end. It's an inconvenience for the user to delete a rblist which is not allocated by something like malloc(). For example, the rblist is embedded in a larger data structure. This patch creates a new function rblist__exit() which is similar to rblist__delete() but it will not free the pointer of rblist. Signed-off-by: Jin Yao <yao.jin@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1512125856-22056-2-git-send-email-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
51 lines
1.4 KiB
C
51 lines
1.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __PERF_RBLIST_H
|
|
#define __PERF_RBLIST_H
|
|
|
|
#include <linux/rbtree.h>
|
|
#include <stdbool.h>
|
|
|
|
/*
|
|
* create node structs of the form:
|
|
* struct my_node {
|
|
* struct rb_node rb_node;
|
|
* ... my data ...
|
|
* };
|
|
*
|
|
* create list structs of the form:
|
|
* struct mylist {
|
|
* struct rblist rblist;
|
|
* ... my data ...
|
|
* };
|
|
*/
|
|
|
|
struct rblist {
|
|
struct rb_root entries;
|
|
unsigned int nr_entries;
|
|
|
|
int (*node_cmp)(struct rb_node *rbn, const void *entry);
|
|
struct rb_node *(*node_new)(struct rblist *rlist, const void *new_entry);
|
|
void (*node_delete)(struct rblist *rblist, struct rb_node *rb_node);
|
|
};
|
|
|
|
void rblist__init(struct rblist *rblist);
|
|
void rblist__exit(struct rblist *rblist);
|
|
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)
|
|
{
|
|
return rblist->nr_entries == 0;
|
|
}
|
|
|
|
static inline unsigned int rblist__nr_entries(const struct rblist *rblist)
|
|
{
|
|
return rblist->nr_entries;
|
|
}
|
|
|
|
#endif /* __PERF_RBLIST_H */
|