[Lldb-commits] [lldb] r156221 - in /lldb/trunk: include/lldb/Host/ source/API/ source/Breakpoint/ source/Commands/ source/Core/ source/Host/common/ source/Plugins/Process/MacOSX-Kernel/ source/Plugins/Process/gdb-remote/ source/Target/

Jim Ingham jingham at apple.com
Fri May 4 16:02:50 PDT 2012


Author: jingham
Date: Fri May  4 18:02:50 2012
New Revision: 156221

URL: http://llvm.org/viewvc/llvm-project?rev=156221&view=rev
Log:
Don't expose the pthread_mutex_t underlying the Mutex & Mutex::Locker classes.  
No one was using it and Locker(pthread_mutex_t *) immediately asserts for 
pthread_mutex_t's that don't come from a Mutex anyway.  Rather than try to make
that work, we should maintain the Mutex abstraction and not pass around the
platform implementation...

Make Mutex::Locker::Lock take a Mutex & or a Mutex *, and remove the constructor
taking a pthread_mutex_t *.  You no longer need to call Mutex::GetMutex to pass
your mutex to a Locker (you can't in fact, since I made it private.)

Modified:
    lldb/trunk/include/lldb/Host/Condition.h
    lldb/trunk/include/lldb/Host/Mutex.h
    lldb/trunk/include/lldb/Host/Predicate.h
    lldb/trunk/source/API/SBCommandInterpreter.cpp
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/API/SBFunction.cpp
    lldb/trunk/source/API/SBInstruction.cpp
    lldb/trunk/source/API/SBSymbol.cpp
    lldb/trunk/source/Breakpoint/BreakpointList.cpp
    lldb/trunk/source/Breakpoint/WatchpointList.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/ModuleList.cpp
    lldb/trunk/source/Host/common/Condition.cpp
    lldb/trunk/source/Host/common/Mutex.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
    lldb/trunk/source/Target/StackFrameList.cpp

Modified: lldb/trunk/include/lldb/Host/Condition.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Condition.h?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Condition.h (original)
+++ lldb/trunk/include/lldb/Host/Condition.h Fri May  4 18:02:50 2012
@@ -13,6 +13,7 @@
 
 
 #include <pthread.h>
+#include "lldb/Host/Mutex.h"
 
 namespace lldb_private {
 
@@ -56,15 +57,6 @@
     Broadcast ();
 
     //------------------------------------------------------------------
-    /// Get accessor to the pthread condition object.
-    ///
-    /// @return
-    ///     A pointer to the condition variable owned by this object.
-    //------------------------------------------------------------------
-    pthread_cond_t *
-    GetCondition ();
-
-    //------------------------------------------------------------------
     /// Unblocks one thread waiting for the condition variable
     ///
     /// @return
@@ -107,13 +99,22 @@
     /// @see Condition::Signal()
     //------------------------------------------------------------------
     int
-    Wait (pthread_mutex_t *mutex, const TimeValue *abstime = NULL, bool *timed_out = NULL);
+    Wait (Mutex &mutex, const TimeValue *abstime = NULL, bool *timed_out = NULL);
 
 protected:
     //------------------------------------------------------------------
     // Member variables
     //------------------------------------------------------------------
     pthread_cond_t m_condition; ///< The condition variable.
+    
+    //------------------------------------------------------------------
+    /// Get accessor to the pthread condition object.
+    ///
+    /// @return
+    ///     A pointer to the condition variable owned by this object.
+    //------------------------------------------------------------------
+    pthread_cond_t *
+    GetCondition ();
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/include/lldb/Host/Mutex.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Mutex.h?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Mutex.h (original)
+++ lldb/trunk/include/lldb/Host/Mutex.h Fri May  4 18:02:50 2012
@@ -23,6 +23,9 @@
 class Mutex
 {
 public:
+    friend class Locker;
+    friend class Condition;
+    
     enum Type
     {
         eMutexTypeNormal,       ///< Mutex that can't recursively entered by the same thread
@@ -78,18 +81,6 @@
         Locker(Mutex* m);
 
         //--------------------------------------------------------------
-        /// Constructor with a raw pthread mutex object pointer.
-        ///
-        /// This will create a scoped mutex locking object that locks
-        /// \a mutex.
-        ///
-        /// @param[in] mutex
-        ///     A pointer to a pthread_mutex_t that will get locked if
-        ///     non-NULL.
-        //--------------------------------------------------------------
-        Locker(pthread_mutex_t *mutex);
-
-        //--------------------------------------------------------------
         /// Desstructor
         ///
         /// Unlocks any valid pthread_mutex_t that this object may
@@ -105,7 +96,14 @@
         /// non-NULL.
         //--------------------------------------------------------------
         void
-        Lock (pthread_mutex_t *mutex);
+        Lock (Mutex &mutex);
+        
+        void
+        Lock (Mutex *mutex)
+        {
+            if (mutex)
+                Lock(*mutex);
+        }
 
         //--------------------------------------------------------------
         /// Change the contained mutex only if the mutex can be locked.
@@ -123,7 +121,16 @@
         ///     returns \b false otherwise.
         //--------------------------------------------------------------
         bool
-        TryLock (pthread_mutex_t *mutex);
+        TryLock (Mutex &mutex);
+        
+        bool
+        TryLock (Mutex *mutex)
+        {
+            if (mutex)
+                return TryLock(*mutex);
+            else
+                return false;
+        }
 
         void
         Unlock ();
@@ -172,15 +179,6 @@
     ~Mutex();
 
     //------------------------------------------------------------------
-    /// Mutex get accessor.
-    ///
-    /// @return
-    ///     A pointer to the pthread mutex object owned by this object.
-    //------------------------------------------------------------------
-    pthread_mutex_t *
-    GetMutex();
-
-    //------------------------------------------------------------------
     /// Lock the mutex.
     ///
     /// Locks the mutex owned by this object. If the mutex is already
@@ -234,7 +232,17 @@
     // Member variables
     //------------------------------------------------------------------
     pthread_mutex_t m_mutex; ///< The pthread mutex object.
+
 private:
+    //------------------------------------------------------------------
+    /// Mutex get accessor.
+    ///
+    /// @return
+    ///     A pointer to the pthread mutex object owned by this object.
+    //------------------------------------------------------------------
+    pthread_mutex_t *
+    GetMutex();
+
     Mutex(const Mutex&);
     const Mutex& operator=(const Mutex&);
 };

Modified: lldb/trunk/include/lldb/Host/Predicate.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Predicate.h?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Predicate.h (original)
+++ lldb/trunk/include/lldb/Host/Predicate.h Fri May  4 18:02:50 2012
@@ -314,7 +314,7 @@
 
         while (err == 0 && m_value != value)
         {
-            err = m_condition.Wait (m_mutex.GetMutex(), abstime, timed_out);
+            err = m_condition.Wait (m_mutex, abstime, timed_out);
         }
 
         return m_value == value;
@@ -339,7 +339,7 @@
 
         while (err == 0 && m_value != wait_value)
         {
-            err = m_condition.Wait (m_mutex.GetMutex(), abstime, timed_out);
+            err = m_condition.Wait (m_mutex, abstime, timed_out);
         }
 
         if (m_value == wait_value)

Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Fri May  4 18:02:50 2012
@@ -93,7 +93,7 @@
         TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
         Mutex::Locker api_locker;
         if (target_sp)
-            api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock(target_sp->GetAPIMutex());
         m_opaque_ptr->HandleCommand (command_line, add_to_history, result.ref());
     }
     else
@@ -238,7 +238,7 @@
         TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
         Mutex::Locker api_locker;
         if (target_sp)
-            api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock(target_sp->GetAPIMutex());
         m_opaque_ptr->SourceInitFile (false, result.ref());
     }
     else
@@ -263,7 +263,7 @@
         TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
         Mutex::Locker api_locker;
         if (target_sp)
-            api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock(target_sp->GetAPIMutex());
         m_opaque_ptr->SourceInitFile (true, result.ref());
     }
     else

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Fri May  4 18:02:50 2012
@@ -308,7 +308,7 @@
         TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
         Mutex::Locker api_locker;
         if (target_sp)
-            api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock(target_sp->GetAPIMutex());
 
         SBCommandInterpreter sb_interpreter(GetCommandInterpreter ());
         SBCommandReturnObject result;
@@ -830,7 +830,7 @@
         TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
         Mutex::Locker api_locker;
         if (target_sp)
-            api_locker.Lock(target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock(target_sp->GetAPIMutex());
         InputReaderSP reader_sp(*reader);
         m_opaque_sp->PushInputReader (reader_sp);
     }

Modified: lldb/trunk/source/API/SBFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFunction.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFunction.cpp (original)
+++ lldb/trunk/source/API/SBFunction.cpp Fri May  4 18:02:50 2012
@@ -130,7 +130,7 @@
         TargetSP target_sp (target.GetSP());
         if (target_sp)
         {
-            api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock (target_sp->GetAPIMutex());
             target_sp->CalculateExecutionContext (exe_ctx);
             exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }

Modified: lldb/trunk/source/API/SBInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstruction.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/API/SBInstruction.cpp (original)
+++ lldb/trunk/source/API/SBInstruction.cpp Fri May  4 18:02:50 2012
@@ -78,7 +78,7 @@
         TargetSP target_sp (target.GetSP());
         if (target_sp)
         {
-            api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock (target_sp->GetAPIMutex());
             target_sp->CalculateExecutionContext (exe_ctx);
             exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }
@@ -97,7 +97,7 @@
         TargetSP target_sp (target.GetSP());
         if (target_sp)
         {
-            api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock (target_sp->GetAPIMutex());
             target_sp->CalculateExecutionContext (exe_ctx);
             exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }
@@ -116,7 +116,7 @@
         TargetSP target_sp (target.GetSP());
         if (target_sp)
         {
-            api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock (target_sp->GetAPIMutex());
             target_sp->CalculateExecutionContext (exe_ctx);
             exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }

Modified: lldb/trunk/source/API/SBSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBSymbol.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/API/SBSymbol.cpp (original)
+++ lldb/trunk/source/API/SBSymbol.cpp Fri May  4 18:02:50 2012
@@ -126,7 +126,7 @@
         TargetSP target_sp (target.GetSP());
         if (target_sp)
         {
-            api_locker.Lock (target_sp->GetAPIMutex().GetMutex());
+            api_locker.Lock (target_sp->GetAPIMutex());
             target_sp->CalculateExecutionContext (exe_ctx);
         }
         if (m_opaque_ptr->ValueIsAddress())

Modified: lldb/trunk/source/Breakpoint/BreakpointList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointList.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointList.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointList.cpp Fri May  4 18:02:50 2012
@@ -223,5 +223,5 @@
 void
 BreakpointList::GetListMutex (Mutex::Locker &locker)
 {
-    return locker.Lock (m_mutex.GetMutex());
+    return locker.Lock (m_mutex);
 }

Modified: lldb/trunk/source/Breakpoint/WatchpointList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/WatchpointList.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/WatchpointList.cpp (original)
+++ lldb/trunk/source/Breakpoint/WatchpointList.cpp Fri May  4 18:02:50 2012
@@ -273,5 +273,5 @@
 void
 WatchpointList::GetListMutex (Mutex::Locker &locker)
 {
-    return locker.Lock (m_mutex.GetMutex());
+    return locker.Lock (m_mutex);
 }

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Fri May  4 18:02:50 2012
@@ -2839,7 +2839,7 @@
             
             if (use_global_module_list)
             {
-                locker.Lock (Module::GetAllocationModuleCollectionMutex()->GetMutex());
+                locker.Lock (Module::GetAllocationModuleCollectionMutex());
                 num_modules = Module::GetNumberAllocatedModules();
             }
             else

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Fri May  4 18:02:50 2012
@@ -118,12 +118,12 @@
     
     if (mandatory)
     {
-        locker.Lock (m_modules_mutex.GetMutex());
+        locker.Lock (m_modules_mutex);
     }
     else
     {
         // Not mandatory, remove orphans if we can get the mutex
-        if (!locker.TryLock(m_modules_mutex.GetMutex()))
+        if (!locker.TryLock(m_modules_mutex))
             return 0;
     }
     collection::iterator pos = m_modules.begin();

Modified: lldb/trunk/source/Host/common/Condition.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Condition.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Condition.cpp (original)
+++ lldb/trunk/source/Host/common/Condition.cpp Fri May  4 18:02:50 2012
@@ -78,7 +78,7 @@
 // The current thread re-acquires the lock on "mutex".
 //----------------------------------------------------------------------
 int
-Condition::Wait (pthread_mutex_t *mutex, const TimeValue *abstime, bool *timed_out)
+Condition::Wait (Mutex &mutex, const TimeValue *abstime, bool *timed_out)
 {
     int err = 0;
     do
@@ -86,10 +86,10 @@
         if (abstime && abstime->IsValid())
         {
             struct timespec abstime_ts = abstime->GetAsTimeSpec();
-            err = ::pthread_cond_timedwait (&m_condition, mutex, &abstime_ts);
+            err = ::pthread_cond_timedwait (&m_condition, mutex.GetMutex(), &abstime_ts);
         }
         else
-            err = ::pthread_cond_wait (&m_condition, mutex);
+            err = ::pthread_cond_wait (&m_condition, mutex.GetMutex());
     } while (err == EINTR);
 
     if (timed_out != NULL)

Modified: lldb/trunk/source/Host/common/Mutex.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Mutex.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Mutex.cpp (original)
+++ lldb/trunk/source/Host/common/Mutex.cpp Fri May  4 18:02:50 2012
@@ -108,7 +108,7 @@
 Mutex::Locker::Locker (Mutex& m) :
     m_mutex_ptr(NULL)
 {
-    Lock (m.GetMutex());
+    Lock (m);
 }
 
 //----------------------------------------------------------------------
@@ -121,18 +121,7 @@
     m_mutex_ptr(NULL)
 {
     if (m)
-        Lock (m->GetMutex());
-}
-
-//----------------------------------------------------------------------
-// Constructor with a raw pthread mutex object pointer.
-//
-// This will create a scoped mutex locking object that locks "mutex"
-//----------------------------------------------------------------------
-Mutex::Locker::Locker (pthread_mutex_t *mutex_ptr) :
-    m_mutex_ptr (NULL)
-{
-    Lock (mutex_ptr);
+        Lock (m);
 }
 
 //----------------------------------------------------------------------
@@ -150,8 +139,10 @@
 // mutex) and lock the new "mutex" object if it is non-NULL.
 //----------------------------------------------------------------------
 void
-Mutex::Locker::Lock (pthread_mutex_t *mutex_ptr)
+Mutex::Locker::Lock (Mutex &mutex)
 {
+    pthread_mutex_t *mutex_ptr = mutex.GetMutex();
+
     // We already have this mutex locked or both are NULL...
     if (m_mutex_ptr == mutex_ptr)
         return;
@@ -176,8 +167,10 @@
 }
 
 bool
-Mutex::Locker::TryLock (pthread_mutex_t *mutex_ptr)
+Mutex::Locker::TryLock (Mutex &mutex)
 {
+    pthread_mutex_t *mutex_ptr = mutex.GetMutex();
+    
     // We already have this mutex locked!
     if (m_mutex_ptr == mutex_ptr)
         return m_mutex_ptr != NULL;

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp Fri May  4 18:02:50 2012
@@ -153,7 +153,7 @@
 bool
 CommunicationKDP::GetSequenceMutex (Mutex::Locker& locker)
 {
-    return locker.TryLock (m_sequence_mutex.GetMutex());
+    return locker.TryLock (m_sequence_mutex);
 }
 
 

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Fri May  4 18:02:50 2012
@@ -264,7 +264,7 @@
 bool
 GDBRemoteCommunication::GetSequenceMutex (Mutex::Locker& locker)
 {
-    return locker.TryLock (m_sequence_mutex.GetMutex());
+    return locker.TryLock (m_sequence_mutex);
 }
 
 

Modified: lldb/trunk/source/Target/StackFrameList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrameList.cpp?rev=156221&r1=156220&r2=156221&view=diff
==============================================================================
--- lldb/trunk/source/Target/StackFrameList.cpp (original)
+++ lldb/trunk/source/Target/StackFrameList.cpp Fri May  4 18:02:50 2012
@@ -466,8 +466,8 @@
 void
 StackFrameList::Merge (std::auto_ptr<StackFrameList>& curr_ap, lldb::StackFrameListSP& prev_sp)
 {
-    Mutex::Locker curr_locker (curr_ap.get() ? curr_ap->m_mutex.GetMutex() : NULL);
-    Mutex::Locker prev_locker (prev_sp.get() ? prev_sp->m_mutex.GetMutex() : NULL);
+    Mutex::Locker curr_locker (curr_ap.get() ? &curr_ap->m_mutex : NULL);
+    Mutex::Locker prev_locker (prev_sp.get() ? &prev_sp->m_mutex : NULL);
 
 #if defined (DEBUG_STACK_FRAMES)
     StreamFile s(stdout, false);





More information about the lldb-commits mailing list