[llvm-branch-commits] [lldb] r199435 - Make SBCommandInterpreter::IsActive() not have to take a lock.

Greg Clayton gclayton at apple.com
Thu Jan 16 15:04:17 PST 2014


Author: gclayton
Date: Thu Jan 16 17:04:16 2014
New Revision: 199435

URL: http://llvm.org/viewvc/llvm-project?rev=199435&view=rev
Log:
Make SBCommandInterpreter::IsActive() not have to take a lock.


Modified:
    lldb/branches/iohandler/include/lldb/Core/IOHandler.h
    lldb/branches/iohandler/source/Core/Debugger.cpp

Modified: lldb/branches/iohandler/include/lldb/Core/IOHandler.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/include/lldb/Core/IOHandler.h?rev=199435&r1=199434&r2=199435&view=diff
==============================================================================
--- lldb/branches/iohandler/include/lldb/Core/IOHandler.h (original)
+++ lldb/branches/iohandler/include/lldb/Core/IOHandler.h Thu Jan 16 17:04:16 2014
@@ -487,7 +487,8 @@ namespace lldb_private {
         
         IOHandlerStack () :
             m_stack(),
-            m_mutex(Mutex::eMutexTypeRecursive)
+            m_mutex(Mutex::eMutexTypeRecursive),
+            m_top (NULL)
         {
         }
         
@@ -509,6 +510,8 @@ namespace lldb_private {
             {
                 Mutex::Locker locker (m_mutex);
                 m_stack.push (sp);
+                // Set m_top the non-locking IsTop() call
+                m_top = sp.get();
             }
         }
         
@@ -537,6 +540,11 @@ namespace lldb_private {
             Mutex::Locker locker (m_mutex);
             if (!m_stack.empty())
                 m_stack.pop();
+            // Set m_top the non-locking IsTop() call
+            if (m_stack.empty())
+                m_top = NULL;
+            else
+                m_top = m_stack.top().get();
         }
 
         Mutex &
@@ -545,10 +553,17 @@ namespace lldb_private {
             return m_mutex;
         }
         
+        bool
+        IsTop (const lldb::IOHandlerSP &io_handler_sp) const
+        {
+            return m_top == io_handler_sp.get();
+        }
+        
     protected:
         
         std::stack<lldb::IOHandlerSP> m_stack;
         mutable Mutex m_mutex;
+        IOHandler *m_top;
         
     private:
         

Modified: lldb/branches/iohandler/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/iohandler/source/Core/Debugger.cpp?rev=199435&r1=199434&r2=199435&view=diff
==============================================================================
--- lldb/branches/iohandler/source/Core/Debugger.cpp (original)
+++ lldb/branches/iohandler/source/Core/Debugger.cpp Thu Jan 16 17:04:16 2014
@@ -881,8 +881,7 @@ Debugger::ExecuteIOHanders()
 bool
 Debugger::IsTopIOHandler (const lldb::IOHandlerSP& reader_sp)
 {
-    IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
-    return top_reader_sp.get() == reader_sp.get();
+    return m_input_reader_stack.IsTop (reader_sp);
 }
 
 





More information about the llvm-branch-commits mailing list