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/Communication.cpp b/lldb/source/Core/Communication.cpp
index 557fb95..f1dcb95 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -33,31 +33,30 @@
return class_name;
}
-Communication::Communication(const char *name) :
- Broadcaster(nullptr, name),
- m_connection_sp(),
- m_read_thread_enabled(false),
- m_read_thread_did_exit(false),
- m_bytes(),
- m_bytes_mutex(Mutex::eMutexTypeRecursive),
- m_write_mutex(Mutex::eMutexTypeNormal),
- m_synchronize_mutex(Mutex::eMutexTypeNormal),
- m_callback(nullptr),
- m_callback_baton(nullptr),
- m_close_on_eof(true)
+Communication::Communication(const char *name)
+ : Broadcaster(nullptr, name),
+ m_connection_sp(),
+ m_read_thread_enabled(false),
+ m_read_thread_did_exit(false),
+ m_bytes(),
+ m_bytes_mutex(),
+ m_write_mutex(),
+ m_synchronize_mutex(),
+ m_callback(nullptr),
+ m_callback_baton(nullptr),
+ m_close_on_eof(true)
{
- lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
- "%p Communication::Communication (name = %s)",
- this, name);
+ lldb_private::LogIfAnyCategoriesSet(LIBLLDB_LOG_OBJECT | LIBLLDB_LOG_COMMUNICATION,
+ "%p Communication::Communication (name = %s)", this, name);
- SetEventName (eBroadcastBitDisconnected, "disconnected");
- SetEventName (eBroadcastBitReadThreadGotBytes, "got bytes");
- SetEventName (eBroadcastBitReadThreadDidExit, "read thread did exit");
- SetEventName (eBroadcastBitReadThreadShouldExit, "read thread should exit");
- SetEventName (eBroadcastBitPacketAvailable, "packet available");
- SetEventName (eBroadcastBitNoMorePendingInput, "no more pending input");
-
+ SetEventName(eBroadcastBitDisconnected, "disconnected");
+ SetEventName(eBroadcastBitReadThreadGotBytes, "got bytes");
+ SetEventName(eBroadcastBitReadThreadDidExit, "read thread did exit");
+ SetEventName(eBroadcastBitReadThreadShouldExit, "read thread should exit");
+ SetEventName(eBroadcastBitPacketAvailable, "packet available");
+ SetEventName(eBroadcastBitNoMorePendingInput, "no more pending input");
+
CheckInWithManager();
}
@@ -205,7 +204,7 @@
{
lldb::ConnectionSP connection_sp (m_connection_sp);
- Mutex::Locker locker(m_write_mutex);
+ std::lock_guard<std::mutex> guard(m_write_mutex);
lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
"%p Communication::Write (src = %p, src_len = %" PRIu64 ") connection = %p",
this,
@@ -277,7 +276,7 @@
size_t
Communication::GetCachedBytes (void *dst, size_t dst_len)
{
- Mutex::Locker locker(m_bytes_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex);
if (!m_bytes.empty())
{
// If DST is nullptr and we have a thread, then return the number
@@ -311,7 +310,7 @@
}
else if (bytes != nullptr && len > 0)
{
- Mutex::Locker locker(m_bytes_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_bytes_mutex);
m_bytes.append ((const char *)bytes, len);
if (broadcast)
BroadcastEventIfUnique (eBroadcastBitReadThreadGotBytes);
@@ -425,7 +424,7 @@
Communication::SynchronizeWithReadThread ()
{
// Only one thread can do the synchronization dance at a time.
- Mutex::Locker locker(m_synchronize_mutex);
+ std::lock_guard<std::mutex> guard(m_synchronize_mutex);
// First start listening for the synchronization event.
ListenerSP listener_sp(Listener::MakeListener("Communication::SyncronizeWithReadThread"));