Lines Matching refs:thread
13 int thread__init_map_groups(struct thread *thread, struct machine *machine) in thread__init_map_groups() argument
15 struct thread *leader; in thread__init_map_groups()
16 pid_t pid = thread->pid_; in thread__init_map_groups()
18 if (pid == thread->tid || pid == -1) { in thread__init_map_groups()
19 thread->mg = map_groups__new(machine); in thread__init_map_groups()
23 thread->mg = map_groups__get(leader->mg); in thread__init_map_groups()
26 return thread->mg ? 0 : -1; in thread__init_map_groups()
29 struct thread *thread__new(pid_t pid, pid_t tid) in thread__new()
33 struct thread *thread = zalloc(sizeof(*thread)); in thread__new() local
35 if (thread != NULL) { in thread__new()
36 thread->pid_ = pid; in thread__new()
37 thread->tid = tid; in thread__new()
38 thread->ppid = -1; in thread__new()
39 thread->cpu = -1; in thread__new()
40 INIT_LIST_HEAD(&thread->comm_list); in thread__new()
42 if (unwind__prepare_access(thread) < 0) in thread__new()
55 list_add(&comm->list, &thread->comm_list); in thread__new()
59 return thread; in thread__new()
62 free(thread); in thread__new()
66 void thread__delete(struct thread *thread) in thread__delete() argument
70 thread_stack__free(thread); in thread__delete()
72 if (thread->mg) { in thread__delete()
73 map_groups__put(thread->mg); in thread__delete()
74 thread->mg = NULL; in thread__delete()
76 list_for_each_entry_safe(comm, tmp, &thread->comm_list, list) { in thread__delete()
80 unwind__finish_access(thread); in thread__delete()
82 free(thread); in thread__delete()
85 struct thread *thread__get(struct thread *thread) in thread__get() argument
87 ++thread->refcnt; in thread__get()
88 return thread; in thread__get()
91 void thread__put(struct thread *thread) in thread__put() argument
93 if (thread && --thread->refcnt == 0) { in thread__put()
94 list_del_init(&thread->node); in thread__put()
95 thread__delete(thread); in thread__put()
99 struct comm *thread__comm(const struct thread *thread) in thread__comm() argument
101 if (list_empty(&thread->comm_list)) in thread__comm()
104 return list_first_entry(&thread->comm_list, struct comm, list); in thread__comm()
107 struct comm *thread__exec_comm(const struct thread *thread) in thread__exec_comm() argument
111 list_for_each_entry(comm, &thread->comm_list, list) { in thread__exec_comm()
120 int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, in __thread__set_comm() argument
123 struct comm *new, *curr = thread__comm(thread); in __thread__set_comm()
127 if (!thread->comm_set) { in __thread__set_comm()
135 list_add(&new->list, &thread->comm_list); in __thread__set_comm()
138 unwind__flush_access(thread); in __thread__set_comm()
141 thread->comm_set = true; in __thread__set_comm()
146 const char *thread__comm_str(const struct thread *thread) in thread__comm_str() argument
148 const struct comm *comm = thread__comm(thread); in thread__comm_str()
157 int thread__comm_len(struct thread *thread) in thread__comm_len() argument
159 if (!thread->comm_len) { in thread__comm_len()
160 const char *comm = thread__comm_str(thread); in thread__comm_len()
163 thread->comm_len = strlen(comm); in thread__comm_len()
166 return thread->comm_len; in thread__comm_len()
169 size_t thread__fprintf(struct thread *thread, FILE *fp) in thread__fprintf() argument
171 return fprintf(fp, "Thread %d %s\n", thread->tid, thread__comm_str(thread)) + in thread__fprintf()
172 map_groups__fprintf(thread->mg, fp); in thread__fprintf()
175 void thread__insert_map(struct thread *thread, struct map *map) in thread__insert_map() argument
177 map_groups__fixup_overlappings(thread->mg, map, stderr); in thread__insert_map()
178 map_groups__insert(thread->mg, map); in thread__insert_map()
181 static int thread__clone_map_groups(struct thread *thread, in thread__clone_map_groups() argument
182 struct thread *parent) in thread__clone_map_groups()
187 if (thread->pid_ == parent->pid_) in thread__clone_map_groups()
192 if (map_groups__clone(thread->mg, parent->mg, i) < 0) in thread__clone_map_groups()
198 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp) in thread__fork() argument
206 err = thread__set_comm(thread, comm, timestamp); in thread__fork()
211 thread->ppid = parent->tid; in thread__fork()
212 return thread__clone_map_groups(thread, parent); in thread__fork()
215 void thread__find_cpumode_addr_location(struct thread *thread, in thread__find_cpumode_addr_location() argument
228 thread__find_addr_location(thread, cpumodes[i], type, addr, al); in thread__find_cpumode_addr_location()