aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/comm.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2015-05-19 18:07:42 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-05-27 11:21:43 -0400
commit86c19525b7e953217e5ad2b5496029b1ac6fe26b (patch)
tree8c962146fd6350a0b1073318e8b5eef8601521da /tools/perf/util/comm.c
parente7e0efcdb807a570b11f240e2608d7aed5ccdfb1 (diff)
perf comm: Use atomic.h for refcounting
Now that we have atomic.h, we should convert all of the existing refcounts to use it. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Don Zickus <dzickus@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-quzeuy3jwsyod6e06o39cl6y@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/comm.c')
-rw-r--r--tools/perf/util/comm.c13
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
6struct comm_str { 7struct 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 */
13static struct rb_root comm_str_root; 14static struct rb_root comm_str_root;
14 15
15static void comm_str__get(struct comm_str *cs) 16static 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
20static void comm_str__put(struct comm_str *cs) 23static 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