diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-02-04 16:57:06 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-04 16:57:06 -0500 |
commit | d5636fc29f6c8391428e4441c85ae5766e3724b5 (patch) | |
tree | 97ca8d1a73c684985a66f03809d49ef0cefc5704 | |
parent | fc061d0f3d0d22fa1764ecba7bf91178cc1bc36b (diff) |
parse-events: Add ref count to pevent
Add a ref counter to pevent so more than on object can share it and
not worry about which one will free it.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | parse-events.c | 15 | ||||
-rw-r--r-- | parse-events.h | 4 |
2 files changed, 19 insertions, 0 deletions
diff --git a/parse-events.c b/parse-events.c index 672fd84..627f4a1 100644 --- a/parse-events.c +++ b/parse-events.c | |||
@@ -3830,10 +3830,16 @@ struct pevent *pevent_alloc(void) | |||
3830 | if (!pevent) | 3830 | if (!pevent) |
3831 | return NULL; | 3831 | return NULL; |
3832 | memset(pevent, 0, sizeof(*pevent)); | 3832 | memset(pevent, 0, sizeof(*pevent)); |
3833 | pevent->ref_count = 1; | ||
3833 | 3834 | ||
3834 | return pevent; | 3835 | return pevent; |
3835 | } | 3836 | } |
3836 | 3837 | ||
3838 | void pevent_ref(struct pevent *pevent) | ||
3839 | { | ||
3840 | pevent->ref_count++; | ||
3841 | } | ||
3842 | |||
3837 | static void free_format_fields(struct format_field *field) | 3843 | static void free_format_fields(struct format_field *field) |
3838 | { | 3844 | { |
3839 | struct format_field *next; | 3845 | struct format_field *next; |
@@ -3878,6 +3884,10 @@ void pevent_free(struct pevent *pevent) | |||
3878 | struct printk_list *printklist = pevent->printklist, *printknext; | 3884 | struct printk_list *printklist = pevent->printklist, *printknext; |
3879 | int i; | 3885 | int i; |
3880 | 3886 | ||
3887 | pevent->ref_count--; | ||
3888 | if (pevent->ref_count) | ||
3889 | return; | ||
3890 | |||
3881 | if (pevent->cmdlines) { | 3891 | if (pevent->cmdlines) { |
3882 | for (i = 0; i < pevent->cmdline_count; i++) | 3892 | for (i = 0; i < pevent->cmdline_count; i++) |
3883 | free(pevent->cmdlines[i].comm); | 3893 | free(pevent->cmdlines[i].comm); |
@@ -3930,3 +3940,8 @@ void pevent_free(struct pevent *pevent) | |||
3930 | 3940 | ||
3931 | free(pevent); | 3941 | free(pevent); |
3932 | } | 3942 | } |
3943 | |||
3944 | void pevent_unref(struct pevent *pevent) | ||
3945 | { | ||
3946 | pevent_free(pevent); | ||
3947 | } | ||
diff --git a/parse-events.h b/parse-events.h index 1866299..e6ea2ab 100644 --- a/parse-events.h +++ b/parse-events.h | |||
@@ -226,6 +226,8 @@ struct func_map; | |||
226 | struct func_list; | 226 | struct func_list; |
227 | 227 | ||
228 | struct pevent { | 228 | struct pevent { |
229 | int ref_count; | ||
230 | |||
229 | int header_page_ts_offset; | 231 | int header_page_ts_offset; |
230 | int header_page_ts_size; | 232 | int header_page_ts_size; |
231 | int header_page_size_offset; | 233 | int header_page_size_offset; |
@@ -444,6 +446,8 @@ static inline void pevent_set_latency_format(struct pevent *pevent, int lat) | |||
444 | 446 | ||
445 | struct pevent *pevent_alloc(void); | 447 | struct pevent *pevent_alloc(void); |
446 | void pevent_free(struct pevent *pevent); | 448 | void pevent_free(struct pevent *pevent); |
449 | void pevent_ref(struct pevent *pevent); | ||
450 | void pevent_unref(struct pevent *pevent); | ||
447 | 451 | ||
448 | /* for debugging */ | 452 | /* for debugging */ |
449 | void pevent_print_funcs(struct pevent *pevent); | 453 | void pevent_print_funcs(struct pevent *pevent); |