[Lldb-commits] [lldb] r187081 - Modify ProcessPOSIX to use the thread list mutex as needed

Daniel Malea daniel.malea at intel.com
Wed Jul 24 14:44:30 PDT 2013


Author: dmalea
Date: Wed Jul 24 16:44:30 2013
New Revision: 187081

URL: http://llvm.org/viewvc/llvm-project?rev=187081&view=rev
Log:
Modify ProcessPOSIX to use the thread list mutex as needed
- should resolve (at least some) of the spurious crashes we are seeing in multithreaded tests on Linux (and likely FreeBSD)


Modified:
    lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp

Modified: lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp?rev=187081&r1=187080&r2=187081&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp Wed Jul 24 16:44:30 2013
@@ -269,6 +269,9 @@ ProcessPOSIX::DoResume()
     SetPrivateState(eStateRunning);
 
     bool did_resume = false;
+
+    Mutex::Locker lock(m_thread_list.GetMutex());
+
     uint32_t thread_count = m_thread_list.GetSize(false);
     for (uint32_t i = 0; i < thread_count; ++i)
     {
@@ -327,6 +330,8 @@ ProcessPOSIX::DoDetach(bool keep_stopped
         return error;
     }
 
+    Mutex::Locker lock(m_thread_list.GetMutex());
+
     uint32_t thread_count = m_thread_list.GetSize(false);
     for (uint32_t i = 0; i < thread_count; ++i)
     {
@@ -380,6 +385,8 @@ ProcessPOSIX::SendMessage(const ProcessM
 {
     Mutex::Locker lock(m_message_mutex);
 
+    Mutex::Locker thread_lock(m_thread_list.GetMutex());
+
     POSIXThread *thread = static_cast<POSIXThread*>(
         m_thread_list.FindThreadByID(message.GetTID(), false).get());
 
@@ -506,6 +513,8 @@ ProcessPOSIX::RefreshStateAfterStop()
             POSIXThread *thread = static_cast<POSIXThread*>(thread_sp.get());
             thread->SetName(Host::GetThreadName(GetID(), child_tid).c_str());
 
+            Mutex::Locker lock(m_thread_list.GetMutex());
+
             m_thread_list.AddThread(thread_sp);
         }
 
@@ -519,6 +528,9 @@ ProcessPOSIX::RefreshStateAfterStop()
             // FIXME: We should tell the user about this, but the limbo message is probably better for that.
             if (log)
                 log->Printf ("ProcessPOSIX::%s() removing thread, tid = %" PRIi64, __FUNCTION__, tid);
+
+            Mutex::Locker lock(m_thread_list.GetMutex());
+
             ThreadSP thread_sp = m_thread_list.RemoveThreadByID(tid, false);
             thread_sp.reset();
             m_seen_initial_stop.erase(tid);
@@ -669,6 +681,7 @@ ProcessPOSIX::EnableWatchpoint(Watchpoin
 
         // Try to find a vacant watchpoint slot in the inferiors' main thread
         uint32_t wp_hw_index = LLDB_INVALID_INDEX32;
+        Mutex::Locker lock(m_thread_list.GetMutex());
         POSIXThread *thread = static_cast<POSIXThread*>(
                                m_thread_list.GetThreadAtIndex(0, false).get());
 
@@ -738,6 +751,7 @@ ProcessPOSIX::DisableWatchpoint(Watchpoi
         if (wp->IsHardware())
         {
             bool wp_disabled = true;
+            Mutex::Locker lock(m_thread_list.GetMutex());
             uint32_t thread_count = m_thread_list.GetSize(false);
             for (uint32_t i = 0; i < thread_count; ++i)
             {
@@ -767,6 +781,7 @@ Error
 ProcessPOSIX::GetWatchpointSupportInfo(uint32_t &num)
 {
     Error error;
+    Mutex::Locker lock(m_thread_list.GetMutex());
     POSIXThread *thread = static_cast<POSIXThread*>(
                           m_thread_list.GetThreadAtIndex(0, false).get());
     if (thread)
@@ -789,6 +804,7 @@ ProcessPOSIX::GetWatchpointSupportInfo(u
 uint32_t
 ProcessPOSIX::UpdateThreadListIfNeeded()
 {
+    Mutex::Locker lock(m_thread_list.GetMutex());
     // Do not allow recursive updates.
     return m_thread_list.GetSize(false);
 }
@@ -881,6 +897,7 @@ bool
 ProcessPOSIX::IsAThreadRunning()
 {
     bool is_running = false;
+    Mutex::Locker lock(m_thread_list.GetMutex());
     uint32_t thread_count = m_thread_list.GetSize(false);
     for (uint32_t i = 0; i < thread_count; ++i)
     {





More information about the lldb-commits mailing list