diff options
| author | Jin Yao <yao.jin@linux.intel.com> | 2017-12-01 05:57:25 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-12-05 08:24:31 -0500 |
| commit | 33fec3e393dc1c55737cfb9c876b5c0da0d6f380 (patch) | |
| tree | 12da9860e4e7d26ad85a99b6ecd5127d0a9d9fec | |
| parent | 35a8a148d8c1ee9e5ae18f9565a880490f816f89 (diff) | |
perf rblist: Create rblist__exit() function
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>
| -rw-r--r-- | tools/perf/util/rblist.c | 19 | ||||
| -rw-r--r-- | tools/perf/util/rblist.h | 1 |
2 files changed, 13 insertions, 7 deletions
diff --git a/tools/perf/util/rblist.c b/tools/perf/util/rblist.c index 0dfe27d99458..0efc3258c648 100644 --- a/tools/perf/util/rblist.c +++ b/tools/perf/util/rblist.c | |||
| @@ -101,16 +101,21 @@ void rblist__init(struct rblist *rblist) | |||
| 101 | return; | 101 | return; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | void rblist__exit(struct rblist *rblist) | ||
| 105 | { | ||
| 106 | struct rb_node *pos, *next = rb_first(&rblist->entries); | ||
| 107 | |||
| 108 | while (next) { | ||
| 109 | pos = next; | ||
| 110 | next = rb_next(pos); | ||
| 111 | rblist__remove_node(rblist, pos); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 104 | void rblist__delete(struct rblist *rblist) | 115 | void rblist__delete(struct rblist *rblist) |
| 105 | { | 116 | { |
| 106 | if (rblist != NULL) { | 117 | if (rblist != NULL) { |
| 107 | struct rb_node *pos, *next = rb_first(&rblist->entries); | 118 | rblist__exit(rblist); |
| 108 | |||
| 109 | while (next) { | ||
| 110 | pos = next; | ||
| 111 | next = rb_next(pos); | ||
| 112 | rblist__remove_node(rblist, pos); | ||
| 113 | } | ||
| 114 | free(rblist); | 119 | free(rblist); |
| 115 | } | 120 | } |
| 116 | } | 121 | } |
diff --git a/tools/perf/util/rblist.h b/tools/perf/util/rblist.h index 4c8638a22571..76df15c27f5f 100644 --- a/tools/perf/util/rblist.h +++ b/tools/perf/util/rblist.h | |||
| @@ -29,6 +29,7 @@ struct rblist { | |||
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | void rblist__init(struct rblist *rblist); | 31 | void rblist__init(struct rblist *rblist); |
| 32 | void rblist__exit(struct rblist *rblist); | ||
| 32 | void rblist__delete(struct rblist *rblist); | 33 | void rblist__delete(struct rblist *rblist); |
| 33 | int rblist__add_node(struct rblist *rblist, const void *new_entry); | 34 | int rblist__add_node(struct rblist *rblist, const void *new_entry); |
| 34 | void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node); | 35 | void rblist__remove_node(struct rblist *rblist, struct rb_node *rb_node); |
