diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/comm.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tools/perf/util/comm.c b/tools/perf/util/comm.c index b2bb59df65e1..21b7ff382c3f 100644 --- a/tools/perf/util/comm.c +++ b/tools/perf/util/comm.c | |||
@@ -2,24 +2,27 @@ | |||
2 | #include "util.h" | 2 | #include "util.h" |
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <linux/atomic.h> | ||
5 | 6 | ||
6 | struct comm_str { | 7 | struct comm_str { |
7 | char *str; | 8 | char *str; |
8 | struct rb_node rb_node; | 9 | struct rb_node rb_node; |
9 | int ref; | 10 | atomic_t refcnt; |
10 | }; | 11 | }; |
11 | 12 | ||
12 | /* Should perhaps be moved to struct machine */ | 13 | /* Should perhaps be moved to struct machine */ |
13 | static struct rb_root comm_str_root; | 14 | static struct rb_root comm_str_root; |
14 | 15 | ||
15 | static void comm_str__get(struct comm_str *cs) | 16 | static struct comm_str *comm_str__get(struct comm_str *cs) |
16 | { | 17 | { |
17 | cs->ref++; | 18 | if (cs) |
19 | atomic_inc(&cs->refcnt); | ||
20 | return cs; | ||
18 | } | 21 | } |
19 | 22 | ||
20 | static void comm_str__put(struct comm_str *cs) | 23 | static void comm_str__put(struct comm_str *cs) |
21 | { | 24 | { |
22 | if (!--cs->ref) { | 25 | if (cs && atomic_dec_and_test(&cs->refcnt)) { |
23 | rb_erase(&cs->rb_node, &comm_str_root); | 26 | rb_erase(&cs->rb_node, &comm_str_root); |
24 | zfree(&cs->str); | 27 | zfree(&cs->str); |
25 | free(cs); | 28 | free(cs); |
@@ -40,6 +43,8 @@ static struct comm_str *comm_str__alloc(const char *str) | |||
40 | return NULL; | 43 | return NULL; |
41 | } | 44 | } |
42 | 45 | ||
46 | atomic_set(&cs->refcnt, 0); | ||
47 | |||
43 | return cs; | 48 | return cs; |
44 | } | 49 | } |
45 | 50 | ||