diff options
Diffstat (limited to 'source/Target/ThreadList.cpp')
-rw-r--r-- | source/Target/ThreadList.cpp | 102 |
1 files changed, 72 insertions, 30 deletions
diff --git a/source/Target/ThreadList.cpp b/source/Target/ThreadList.cpp index a34cb0fa143a..23e9f7807321 100644 --- a/source/Target/ThreadList.cpp +++ b/source/Target/ThreadList.cpp @@ -53,7 +53,8 @@ ThreadList::operator = (const ThreadList& rhs) { // Lock both mutexes to make sure neither side changes anyone on us // while the assignment occurs - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + m_process = rhs.m_process; m_stop_id = rhs.m_stop_id; m_threads = rhs.m_threads; @@ -71,6 +72,30 @@ ThreadList::~ThreadList() Clear(); } +lldb::ThreadSP +ThreadList::GetExpressionExecutionThread() +{ + if (m_expression_tid_stack.empty()) + return GetSelectedThread(); + ThreadSP expr_thread_sp = FindThreadByID(m_expression_tid_stack.back()); + if (expr_thread_sp) + return expr_thread_sp; + else + return GetSelectedThread(); +} + +void +ThreadList::PushExpressionExecutionThread(lldb::tid_t tid) +{ + m_expression_tid_stack.push_back(tid); +} + +void +ThreadList::PopExpressionExecutionThread(lldb::tid_t tid) +{ + assert(m_expression_tid_stack.back() == tid); + m_expression_tid_stack.pop_back(); +} uint32_t ThreadList::GetStopID () const @@ -87,7 +112,8 @@ ThreadList::SetStopID (uint32_t stop_id) uint32_t ThreadList::GetSize (bool can_update) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + if (can_update) m_process->UpdateThreadListIfNeeded(); return m_threads.size(); @@ -96,7 +122,8 @@ ThreadList::GetSize (bool can_update) ThreadSP ThreadList::GetThreadAtIndex (uint32_t idx, bool can_update) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + if (can_update) m_process->UpdateThreadListIfNeeded(); @@ -109,7 +136,7 @@ ThreadList::GetThreadAtIndex (uint32_t idx, bool can_update) ThreadSP ThreadList::FindThreadByID (lldb::tid_t tid, bool can_update) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); if (can_update) m_process->UpdateThreadListIfNeeded(); @@ -131,8 +158,8 @@ ThreadList::FindThreadByID (lldb::tid_t tid, bool can_update) ThreadSP ThreadList::FindThreadByProtocolID (lldb::tid_t tid, bool can_update) { - Mutex::Locker locker(GetMutex()); - + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + if (can_update) m_process->UpdateThreadListIfNeeded(); @@ -154,8 +181,8 @@ ThreadList::FindThreadByProtocolID (lldb::tid_t tid, bool can_update) ThreadSP ThreadList::RemoveThreadByID (lldb::tid_t tid, bool can_update) { - Mutex::Locker locker(GetMutex()); - + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + if (can_update) m_process->UpdateThreadListIfNeeded(); @@ -177,8 +204,8 @@ ThreadList::RemoveThreadByID (lldb::tid_t tid, bool can_update) ThreadSP ThreadList::RemoveThreadByProtocolID (lldb::tid_t tid, bool can_update) { - Mutex::Locker locker(GetMutex()); - + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + if (can_update) m_process->UpdateThreadListIfNeeded(); @@ -203,7 +230,7 @@ ThreadList::GetThreadSPForThreadPtr (Thread *thread_ptr) ThreadSP thread_sp; if (thread_ptr) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); uint32_t idx = 0; const uint32_t num_threads = m_threads.size(); @@ -224,7 +251,7 @@ ThreadList::GetThreadSPForThreadPtr (Thread *thread_ptr) ThreadSP ThreadList::FindThreadByIndexID (uint32_t index_id, bool can_update) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); if (can_update) m_process->UpdateThreadListIfNeeded(); @@ -260,7 +287,7 @@ ThreadList::ShouldStop (Event *event_ptr) collection threads_copy; { // Scope for locker - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); m_process->UpdateThreadListIfNeeded(); for (lldb::ThreadSP thread_sp : m_threads) @@ -371,7 +398,7 @@ ThreadList::ShouldStop (Event *event_ptr) Vote ThreadList::ShouldReportStop (Event *event_ptr) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); Vote result = eVoteNoOpinion; m_process->UpdateThreadListIfNeeded(); @@ -422,7 +449,8 @@ ThreadList::ShouldReportStop (Event *event_ptr) void ThreadList::SetShouldReportStop (Vote vote) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + m_process->UpdateThreadListIfNeeded(); collection::iterator pos, end = m_threads.end(); for (pos = m_threads.begin(); pos != end; ++pos) @@ -436,7 +464,7 @@ Vote ThreadList::ShouldReportRun (Event *event_ptr) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); Vote result = eVoteNoOpinion; m_process->UpdateThreadListIfNeeded(); @@ -475,7 +503,7 @@ ThreadList::ShouldReportRun (Event *event_ptr) void ThreadList::Clear() { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); m_stop_id = 0; m_threads.clear(); m_selected_tid = LLDB_INVALID_THREAD_ID; @@ -484,7 +512,7 @@ ThreadList::Clear() void ThreadList::Destroy() { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); const uint32_t num_threads = m_threads.size(); for (uint32_t idx = 0; idx < num_threads; ++idx) { @@ -495,7 +523,7 @@ ThreadList::Destroy() void ThreadList::RefreshStateAfterStop () { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); m_process->UpdateThreadListIfNeeded(); @@ -513,7 +541,7 @@ ThreadList::DiscardThreadPlans () { // You don't need to update the thread list here, because only threads // that you currently know about have any thread plans. - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); collection::iterator pos, end = m_threads.end(); for (pos = m_threads.begin(); pos != end; ++pos) @@ -528,7 +556,7 @@ ThreadList::WillResume () // But we only do this for threads that are running, user suspended // threads stay where they are. - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); m_process->UpdateThreadListIfNeeded(); collection::iterator pos, end = m_threads.end(); @@ -676,7 +704,7 @@ ThreadList::WillResume () void ThreadList::DidResume () { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); collection::iterator pos, end = m_threads.end(); for (pos = m_threads.begin(); pos != end; ++pos) { @@ -691,7 +719,7 @@ ThreadList::DidResume () void ThreadList::DidStop () { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); collection::iterator pos, end = m_threads.end(); for (pos = m_threads.begin(); pos != end; ++pos) { @@ -712,7 +740,7 @@ ThreadList::DidStop () ThreadSP ThreadList::GetSelectedThread () { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); ThreadSP thread_sp = FindThreadByID(m_selected_tid); if (!thread_sp.get()) { @@ -727,7 +755,7 @@ ThreadList::GetSelectedThread () bool ThreadList::SetSelectedThreadByID (lldb::tid_t tid, bool notify) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); ThreadSP selected_thread_sp(FindThreadByID(tid)); if (selected_thread_sp) { @@ -746,7 +774,7 @@ ThreadList::SetSelectedThreadByID (lldb::tid_t tid, bool notify) bool ThreadList::SetSelectedThreadByIndexID (uint32_t index_id, bool notify) { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); ThreadSP selected_thread_sp (FindThreadByIndexID(index_id)); if (selected_thread_sp.get()) { @@ -778,7 +806,8 @@ ThreadList::Update (ThreadList &rhs) { // Lock both mutexes to make sure neither side changes anyone on us // while the assignment occurs - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); + m_process = rhs.m_process; m_stop_id = rhs.m_stop_id; m_threads.swap(rhs.m_threads); @@ -816,15 +845,28 @@ ThreadList::Update (ThreadList &rhs) void ThreadList::Flush () { - Mutex::Locker locker(GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex()); collection::iterator pos, end = m_threads.end(); for (pos = m_threads.begin(); pos != end; ++pos) (*pos)->Flush (); } -Mutex & -ThreadList::GetMutex () +std::recursive_mutex & +ThreadList::GetMutex() { return m_process->m_thread_mutex; } +ThreadList::ExpressionExecutionThreadPusher::ExpressionExecutionThreadPusher (lldb::ThreadSP thread_sp) : + m_thread_list(nullptr), + m_tid(LLDB_INVALID_THREAD_ID) +{ + if (thread_sp) + { + m_tid = thread_sp->GetID(); + m_thread_list = &thread_sp->GetProcess()->GetThreadList(); + m_thread_list->PushExpressionExecutionThread(m_tid); + } +} + + |