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/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 1d92f31..1e7f1e5 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -1978,7 +1978,7 @@
     if (check_global_list)
     {
         // Check the global list
-        Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
+        std::lock_guard<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex());
         const size_t num_modules = Module::GetNumberAllocatedModules();
         ModuleSP module_sp;
         for (size_t image_idx = 0; image_idx<num_modules; ++image_idx)
@@ -2470,7 +2470,7 @@
                     else
                     {
                         // Check the global list
-                        Mutex::Locker locker(Module::GetAllocationModuleCollectionMutex());
+                        std::lock_guard<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex());
 
                         result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr);
                     }
@@ -3291,16 +3291,20 @@
             }
 
             size_t num_modules = 0;
-            Mutex::Locker locker;      // This locker will be locked on the mutex in module_list_ptr if it is non-nullptr.
-                                       // Otherwise it will lock the AllocationModuleCollectionMutex when accessing
-                                       // the global module list directly.
+
+            // This locker will be locked on the mutex in module_list_ptr if it is non-nullptr.
+            // Otherwise it will lock the AllocationModuleCollectionMutex when accessing
+            // the global module list directly.
+            std::unique_lock<std::recursive_mutex> guard(Module::GetAllocationModuleCollectionMutex(), std::defer_lock);
+            Mutex::Locker locker;
+
             const ModuleList *module_list_ptr = nullptr;
             const size_t argc = command.GetArgumentCount();
             if (argc == 0)
             {
                 if (use_global_module_list)
                 {
-                    locker.Lock (Module::GetAllocationModuleCollectionMutex());
+                    guard.lock();
                     num_modules = Module::GetNumberAllocatedModules();
                 }
                 else
@@ -3331,6 +3335,7 @@
 
             if (module_list_ptr != nullptr)
             {
+                assert(use_global_module_list == false && "locking violation");
                 locker.Lock(module_list_ptr->GetMutex());
                 num_modules = module_list_ptr->GetSize();
             }