[Lldb-commits] [lldb] r167778 - /lldb/trunk/source/Core/Listener.cpp

Greg Clayton gclayton at apple.com
Mon Nov 12 15:15:22 PST 2012


Author: gclayton
Date: Mon Nov 12 17:15:22 2012
New Revision: 167778

URL: http://llvm.org/viewvc/llvm-project?rev=167778&view=rev
Log:
Patch from Andrew Kaylor that fixes a race condition in the Listener.cpp.


Modified:
    lldb/trunk/source/Core/Listener.cpp

Modified: lldb/trunk/source/Core/Listener.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Listener.cpp?rev=167778&r1=167777&r2=167778&view=diff
==============================================================================
--- lldb/trunk/source/Core/Listener.cpp (original)
+++ lldb/trunk/source/Core/Listener.cpp Mon Nov 12 17:15:22 2012
@@ -312,11 +312,6 @@
                 m_cond_wait.SetValue (false, eBroadcastNever);
         }
         
-        // Unlock the event queue here.  We've removed this event and are about to return
-        // it so it should be okay to get the next event off the queue here - and it might
-        // be useful to do that in the "DoOnRemoval".
-        lock.Unlock();
-        
         // Don't call DoOnRemoval if you aren't removing the event...
         if (remove)
             event_sp->DoOnRemoval();
@@ -411,12 +406,20 @@
 
     while (1)
     {
-        if (GetNextEventInternal (broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, event_sp))
-            return true;
-
-        // Reset condition value to false, so we can wait for new events to be
-        // added that might meet our current filter
-        m_cond_wait.SetValue (false, eBroadcastNever);
+        // Scope for "event_locker"
+        {
+            // Don't allow new events to be added while we're checking for the
+            // one we want.  Otherwise, setting m_cond_wait to false below
+            // might cause us to miss one.
+            Mutex::Locker event_locker(m_events_mutex);
+
+            if (GetNextEventInternal (broadcaster, broadcaster_names, num_broadcaster_names, event_type_mask, event_sp))
+                return true;
+
+            // Reset condition value to false, so we can wait for new events to be
+            // added that might meet our current filter
+            m_cond_wait.SetValue (false, eBroadcastNever);
+        }
 
         if (m_cond_wait.WaitForValueEqualTo (true, timeout, &timed_out))
             continue;





More information about the lldb-commits mailing list