aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/thread.c')
-rw-r--r--tools/perf/util/thread.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 0a9ae8014729..dfd00c6dad6e 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -19,8 +19,10 @@ int thread__init_map_groups(struct thread *thread, struct machine *machine)
19 thread->mg = map_groups__new(machine); 19 thread->mg = map_groups__new(machine);
20 } else { 20 } else {
21 leader = __machine__findnew_thread(machine, pid, pid); 21 leader = __machine__findnew_thread(machine, pid, pid);
22 if (leader) 22 if (leader) {
23 thread->mg = map_groups__get(leader->mg); 23 thread->mg = map_groups__get(leader->mg);
24 thread__put(leader);
25 }
24 } 26 }
25 27
26 return thread->mg ? 0 : -1; 28 return thread->mg ? 0 : -1;
@@ -53,7 +55,7 @@ struct thread *thread__new(pid_t pid, pid_t tid)
53 goto err_thread; 55 goto err_thread;
54 56
55 list_add(&comm->list, &thread->comm_list); 57 list_add(&comm->list, &thread->comm_list);
56 atomic_set(&thread->refcnt, 0); 58 atomic_set(&thread->refcnt, 1);
57 RB_CLEAR_NODE(&thread->rb_node); 59 RB_CLEAR_NODE(&thread->rb_node);
58 } 60 }
59 61
@@ -95,6 +97,10 @@ struct thread *thread__get(struct thread *thread)
95void thread__put(struct thread *thread) 97void thread__put(struct thread *thread)
96{ 98{
97 if (thread && atomic_dec_and_test(&thread->refcnt)) { 99 if (thread && atomic_dec_and_test(&thread->refcnt)) {
100 /*
101 * Remove it from the dead_threads list, as last reference
102 * is gone.
103 */
98 list_del_init(&thread->node); 104 list_del_init(&thread->node);
99 thread__delete(thread); 105 thread__delete(thread);
100 } 106 }