Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753307AbbLICTM (ORCPT ); Tue, 8 Dec 2015 21:19:12 -0500 Received: from mail9.hitachi.co.jp ([133.145.228.44]:50899 "EHLO mail9.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753242AbbLICTI (ORCPT ); Tue, 8 Dec 2015 21:19:08 -0500 X-AuditID: 85900ec0-9e1cab9000001a57-b7-56678f9815ec Subject: [PATCH perf/core 12/22] perf: Make thread_map to use refcnt for debug From: Masami Hiramatsu To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Adrian Hunter , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Ingo Molnar , Namhyung Kim , Jiri Olsa Date: Wed, 09 Dec 2015 11:11:14 +0900 Message-ID: <20151209021114.10245.78998.stgit@localhost.localdomain> In-Reply-To: <20151209021047.10245.8918.stgit@localhost.localdomain> References: <20151209021047.10245.8918.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3381 Lines: 110 Make 'thread_map' object to use refcnt interface for debug. This can find refcnt related memory leaks. Signed-off-by: Masami Hiramatsu --- tools/perf/util/thread_map.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index 6ec3c5c..a87eae4 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -13,6 +13,7 @@ #include "thread_map.h" #include "util.h" #include "debug.h" +#include "refcnt.h" /* Skip "." and ".." directories */ static int filter(const struct dirent *dir) @@ -65,7 +66,7 @@ struct thread_map *thread_map__new_by_pid(pid_t pid) for (i = 0; i < items; i++) thread_map__set_pid(threads, i, atoi(namelist[i]->d_name)); threads->nr = items; - atomic_set(&threads->refcnt, 1); + refcnt__init_as(threads, refcnt, 1, "thread_map"); } for (i=0; inr = 1; - atomic_set(&threads->refcnt, 1); + refcnt__init_as(threads, refcnt, 1, "thread_map"); } return threads; @@ -104,7 +105,7 @@ struct thread_map *thread_map__new_by_uid(uid_t uid) goto out_free_threads; threads->nr = 0; - atomic_set(&threads->refcnt, 1); + refcnt__init_as(threads, refcnt, 1, "thread_map"); while (!readdir_r(proc, &dirent, &next) && next) { char *end; @@ -234,7 +235,7 @@ static struct thread_map *thread_map__new_by_pid_str(const char *pid_str) out: strlist__delete(slist); if (threads) - atomic_set(&threads->refcnt, 1); + refcnt__init_as(threads, refcnt, 1, "thread_map"); return threads; out_free_namelist: @@ -254,7 +255,7 @@ struct thread_map *thread_map__new_dummy(void) if (threads != NULL) { thread_map__set_pid(threads, 0, -1); threads->nr = 1; - atomic_set(&threads->refcnt, 1); + refcnt__init_as(threads, refcnt, 1, "thread_map"); } return threads; } @@ -299,7 +300,7 @@ static struct thread_map *thread_map__new_by_tid_str(const char *tid_str) } out: if (threads) - atomic_set(&threads->refcnt, 1); + refcnt__init_as(threads, refcnt, 1, "thread_map"); return threads; out_free_threads: @@ -328,21 +329,22 @@ static void thread_map__delete(struct thread_map *threads) "thread map refcnt unbalanced\n"); for (i = 0; i < threads->nr; i++) free(thread_map__comm(threads, i)); + refcnt__exit(threads, refcnt); free(threads); } } -struct thread_map *thread_map__get(struct thread_map *map) +struct thread_map *thread_map__get(struct thread_map *threads) { - if (map) - atomic_inc(&map->refcnt); - return map; + if (threads) + refcnt__get(threads, refcnt); + return threads; } -void thread_map__put(struct thread_map *map) +void thread_map__put(struct thread_map *threads) { - if (map && atomic_dec_and_test(&map->refcnt)) - thread_map__delete(map); + if (threads && refcnt__put(threads, refcnt)) + thread_map__delete(threads); } size_t thread_map__fprintf(struct thread_map *threads, FILE *fp) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/