diff options
Diffstat (limited to 'tools/perf/lib/cpumap.c')
-rw-r--r-- | tools/perf/lib/cpumap.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c index 80d587ab95aa..f3cfb4c71106 100644 --- a/tools/perf/lib/cpumap.c +++ b/tools/perf/lib/cpumap.c | |||
@@ -3,6 +3,8 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <linux/refcount.h> | 4 | #include <linux/refcount.h> |
5 | #include <internal/cpumap.h> | 5 | #include <internal/cpumap.h> |
6 | #include <asm/bug.h> | ||
7 | #include <stdio.h> | ||
6 | 8 | ||
7 | struct perf_cpu_map *perf_cpu_map__dummy_new(void) | 9 | struct perf_cpu_map *perf_cpu_map__dummy_new(void) |
8 | { | 10 | { |
@@ -16,3 +18,25 @@ struct perf_cpu_map *perf_cpu_map__dummy_new(void) | |||
16 | 18 | ||
17 | return cpus; | 19 | return cpus; |
18 | } | 20 | } |
21 | |||
22 | static void cpu_map__delete(struct perf_cpu_map *map) | ||
23 | { | ||
24 | if (map) { | ||
25 | WARN_ONCE(refcount_read(&map->refcnt) != 0, | ||
26 | "cpu_map refcnt unbalanced\n"); | ||
27 | free(map); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map) | ||
32 | { | ||
33 | if (map) | ||
34 | refcount_inc(&map->refcnt); | ||
35 | return map; | ||
36 | } | ||
37 | |||
38 | void perf_cpu_map__put(struct perf_cpu_map *map) | ||
39 | { | ||
40 | if (map && refcount_dec_and_test(&map->refcnt)) | ||
41 | cpu_map__delete(map); | ||
42 | } | ||