@@ -41,6 +41,7 @@ int thread__init_maps(struct thread *thread, struct machine *machine)
4141}
4242
4343struct thread * thread__new (pid_t pid , pid_t tid )
44+ NO_THREAD_SAFETY_ANALYSIS /* Allocation/creation is inherently single threaded. */
4445{
4546 RC_STRUCT (thread ) * _thread = zalloc (sizeof (* _thread ));
4647 struct thread * thread ;
@@ -200,24 +201,39 @@ int thread__set_namespaces(struct thread *thread, u64 timestamp,
200201 return ret ;
201202}
202203
203- struct comm * thread__comm (struct thread * thread )
204+ static struct comm * __thread__comm (struct thread * thread )
205+ SHARED_LOCKS_REQUIRED (thread__comm_lock (thread ))
204206{
205207 if (list_empty (thread__comm_list (thread )))
206208 return NULL ;
207209
208210 return list_first_entry (thread__comm_list (thread ), struct comm , list );
209211}
210212
213+ struct comm * thread__comm (struct thread * thread )
214+ {
215+ struct comm * res = NULL ;
216+
217+ down_read (thread__comm_lock (thread ));
218+ res = __thread__comm (thread );
219+ up_read (thread__comm_lock (thread ));
220+ return res ;
221+ }
222+
211223struct comm * thread__exec_comm (struct thread * thread )
212224{
213225 struct comm * comm , * last = NULL , * second_last = NULL ;
214226
227+ down_read (thread__comm_lock (thread ));
215228 list_for_each_entry (comm , thread__comm_list (thread ), list ) {
216- if (comm -> exec )
229+ if (comm -> exec ) {
230+ up_read (thread__comm_lock (thread ));
217231 return comm ;
232+ }
218233 second_last = last ;
219234 last = comm ;
220235 }
236+ up_read (thread__comm_lock (thread ));
221237
222238 /*
223239 * 'last' with no start time might be the parent's comm of a synthesized
@@ -233,8 +249,9 @@ struct comm *thread__exec_comm(struct thread *thread)
233249
234250static int ____thread__set_comm (struct thread * thread , const char * str ,
235251 u64 timestamp , bool exec )
252+ EXCLUSIVE_LOCKS_REQUIRED (thread__comm_lock (thread ))
236253{
237- struct comm * new , * curr = thread__comm (thread );
254+ struct comm * new , * curr = __thread__comm (thread );
238255
239256 /* Override the default :tid entry */
240257 if (!thread__comm_set (thread )) {
@@ -285,8 +302,9 @@ int thread__set_comm_from_proc(struct thread *thread)
285302}
286303
287304static const char * __thread__comm_str (struct thread * thread )
305+ SHARED_LOCKS_REQUIRED (thread__comm_lock (thread ))
288306{
289- const struct comm * comm = thread__comm (thread );
307+ const struct comm * comm = __thread__comm (thread );
290308
291309 if (!comm )
292310 return NULL ;
0 commit comments