remove use of Mutex in favour of std::{,recursive_}mutex

This is a pretty straightforward first pass over removing a number of uses of
Mutex in favor of std::mutex or std::recursive_mutex. The problem is that there
are interfaces which take Mutex::Locker & to lock internal locks. This patch
cleans up most of the easy cases. The only non-trivial change is in
CommandObjectTarget.cpp where a Mutex::Locker was split into two.

llvm-svn: 269877
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 1650215..d5727ef 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -12,6 +12,7 @@
 // C Includes
 // C++ Includes
 #include <map>
+#include <mutex>
 
 // Other libraries and framework includes
 #include "llvm/ADT/StringRef.h"
@@ -67,10 +68,10 @@
 
 #pragma mark Static Functions
 
-static Mutex &
-GetDebuggerListMutex ()
+static std::recursive_mutex &
+GetDebuggerListMutex()
 {
-    static Mutex g_mutex(Mutex::eMutexTypeRecursive);
+    static std::recursive_mutex g_mutex;
     return g_mutex;
 }
 
@@ -469,7 +470,7 @@
     assert(lldb_initialized && "Debugger::Terminate called without a matching Debugger::Initialize!");
 
     // Clear our master list of debugger objects
-    Mutex::Locker locker (GetDebuggerListMutex ());
+    std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
     auto& debuggers = GetDebuggerList();
     for (const auto& debugger: debuggers)
         debugger->Clear();
@@ -605,7 +606,7 @@
     DebuggerSP debugger_sp (new Debugger(log_callback, baton));
     if (lldb_initialized)
     {
-        Mutex::Locker locker (GetDebuggerListMutex ());
+        std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
         GetDebuggerList().push_back(debugger_sp);
     }
     debugger_sp->InstanceInitialize ();
@@ -622,7 +623,7 @@
 
     if (lldb_initialized)
     {
-        Mutex::Locker locker (GetDebuggerListMutex ());
+        std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
         DebuggerList &debugger_list = GetDebuggerList ();
         DebuggerList::iterator pos, end = debugger_list.end();
         for (pos = debugger_list.begin (); pos != end; ++pos)
@@ -642,7 +643,7 @@
     DebuggerSP debugger_sp;
     if (lldb_initialized)
     {
-        Mutex::Locker locker (GetDebuggerListMutex ());
+        std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
         DebuggerList &debugger_list = GetDebuggerList();
         DebuggerList::iterator pos, end = debugger_list.end();
 
@@ -664,7 +665,7 @@
     TargetSP target_sp;
     if (lldb_initialized)
     {
-        Mutex::Locker locker (GetDebuggerListMutex ());
+        std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
         DebuggerList &debugger_list = GetDebuggerList();
         DebuggerList::iterator pos, end = debugger_list.end();
         for (pos = debugger_list.begin(); pos != end; ++pos)
@@ -683,7 +684,7 @@
     TargetSP target_sp;
     if (lldb_initialized)
     {
-        Mutex::Locker locker (GetDebuggerListMutex ());
+        std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
         DebuggerList &debugger_list = GetDebuggerList();
         DebuggerList::iterator pos, end = debugger_list.end();
         for (pos = debugger_list.begin(); pos != end; ++pos)
@@ -922,33 +923,33 @@
 }
 
 void
-Debugger::DispatchInputInterrupt ()
+Debugger::DispatchInputInterrupt()
 {
-    Mutex::Locker locker (m_input_reader_stack.GetMutex());
-    IOHandlerSP reader_sp (m_input_reader_stack.Top());
+    std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
+    IOHandlerSP reader_sp(m_input_reader_stack.Top());
     if (reader_sp)
         reader_sp->Interrupt();
 }
 
 void
-Debugger::DispatchInputEndOfFile ()
+Debugger::DispatchInputEndOfFile()
 {
-    Mutex::Locker locker (m_input_reader_stack.GetMutex());
-    IOHandlerSP reader_sp (m_input_reader_stack.Top());
+    std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
+    IOHandlerSP reader_sp(m_input_reader_stack.Top());
     if (reader_sp)
         reader_sp->GotEOF();
 }
 
 void
-Debugger::ClearIOHandlers ()
+Debugger::ClearIOHandlers()
 {
     // The bottom input reader should be the main debugger input reader.  We do not want to close that one here.
-    Mutex::Locker locker (m_input_reader_stack.GetMutex());
+    std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
     while (m_input_reader_stack.GetSize() > 1)
     {
-        IOHandlerSP reader_sp (m_input_reader_stack.Top());
+        IOHandlerSP reader_sp(m_input_reader_stack.Top());
         if (reader_sp)
-            PopIOHandler (reader_sp);
+            PopIOHandler(reader_sp);
     }
 }
 
@@ -1041,16 +1042,16 @@
 }
 
 void
-Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
+Debugger::AdoptTopIOHandlerFilesIfInvalid(StreamFileSP &in, StreamFileSP &out, StreamFileSP &err)
 {
     // Before an IOHandler runs, it must have in/out/err streams.
     // This function is called when one ore more of the streams
     // are nullptr. We use the top input reader's in/out/err streams,
     // or fall back to the debugger file handles, or we fall back
     // onto stdin/stdout/stderr as a last resort.
-    
-    Mutex::Locker locker (m_input_reader_stack.GetMutex());
-    IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
+
+    std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
+    IOHandlerSP top_reader_sp(m_input_reader_stack.Top());
     // If no STDIN has been set, then set it appropriately
     if (!in)
     {
@@ -1058,7 +1059,7 @@
             in = top_reader_sp->GetInputStreamFile();
         else
             in = GetInputFile();
-        
+
         // If there is nothing, use stdin
         if (!in)
             in = StreamFileSP(new StreamFile(stdin, false));
@@ -1070,7 +1071,7 @@
             out = top_reader_sp->GetOutputStreamFile();
         else
             out = GetOutputFile();
-        
+
         // If there is nothing, use stdout
         if (!out)
             out = StreamFileSP(new StreamFile(stdout, false));
@@ -1082,31 +1083,30 @@
             err = top_reader_sp->GetErrorStreamFile();
         else
             err = GetErrorFile();
-        
+
         // If there is nothing, use stderr
         if (!err)
             err = StreamFileSP(new StreamFile(stdout, false));
-        
     }
 }
 
 void
-Debugger::PushIOHandler (const IOHandlerSP& reader_sp)
+Debugger::PushIOHandler(const IOHandlerSP &reader_sp)
 {
     if (!reader_sp)
         return;
- 
-    Mutex::Locker locker (m_input_reader_stack.GetMutex());
+
+    std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
 
     // Get the current top input reader...
-    IOHandlerSP top_reader_sp (m_input_reader_stack.Top());
-    
+    IOHandlerSP top_reader_sp(m_input_reader_stack.Top());
+
     // Don't push the same IO handler twice...
     if (reader_sp == top_reader_sp)
         return;
 
     // Push our new input reader
-    m_input_reader_stack.Push (reader_sp);
+    m_input_reader_stack.Push(reader_sp);
     reader_sp->Activate();
 
     // Interrupt the top input reader to it will exit its Run() function
@@ -1119,12 +1119,12 @@
 }
 
 bool
-Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp)
+Debugger::PopIOHandler(const IOHandlerSP &pop_reader_sp)
 {
-    if (! pop_reader_sp)
+    if (!pop_reader_sp)
         return false;
 
-    Mutex::Locker locker (m_input_reader_stack.GetMutex());
+    std::lock_guard<std::recursive_mutex> guard(m_input_reader_stack.GetMutex());
 
     // The reader on the stop of the stack is done, so let the next
     // read on the stack refresh its prompt and if there is one...
@@ -1138,7 +1138,7 @@
 
     reader_sp->Deactivate();
     reader_sp->Cancel();
-    m_input_reader_stack.Pop ();
+    m_input_reader_stack.Pop();
 
     reader_sp = m_input_reader_stack.Top();
     if (reader_sp)
@@ -1164,7 +1164,7 @@
 {
     if (lldb_initialized)
     {
-        Mutex::Locker locker (GetDebuggerListMutex ());
+        std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
         return GetDebuggerList().size();
     }
     return 0;
@@ -1177,9 +1177,9 @@
     
     if (lldb_initialized)
     {
-        Mutex::Locker locker (GetDebuggerListMutex ());
+        std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
         DebuggerList &debugger_list = GetDebuggerList();
-        
+
         if (index < debugger_list.size())
             debugger_sp = debugger_list[index];
     }
@@ -1194,7 +1194,7 @@
 
     if (lldb_initialized)
     {
-        Mutex::Locker locker (GetDebuggerListMutex ());
+        std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex());
         DebuggerList &debugger_list = GetDebuggerList();
         DebuggerList::iterator pos, end = debugger_list.end();
         for (pos = debugger_list.begin(); pos != end; ++pos)