23
23
using namespace lldb ;
24
24
using namespace lldb_private ;
25
25
26
- ThreadList::ThreadList (Process * process)
26
+ ThreadList::ThreadList (Process & process)
27
27
: ThreadCollection(), m_process(process), m_stop_id(0 ),
28
28
m_selected_tid(LLDB_INVALID_THREAD_ID) {}
29
29
@@ -36,14 +36,13 @@ ThreadList::ThreadList(const ThreadList &rhs)
36
36
37
37
const ThreadList &ThreadList::operator =(const ThreadList &rhs) {
38
38
if (this != &rhs) {
39
- // Lock both mutexes to make sure neither side changes anyone on us while
40
- // the assignment occurs
41
- std::lock (GetMutex (), rhs.GetMutex ());
42
- std::lock_guard<std::recursive_mutex> guard (GetMutex (), std::adopt_lock);
43
- std::lock_guard<std::recursive_mutex> rhs_guard (rhs.GetMutex (),
44
- std::adopt_lock);
45
-
46
- m_process = rhs.m_process ;
39
+ // We only allow assignments between thread lists describing the same
40
+ // process. Same process implies same mutex, which means it's enough to lock
41
+ // just the current object.
42
+ assert (&m_process == &rhs.m_process );
43
+ assert (&GetMutex () == &rhs.GetMutex ());
44
+ std::lock_guard<std::recursive_mutex> guard (GetMutex ());
45
+
47
46
m_stop_id = rhs.m_stop_id ;
48
47
m_threads = rhs.m_threads ;
49
48
m_selected_tid = rhs.m_selected_tid ;
@@ -84,15 +83,15 @@ uint32_t ThreadList::GetSize(bool can_update) {
84
83
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
85
84
86
85
if (can_update)
87
- m_process-> UpdateThreadListIfNeeded ();
86
+ m_process. UpdateThreadListIfNeeded ();
88
87
return m_threads.size ();
89
88
}
90
89
91
90
ThreadSP ThreadList::GetThreadAtIndex (uint32_t idx, bool can_update) {
92
91
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
93
92
94
93
if (can_update)
95
- m_process-> UpdateThreadListIfNeeded ();
94
+ m_process. UpdateThreadListIfNeeded ();
96
95
97
96
ThreadSP thread_sp;
98
97
if (idx < m_threads.size ())
@@ -104,7 +103,7 @@ ThreadSP ThreadList::FindThreadByID(lldb::tid_t tid, bool can_update) {
104
103
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
105
104
106
105
if (can_update)
107
- m_process-> UpdateThreadListIfNeeded ();
106
+ m_process. UpdateThreadListIfNeeded ();
108
107
109
108
ThreadSP thread_sp;
110
109
uint32_t idx = 0 ;
@@ -122,7 +121,7 @@ ThreadSP ThreadList::FindThreadByProtocolID(lldb::tid_t tid, bool can_update) {
122
121
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
123
122
124
123
if (can_update)
125
- m_process-> UpdateThreadListIfNeeded ();
124
+ m_process. UpdateThreadListIfNeeded ();
126
125
127
126
ThreadSP thread_sp;
128
127
uint32_t idx = 0 ;
@@ -140,7 +139,7 @@ ThreadSP ThreadList::RemoveThreadByID(lldb::tid_t tid, bool can_update) {
140
139
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
141
140
142
141
if (can_update)
143
- m_process-> UpdateThreadListIfNeeded ();
142
+ m_process. UpdateThreadListIfNeeded ();
144
143
145
144
ThreadSP thread_sp;
146
145
uint32_t idx = 0 ;
@@ -160,7 +159,7 @@ ThreadSP ThreadList::RemoveThreadByProtocolID(lldb::tid_t tid,
160
159
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
161
160
162
161
if (can_update)
163
- m_process-> UpdateThreadListIfNeeded ();
162
+ m_process. UpdateThreadListIfNeeded ();
164
163
165
164
ThreadSP thread_sp;
166
165
uint32_t idx = 0 ;
@@ -210,7 +209,7 @@ ThreadSP ThreadList::FindThreadByIndexID(uint32_t index_id, bool can_update) {
210
209
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
211
210
212
211
if (can_update)
213
- m_process-> UpdateThreadListIfNeeded ();
212
+ m_process. UpdateThreadListIfNeeded ();
214
213
215
214
ThreadSP thread_sp;
216
215
const uint32_t num_threads = m_threads.size ();
@@ -241,7 +240,7 @@ bool ThreadList::ShouldStop(Event *event_ptr) {
241
240
// Scope for locker
242
241
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
243
242
244
- m_process-> UpdateThreadListIfNeeded ();
243
+ m_process. UpdateThreadListIfNeeded ();
245
244
for (lldb::ThreadSP thread_sp : m_threads) {
246
245
// This is an optimization... If we didn't let a thread run in between
247
246
// the previous stop and this one, we shouldn't have to consult it for
@@ -377,7 +376,7 @@ Vote ThreadList::ShouldReportStop(Event *event_ptr) {
377
376
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
378
377
379
378
Vote result = eVoteNoOpinion;
380
- m_process-> UpdateThreadListIfNeeded ();
379
+ m_process. UpdateThreadListIfNeeded ();
381
380
collection::iterator pos, end = m_threads.end ();
382
381
383
382
Log *log = GetLog (LLDBLog::Step);
@@ -425,7 +424,7 @@ Vote ThreadList::ShouldReportStop(Event *event_ptr) {
425
424
void ThreadList::SetShouldReportStop (Vote vote) {
426
425
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
427
426
428
- m_process-> UpdateThreadListIfNeeded ();
427
+ m_process. UpdateThreadListIfNeeded ();
429
428
collection::iterator pos, end = m_threads.end ();
430
429
for (pos = m_threads.begin (); pos != end; ++pos) {
431
430
ThreadSP thread_sp (*pos);
@@ -438,7 +437,7 @@ Vote ThreadList::ShouldReportRun(Event *event_ptr) {
438
437
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
439
438
440
439
Vote result = eVoteNoOpinion;
441
- m_process-> UpdateThreadListIfNeeded ();
440
+ m_process. UpdateThreadListIfNeeded ();
442
441
collection::iterator pos, end = m_threads.end ();
443
442
444
443
// Run through the threads and ask whether we should report this event. The
@@ -486,7 +485,7 @@ void ThreadList::Destroy() {
486
485
void ThreadList::RefreshStateAfterStop () {
487
486
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
488
487
489
- m_process-> UpdateThreadListIfNeeded ();
488
+ m_process. UpdateThreadListIfNeeded ();
490
489
491
490
Log *log = GetLog (LLDBLog::Step);
492
491
if (log && log->GetVerbose ())
@@ -515,7 +514,7 @@ bool ThreadList::WillResume() {
515
514
// they are.
516
515
517
516
std::lock_guard<std::recursive_mutex> guard (GetMutex ());
518
- m_process-> UpdateThreadListIfNeeded ();
517
+ m_process. UpdateThreadListIfNeeded ();
519
518
520
519
collection::iterator pos, end = m_threads.end ();
521
520
@@ -546,13 +545,13 @@ bool ThreadList::WillResume() {
546
545
if (log && log->GetVerbose ())
547
546
LLDB_LOGF (log, " Turning on notification of new threads while single "
548
547
" stepping a thread." );
549
- m_process-> StartNoticingNewThreads ();
548
+ m_process. StartNoticingNewThreads ();
550
549
} else {
551
550
Log *log = GetLog (LLDBLog::Step);
552
551
if (log && log->GetVerbose ())
553
552
LLDB_LOGF (log, " Turning off notification of new threads while single "
554
553
" stepping a thread." );
555
- m_process-> StopNoticingNewThreads ();
554
+ m_process. StopNoticingNewThreads ();
556
555
}
557
556
558
557
// Give all the threads that are likely to run a last chance to set up their
@@ -575,7 +574,7 @@ bool ThreadList::WillResume() {
575
574
576
575
ThreadList run_me_only_list (m_process);
577
576
578
- run_me_only_list.SetStopID (m_process-> GetStopID ());
577
+ run_me_only_list.SetStopID (m_process. GetStopID ());
579
578
580
579
// One or more threads might want to "Stop Others". We want to handle all
581
580
// those requests first. And if there is a thread that wanted to "resume
@@ -736,11 +735,13 @@ void ThreadList::NotifySelectedThreadChanged(lldb::tid_t tid) {
736
735
737
736
void ThreadList::Update (ThreadList &rhs) {
738
737
if (this != &rhs) {
739
- // Lock both mutexes to make sure neither side changes anyone on us while
740
- // the assignment occurs
741
- std::scoped_lock<std::recursive_mutex, std::recursive_mutex> guard (GetMutex (), rhs.GetMutex ());
738
+ // We only allow assignments between thread lists describing the same
739
+ // process. Same process implies same mutex, which means it's enough to lock
740
+ // just the current object.
741
+ assert (&m_process == &rhs.m_process );
742
+ assert (&GetMutex () == &rhs.GetMutex ());
743
+ std::lock_guard<std::recursive_mutex> guard (GetMutex ());
742
744
743
- m_process = rhs.m_process ;
744
745
m_stop_id = rhs.m_stop_id ;
745
746
m_threads.swap (rhs.m_threads );
746
747
m_selected_tid = rhs.m_selected_tid ;
@@ -784,7 +785,7 @@ void ThreadList::Flush() {
784
785
}
785
786
786
787
std::recursive_mutex &ThreadList::GetMutex () const {
787
- return m_process-> m_thread_mutex ;
788
+ return m_process. m_thread_mutex ;
788
789
}
789
790
790
791
ThreadList::ExpressionExecutionThreadPusher::ExpressionExecutionThreadPusher (
0 commit comments