diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-05-18 01:59:10 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-05-18 01:59:10 +0000 |
commit | 16ff8604690ea63a3a82dd3b156061afb84dbcf1 (patch) | |
tree | a2d912258ecb0690f4a810ca1e438fc277160326 /lldb/source/Core/Debugger.cpp | |
parent | a36a61d46ac3f2ea10e78ac816bca5784bc8ba35 (diff) | |
download | bcm5719-llvm-16ff8604690ea63a3a82dd3b156061afb84dbcf1.tar.gz bcm5719-llvm-16ff8604690ea63a3a82dd3b156061afb84dbcf1.zip |
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
Diffstat (limited to 'lldb/source/Core/Debugger.cpp')
-rw-r--r-- | lldb/source/Core/Debugger.cpp | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 16502159b6b..d5727efe6a3 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 @@ static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024; #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 @@ Debugger::Terminate () 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 @@ Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton) 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 @@ Debugger::Destroy (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(); for (pos = debugger_list.begin (); pos != end; ++pos) @@ -642,7 +643,7 @@ Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name) 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 @@ Debugger::FindTargetWithProcessID (lldb::pid_t pid) 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 @@ Debugger::FindTargetWithProcess (Process *process) 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 @@ Debugger::GetSelectedExecutionContext () } 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 @@ Debugger::RunIOHandler (const IOHandlerSP& reader_sp) } 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 @@ Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, 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 @@ Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, 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 @@ Debugger::AdoptTopIOHandlerFilesIfInvalid (StreamFileSP &in, StreamFileSP &out, 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 @@ Debugger::PushIOHandler (const IOHandlerSP& reader_sp) } 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 @@ Debugger::PopIOHandler (const IOHandlerSP& pop_reader_sp) 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 @@ Debugger::GetNumDebuggers() { if (lldb_initialized) { - Mutex::Locker locker (GetDebuggerListMutex ()); + std::lock_guard<std::recursive_mutex> guard(GetDebuggerListMutex()); return GetDebuggerList().size(); } return 0; @@ -1177,9 +1177,9 @@ Debugger::GetDebuggerAtIndex (size_t index) 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 @@ Debugger::FindDebuggerWithID (lldb::user_id_t id) 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) |