[Lldb-commits] [lldb] r180050 - Fix lock hierarchy violation in Listener/Broadcaster

Daniel Malea daniel.malea at intel.com
Mon Apr 22 14:22:42 PDT 2013


Author: dmalea
Date: Mon Apr 22 16:22:41 2013
New Revision: 180050

URL: http://llvm.org/viewvc/llvm-project?rev=180050&view=rev
Log:
Fix lock hierarchy violation in Listener/Broadcaster
- avoid deadlocks if Broadcaster::SignUpListenersForBroadcaster and
  Listener::StartListeningForEventSpec are both called concurrently


Modified:
    lldb/trunk/include/lldb/Core/Broadcaster.h
    lldb/trunk/source/Core/Listener.cpp

Modified: lldb/trunk/include/lldb/Core/Broadcaster.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Broadcaster.h?rev=180050&r1=180049&r2=180050&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Broadcaster.h (original)
+++ lldb/trunk/include/lldb/Core/Broadcaster.h Mon Apr 22 16:22:41 2013
@@ -85,6 +85,8 @@ private:
 class BroadcasterManager
 {
 public:
+    friend class Listener;
+
     BroadcasterManager ();
 
     ~BroadcasterManager () {}

Modified: lldb/trunk/source/Core/Listener.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Listener.cpp?rev=180050&r1=180049&r2=180050&view=diff
==============================================================================
--- lldb/trunk/source/Core/Listener.cpp (original)
+++ lldb/trunk/source/Core/Listener.cpp Mon Apr 22 16:22:41 2013
@@ -533,6 +533,9 @@ uint32_t
 Listener::StartListeningForEventSpec (BroadcasterManager &manager, 
                              const BroadcastEventSpec &event_spec)
 {
+    // The BroadcasterManager mutex must be locked before m_broadcasters_mutex 
+    // to avoid violating the lock hierarchy (manager before broadcasters).
+    Mutex::Locker manager_locker(manager.m_manager_mutex);
     Mutex::Locker locker(m_broadcasters_mutex);
 
     uint32_t bits_acquired = manager.RegisterListenerForEvents(*this, event_spec);





More information about the lldb-commits mailing list