blob: 79df0f2184e038290b08691cfbc51eb0b5a1dcad [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ThreadList.cpp ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#include <stdlib.h>
10
11#include <algorithm>
12
Greg Clayton2cad65a2010-09-03 17:10:42 +000013#include "lldb/Core/Log.h"
14#include "lldb/Target/RegisterContext.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Target/ThreadList.h"
16#include "lldb/Target/Thread.h"
17#include "lldb/Target/ThreadPlan.h"
18#include "lldb/Target/Process.h"
19
20using namespace lldb;
21using namespace lldb_private;
22
23ThreadList::ThreadList (Process *process) :
24 m_process (process),
25 m_stop_id (0),
26 m_threads(),
27 m_threads_mutex (Mutex::eMutexTypeRecursive),
Jim Ingham2976d002010-08-26 21:32:51 +000028 m_selected_tid (LLDB_INVALID_THREAD_ID)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029{
30}
31
32ThreadList::ThreadList (const ThreadList &rhs) :
33 m_process (),
34 m_stop_id (),
35 m_threads (),
36 m_threads_mutex (Mutex::eMutexTypeRecursive),
Jim Ingham2976d002010-08-26 21:32:51 +000037 m_selected_tid ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038{
39 // Use the assignment operator since it uses the mutex
40 *this = rhs;
41}
42
43const ThreadList&
44ThreadList::operator = (const ThreadList& rhs)
45{
46 if (this != &rhs)
47 {
48 // Lock both mutexes to make sure neither side changes anyone on us
49 // while the assignement occurs
Greg Claytonb1320972010-07-14 00:18:15 +000050 Mutex::Locker locker_lhs(m_threads_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051 Mutex::Locker locker_rhs(rhs.m_threads_mutex);
52 m_process = rhs.m_process;
53 m_stop_id = rhs.m_stop_id;
54 m_threads = rhs.m_threads;
Jim Ingham2976d002010-08-26 21:32:51 +000055 m_selected_tid = rhs.m_selected_tid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056 }
57 return *this;
58}
59
60
61ThreadList::~ThreadList()
62{
63}
64
65
66uint32_t
67ThreadList::GetStopID () const
68{
69 return m_stop_id;
70}
71
72void
73ThreadList::SetStopID (uint32_t stop_id)
74{
75 m_stop_id = stop_id;
76}
77
78
79void
80ThreadList::AddThread (ThreadSP &thread_sp)
81{
82 Mutex::Locker locker(m_threads_mutex);
83 m_threads.push_back(thread_sp);
84}
85
86uint32_t
87ThreadList::GetSize (bool can_update)
88{
89 Mutex::Locker locker(m_threads_mutex);
90 if (can_update)
91 m_process->UpdateThreadListIfNeeded();
92 return m_threads.size();
93}
94
95ThreadSP
96ThreadList::GetThreadAtIndex (uint32_t idx, bool can_update)
97{
98 Mutex::Locker locker(m_threads_mutex);
99 if (can_update)
100 m_process->UpdateThreadListIfNeeded();
101
102 ThreadSP thread_sp;
103 if (idx < m_threads.size())
104 thread_sp = m_threads[idx];
105 return thread_sp;
106}
107
108ThreadSP
109ThreadList::FindThreadByID (lldb::tid_t tid, bool can_update)
110{
111 Mutex::Locker locker(m_threads_mutex);
112
113 if (can_update)
114 m_process->UpdateThreadListIfNeeded();
115
116 ThreadSP thread_sp;
117 uint32_t idx = 0;
118 const uint32_t num_threads = m_threads.size();
119 for (idx = 0; idx < num_threads; ++idx)
120 {
121 if (m_threads[idx]->GetID() == tid)
122 {
123 thread_sp = m_threads[idx];
124 break;
125 }
126 }
127 return thread_sp;
128}
129
130ThreadSP
131ThreadList::GetThreadSPForThreadPtr (Thread *thread_ptr)
132{
133 ThreadSP thread_sp;
134 if (thread_ptr)
135 {
136 Mutex::Locker locker(m_threads_mutex);
137
138 uint32_t idx = 0;
139 const uint32_t num_threads = m_threads.size();
140 for (idx = 0; idx < num_threads; ++idx)
141 {
142 if (m_threads[idx].get() == thread_ptr)
143 {
144 thread_sp = m_threads[idx];
145 break;
146 }
147 }
148 }
149 return thread_sp;
150}
151
152
153
154ThreadSP
155ThreadList::FindThreadByIndexID (uint32_t index_id, bool can_update)
156{
157 Mutex::Locker locker(m_threads_mutex);
158
159 if (can_update)
160 m_process->UpdateThreadListIfNeeded();
161
162 ThreadSP thread_sp;
163 const uint32_t num_threads = m_threads.size();
164 for (uint32_t idx = 0; idx < num_threads; ++idx)
165 {
166 if (m_threads[idx]->GetIndexID() == index_id)
167 {
168 thread_sp = m_threads[idx];
169 break;
170 }
171 }
172 return thread_sp;
173}
174
175bool
176ThreadList::ShouldStop (Event *event_ptr)
177{
178 Mutex::Locker locker(m_threads_mutex);
179
180 // Running events should never stop, obviously...
181
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000182 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000183
Jim Inghamb01e7422010-06-19 04:45:32 +0000184 bool should_stop = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000185 m_process->UpdateThreadListIfNeeded();
186
187 collection::iterator pos, end = m_threads.end();
188
Greg Clayton2cad65a2010-09-03 17:10:42 +0000189 if (log)
Greg Clayton1346f7e2010-09-03 22:45:01 +0000190 log->Printf ("%s %zu threads", __FUNCTION__, m_threads.size());
Greg Clayton2cad65a2010-09-03 17:10:42 +0000191
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 // Run through the threads and ask whether we should stop. Don't ask
193 // suspended threads, however, it makes more sense for them to preserve their
194 // state across the times the process runs but they don't get a chance to.
195 for (pos = m_threads.begin(); pos != end; ++pos)
196 {
197 ThreadSP thread_sp(*pos);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000198
Greg Clayton2cad65a2010-09-03 17:10:42 +0000199 if (thread_sp->GetResumeState () == eStateSuspended)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200 {
Greg Clayton2cad65a2010-09-03 17:10:42 +0000201 if (log)
Greg Clayton1346f7e2010-09-03 22:45:01 +0000202 log->Printf ("%s tid = 0x%4.4x, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)",
203 __FUNCTION__,
204 thread_sp->GetID (),
205 thread_sp->GetRegisterContext()->GetPC());
Greg Clayton2cad65a2010-09-03 17:10:42 +0000206 continue;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207 }
Greg Clayton2cad65a2010-09-03 17:10:42 +0000208
209 if (thread_sp->ThreadStoppedForAReason() == false)
210 {
211 if (log)
Greg Clayton1346f7e2010-09-03 22:45:01 +0000212 log->Printf ("%s tid = 0x%4.4x, pc = 0x%16.16llx, should_stop = 0 (ignore since no stop reason)",
213 __FUNCTION__,
214 thread_sp->GetID (),
215 thread_sp->GetRegisterContext()->GetPC());
Greg Clayton2cad65a2010-09-03 17:10:42 +0000216 continue;
Greg Clayton2cad65a2010-09-03 17:10:42 +0000217 }
218
219 const bool thread_should_stop = thread_sp->ShouldStop(event_ptr);
220 if (log)
Greg Clayton1346f7e2010-09-03 22:45:01 +0000221 log->Printf ("%s tid = 0x%4.4x, pc = 0x%16.16llx, should_stop = %i",
222 __FUNCTION__,
223 thread_sp->GetID (),
224 thread_sp->GetRegisterContext()->GetPC(),
225 thread_should_stop);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000226 if (thread_should_stop)
227 should_stop |= true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228 }
Jim Inghamb01e7422010-06-19 04:45:32 +0000229
Greg Clayton2cad65a2010-09-03 17:10:42 +0000230 if (log)
Greg Clayton1346f7e2010-09-03 22:45:01 +0000231 log->Printf ("%s overall should_stop = %i", __FUNCTION__, should_stop);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000232
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000233 if (should_stop)
234 {
235 for (pos = m_threads.begin(); pos != end; ++pos)
236 {
237 ThreadSP thread_sp(*pos);
238 thread_sp->WillStop ();
239 }
240 }
241
242 return should_stop;
243}
244
245Vote
246ThreadList::ShouldReportStop (Event *event_ptr)
247{
Greg Clayton2cad65a2010-09-03 17:10:42 +0000248 Mutex::Locker locker(m_threads_mutex);
249
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250 Vote result = eVoteNoOpinion;
251 m_process->UpdateThreadListIfNeeded();
252 collection::iterator pos, end = m_threads.end();
253
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000254 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton2cad65a2010-09-03 17:10:42 +0000255
256 if (log)
Greg Clayton1346f7e2010-09-03 22:45:01 +0000257 log->Printf ("%s %zu threads", __FUNCTION__, m_threads.size());
Greg Clayton2cad65a2010-09-03 17:10:42 +0000258
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000259 // Run through the threads and ask whether we should report this event.
260 // For stopping, a YES vote wins over everything. A NO vote wins over NO opinion.
261 for (pos = m_threads.begin(); pos != end; ++pos)
262 {
263 ThreadSP thread_sp(*pos);
264 if (thread_sp->ThreadStoppedForAReason() && (thread_sp->GetResumeState () != eStateSuspended))
265 {
Greg Claytone0d378b2011-03-24 21:19:54 +0000266 const Vote vote = thread_sp->ShouldReportStop (event_ptr);
Greg Clayton2cad65a2010-09-03 17:10:42 +0000267 if (log)
Greg Clayton1346f7e2010-09-03 22:45:01 +0000268 log->Printf ("%s thread 0x%4.4x: pc = 0x%16.16llx, vote = %s",
Greg Clayton2cad65a2010-09-03 17:10:42 +0000269 __FUNCTION__,
270 thread_sp->GetID (),
271 thread_sp->GetRegisterContext()->GetPC(),
272 GetVoteAsCString (vote));
273 switch (vote)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 {
Greg Clayton2cad65a2010-09-03 17:10:42 +0000275 case eVoteNoOpinion:
276 continue;
277
278 case eVoteYes:
279 result = eVoteYes;
280 break;
281
282 case eVoteNo:
283 if (result == eVoteNoOpinion)
284 {
285 result = eVoteNo;
286 }
287 else
288 {
289 if (log)
Greg Clayton1346f7e2010-09-03 22:45:01 +0000290 log->Printf ("%s thread 0x%4.4x: pc = 0x%16.16llx voted %s, but lost out because result was %s",
Greg Clayton2cad65a2010-09-03 17:10:42 +0000291 __FUNCTION__,
292 thread_sp->GetID (),
293 thread_sp->GetRegisterContext()->GetPC(),
294 GetVoteAsCString (vote),
295 GetVoteAsCString (result));
296 }
297 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298 }
299 }
300 }
Greg Clayton2cad65a2010-09-03 17:10:42 +0000301 if (log)
Greg Clayton1346f7e2010-09-03 22:45:01 +0000302 log->Printf ("%s returning %s", __FUNCTION__, GetVoteAsCString (result));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000303 return result;
304}
305
306Vote
307ThreadList::ShouldReportRun (Event *event_ptr)
308{
Greg Clayton2cad65a2010-09-03 17:10:42 +0000309
310 Mutex::Locker locker(m_threads_mutex);
311
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312 Vote result = eVoteNoOpinion;
313 m_process->UpdateThreadListIfNeeded();
314 collection::iterator pos, end = m_threads.end();
315
316 // Run through the threads and ask whether we should report this event.
317 // The rule is NO vote wins over everything, a YES vote wins over no opinion.
318
Jim Inghamce579832011-01-24 04:11:25 +0000319 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
320
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321 for (pos = m_threads.begin(); pos != end; ++pos)
322 {
Jim Inghamce579832011-01-24 04:11:25 +0000323 if ((*pos)->GetResumeState () != eStateSuspended)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000324 {
Jim Inghamce579832011-01-24 04:11:25 +0000325 switch ((*pos)->ShouldReportRun (event_ptr))
326 {
327 case eVoteNoOpinion:
328 continue;
329 case eVoteYes:
330 if (result == eVoteNoOpinion)
331 result = eVoteYes;
332 break;
333 case eVoteNo:
Greg Claytonabcbc8a2011-01-24 05:36:47 +0000334 if (log)
335 log->Printf ("ThreadList::ShouldReportRun() thread %d (0x%4.4x) says don't report.",
336 (*pos)->GetIndexID(),
337 (*pos)->GetID());
Jim Inghamce579832011-01-24 04:11:25 +0000338 result = eVoteNo;
339 break;
340 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000341 }
342 }
343 return result;
344}
345
346void
347ThreadList::Clear()
348{
Greg Claytonc4e411f2011-01-18 19:36:39 +0000349 Mutex::Locker locker(m_threads_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000350 m_stop_id = 0;
351 m_threads.clear();
Jim Ingham2976d002010-08-26 21:32:51 +0000352 m_selected_tid = LLDB_INVALID_THREAD_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000353}
354
355void
356ThreadList::RefreshStateAfterStop ()
357{
358 Mutex::Locker locker(m_threads_mutex);
359
360 m_process->UpdateThreadListIfNeeded();
Jim Ingham1c823b42011-01-22 01:33:44 +0000361
362 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
363 if (log)
364 log->Printf ("Turning off notification of new threads while single stepping a thread.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365
366 collection::iterator pos, end = m_threads.end();
367 for (pos = m_threads.begin(); pos != end; ++pos)
368 (*pos)->RefreshStateAfterStop ();
369}
370
371void
372ThreadList::DiscardThreadPlans ()
373{
374 // You don't need to update the thread list here, because only threads
375 // that you currently know about have any thread plans.
376 Mutex::Locker locker(m_threads_mutex);
377
378 collection::iterator pos, end = m_threads.end();
379 for (pos = m_threads.begin(); pos != end; ++pos)
380 (*pos)->DiscardThreadPlans (true);
381
382}
383
384bool
385ThreadList::WillResume ()
386{
387 // Run through the threads and perform their momentary actions.
388 // But we only do this for threads that are running, user suspended
389 // threads stay where they are.
390 bool success = true;
391
392 Mutex::Locker locker(m_threads_mutex);
393 m_process->UpdateThreadListIfNeeded();
394
395 collection::iterator pos, end = m_threads.end();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396
Jim Inghama3241c12010-07-14 02:27:20 +0000397 // See if any thread wants to run stopping others. If it does, then we won't
398 // setup the other threads for resume, since they aren't going to get a chance
399 // to run. This is necessary because the SetupForResume might add "StopOthers"
400 // plans which would then get to be part of the who-gets-to-run negotiation, but
401 // they're coming in after the fact, and the threads that are already set up should
402 // take priority.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403
Jim Inghama3241c12010-07-14 02:27:20 +0000404 bool wants_solo_run = false;
405
406 for (pos = m_threads.begin(); pos != end; ++pos)
407 {
408 if ((*pos)->GetResumeState() != eStateSuspended &&
409 (*pos)->GetCurrentPlan()->StopOthers())
410 {
411 wants_solo_run = true;
412 break;
413 }
414 }
415
Jim Ingham1c823b42011-01-22 01:33:44 +0000416 if (wants_solo_run)
417 {
418 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
419 if (log)
420 log->Printf ("Turning on notification of new threads while single stepping a thread.");
421 m_process->StartNoticingNewThreads();
422 }
423 else
424 {
425 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
426 if (log)
427 log->Printf ("Turning off notification of new threads while single stepping a thread.");
428 m_process->StopNoticingNewThreads();
429 }
Jim Inghama3241c12010-07-14 02:27:20 +0000430
431 // Give all the threads that are likely to run a last chance to set up their state before we
432 // negotiate who is actually going to get a chance to run...
433 // Don't set to resume suspended threads, and if any thread wanted to stop others, only
434 // call setup on the threads that request StopOthers...
435
436 for (pos = m_threads.begin(); pos != end; ++pos)
437 {
438 if ((*pos)->GetResumeState() != eStateSuspended
439 && (!wants_solo_run || (*pos)->GetCurrentPlan()->StopOthers()))
440 {
441 (*pos)->SetupForResume ();
442 }
443 }
444
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 // Now go through the threads and see if any thread wants to run just itself.
446 // if so then pick one and run it.
Jim Inghama3241c12010-07-14 02:27:20 +0000447
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000448 ThreadList run_me_only_list (m_process);
449
450 run_me_only_list.SetStopID(m_process->GetStopID());
451
452 ThreadSP immediate_thread_sp;
453 bool run_only_current_thread = false;
454
455 for (pos = m_threads.begin(); pos != end; ++pos)
456 {
457 ThreadSP thread_sp(*pos);
Jim Inghamb15bfc72010-10-20 00:39:53 +0000458 if (thread_sp->GetResumeState() != eStateSuspended &&
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 thread_sp->GetCurrentPlan()->StopOthers())
460 {
461 // You can't say "stop others" and also want yourself to be suspended.
462 assert (thread_sp->GetCurrentPlan()->RunState() != eStateSuspended);
463
Jim Ingham2976d002010-08-26 21:32:51 +0000464 if (thread_sp == GetSelectedThread())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000465 {
466 run_only_current_thread = true;
467 run_me_only_list.Clear();
468 run_me_only_list.AddThread (thread_sp);
469 break;
470 }
471
472 run_me_only_list.AddThread (thread_sp);
473 }
474
475 }
476
477 if (immediate_thread_sp)
478 {
479 for (pos = m_threads.begin(); pos != end; ++pos)
480 {
481 ThreadSP thread_sp(*pos);
482 if (thread_sp.get() == immediate_thread_sp.get())
483 thread_sp->WillResume(thread_sp->GetCurrentPlan()->RunState());
484 else
485 thread_sp->WillResume (eStateSuspended);
486 }
487 }
488 else if (run_me_only_list.GetSize (false) == 0)
489 {
490 // Everybody runs as they wish:
491 for (pos = m_threads.begin(); pos != end; ++pos)
492 {
493 ThreadSP thread_sp(*pos);
494 thread_sp->WillResume(thread_sp->GetCurrentPlan()->RunState());
495 }
496 }
497 else
498 {
499 ThreadSP thread_to_run;
500
501 if (run_only_current_thread)
502 {
Jim Ingham2976d002010-08-26 21:32:51 +0000503 thread_to_run = GetSelectedThread();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504 }
505 else if (run_me_only_list.GetSize (false) == 1)
506 {
507 thread_to_run = run_me_only_list.GetThreadAtIndex (0);
508 }
509 else
510 {
511 int random_thread = (int)
512 ((run_me_only_list.GetSize (false) * (double) rand ()) / (RAND_MAX + 1.0));
513 thread_to_run = run_me_only_list.GetThreadAtIndex (random_thread);
514 }
515
516 for (pos = m_threads.begin(); pos != end; ++pos)
517 {
518 ThreadSP thread_sp(*pos);
519 if (thread_sp == thread_to_run)
520 thread_sp->WillResume(thread_sp->GetCurrentPlan()->RunState());
521 else
522 thread_sp->WillResume (eStateSuspended);
523 }
524 }
525
526 return success;
527}
528
529void
530ThreadList::DidResume ()
531{
Greg Claytonc4e411f2011-01-18 19:36:39 +0000532 Mutex::Locker locker(m_threads_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 collection::iterator pos, end = m_threads.end();
534 for (pos = m_threads.begin(); pos != end; ++pos)
535 {
536 // Don't clear out threads that aren't going to get a chance to run, rather
537 // leave their state for the next time around.
538 ThreadSP thread_sp(*pos);
539 if (thread_sp->GetResumeState() != eStateSuspended)
540 thread_sp->DidResume ();
541 }
542}
543
544ThreadSP
Jim Ingham2976d002010-08-26 21:32:51 +0000545ThreadList::GetSelectedThread ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546{
547 Mutex::Locker locker(m_threads_mutex);
Johnny Chen943ddb72011-08-25 21:59:59 +0000548 ThreadSP thread_sp = FindThreadByID(m_selected_tid);
549 if (!thread_sp.get())
550 {
551 m_selected_tid = m_threads[0]->GetID();
552 thread_sp = m_threads[0];
553 }
554 return thread_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555}
556
557bool
Jim Ingham2976d002010-08-26 21:32:51 +0000558ThreadList::SetSelectedThreadByID (lldb::tid_t tid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559{
560 Mutex::Locker locker(m_threads_mutex);
561 if (FindThreadByID(tid).get())
Jim Ingham2976d002010-08-26 21:32:51 +0000562 m_selected_tid = tid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563 else
Jim Ingham2976d002010-08-26 21:32:51 +0000564 m_selected_tid = LLDB_INVALID_THREAD_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565
Jim Ingham2976d002010-08-26 21:32:51 +0000566 return m_selected_tid != LLDB_INVALID_THREAD_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567}
568
569bool
Jim Ingham2976d002010-08-26 21:32:51 +0000570ThreadList::SetSelectedThreadByIndexID (uint32_t index_id)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571{
572 Mutex::Locker locker(m_threads_mutex);
573 ThreadSP thread_sp (FindThreadByIndexID(index_id));
574 if (thread_sp.get())
Jim Ingham2976d002010-08-26 21:32:51 +0000575 m_selected_tid = thread_sp->GetID();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576 else
Jim Ingham2976d002010-08-26 21:32:51 +0000577 m_selected_tid = LLDB_INVALID_THREAD_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578
Jim Ingham2976d002010-08-26 21:32:51 +0000579 return m_selected_tid != LLDB_INVALID_THREAD_ID;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580}
581
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000582void
583ThreadList::Update (ThreadList &rhs)
584{
585 if (this != &rhs)
586 {
587 // Lock both mutexes to make sure neither side changes anyone on us
588 // while the assignement occurs
589 Mutex::Locker locker_lhs(m_threads_mutex);
590 Mutex::Locker locker_rhs(rhs.m_threads_mutex);
591 m_process = rhs.m_process;
592 m_stop_id = rhs.m_stop_id;
593 m_threads.swap(rhs.m_threads);
594 m_selected_tid = rhs.m_selected_tid;
595 }
596}
597
598