Clean up vestigial remnants of locking primitives
This finally removes the use of the Mutex and Condition classes. This is an
intricate patch as the Mutex and Condition classes were tied together.
Furthermore, many places had slightly differing uses of time values. Convert
timeout values to relative everywhere to permit the use of
std::chrono::duration, which is required for the use of
std::condition_variable's timeout. Adjust all Condition and related Mutex
classes over to std::{,recursive_}mutex and std::condition_variable.
This change primarily comes at the cost of breaking the TracingMutex which was
based around the Mutex class. It would be possible to write a wrapper to
provide similar functionality, but that is beyond the scope of this change.
llvm-svn: 277011
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index ba018be..a9ecd93 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -720,9 +720,10 @@
std::string &response_string
)
{
- Mutex::Locker locker;
- if (!GetSequenceMutex(locker,
- "ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex"))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (!GetSequenceMutex(
+ lock,
+ "ProcessGDBRemote::SendPacketsAndConcatenateResponses() failed due to not getting the sequence mutex"))
{
Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS));
if (log)
@@ -821,7 +822,7 @@
)
{
PacketResult packet_result = PacketResult::ErrorSendFailed;
- Mutex::Locker locker;
+ std::unique_lock<std::recursive_mutex> lock;
Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
// In order to stop async notifications from being processed in the middle of the
@@ -829,7 +830,7 @@
static ListenerSP hijack_listener_sp(Listener::MakeListener("lldb.NotifyHijacker"));
HijackBroadcaster(hijack_listener_sp, eBroadcastBitGdbReadThreadGotNotify);
- if (GetSequenceMutex (locker))
+ if (GetSequenceMutex(lock))
{
packet_result = SendPacketAndWaitForResponseNoLock (payload, payload_length, response);
}
@@ -848,19 +849,22 @@
log->Printf ("async: async packet = %s", m_async_packet.c_str());
bool timed_out = false;
- if (SendInterrupt(locker, 2, timed_out))
+ if (SendInterrupt(lock, 2, timed_out))
{
if (m_interrupt_sent)
{
m_interrupt_sent = false;
- TimeValue timeout_time;
- timeout_time = TimeValue::Now();
- timeout_time.OffsetWithSeconds (m_packet_timeout);
+
+ std::chrono::time_point<std::chrono::system_clock> until;
+ until = std::chrono::system_clock::now() + std::chrono::seconds(m_packet_timeout);
if (log)
log->Printf ("async: sent interrupt");
- if (m_async_packet_predicate.WaitForValueEqualTo (false, &timeout_time, &timed_out))
+ if (m_async_packet_predicate.WaitForValueEqualTo(
+ false, std::chrono::duration_cast<std::chrono::microseconds>(
+ until - std::chrono::system_clock::now()),
+ &timed_out))
{
if (log)
log->Printf ("async: got response");
@@ -876,7 +880,10 @@
}
// Make sure we wait until the continue packet has been sent again...
- if (m_private_is_running.WaitForValueEqualTo (true, &timeout_time, &timed_out))
+ if (m_private_is_running.WaitForValueEqualTo(
+ true, std::chrono::duration_cast<std::chrono::microseconds>(
+ until - std::chrono::system_clock::now()),
+ &timed_out))
{
if (log)
{
@@ -1045,7 +1052,7 @@
log->Printf("GDBRemoteCommunicationClient::%s ()", __FUNCTION__);
// we want to lock down packet sending while we continue
- Mutex::Locker locker(m_sequence_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_sequence_mutex);
// here we broadcast this before we even send the packet!!
// this signals doContinue() to exit
@@ -1094,7 +1101,7 @@
if (log)
log->Printf ("GDBRemoteCommunicationClient::%s ()", __FUNCTION__);
- Mutex::Locker locker(m_sequence_mutex);
+ std::lock_guard<std::recursive_mutex> guard(m_sequence_mutex);
StateType state = eStateRunning;
m_public_is_running.SetValue (true, eBroadcastNever);
@@ -1394,8 +1401,8 @@
std::lock_guard<std::recursive_mutex> guard(m_async_mutex);
m_async_signal = signo;
bool timed_out = false;
- Mutex::Locker locker;
- if (SendInterrupt (locker, 1, timed_out))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (SendInterrupt(lock, 1, timed_out))
return true;
m_async_signal = -1;
return false;
@@ -1412,12 +1419,8 @@
// (gdb remote protocol requires this), and do what we need to do, then resume.
bool
-GDBRemoteCommunicationClient::SendInterrupt
-(
- Mutex::Locker& locker,
- uint32_t seconds_to_wait_for_stop,
- bool &timed_out
-)
+GDBRemoteCommunicationClient::SendInterrupt(std::unique_lock<std::recursive_mutex> &lock,
+ uint32_t seconds_to_wait_for_stop, bool &timed_out)
{
timed_out = false;
Log *log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_PROCESS | GDBR_LOG_PACKETS));
@@ -1425,7 +1428,7 @@
if (IsRunning())
{
// Only send an interrupt if our debugserver is running...
- if (GetSequenceMutex (locker))
+ if (GetSequenceMutex(lock))
{
if (log)
log->Printf ("SendInterrupt () - got sequence mutex without having to interrupt");
@@ -1444,13 +1447,8 @@
m_interrupt_sent = true;
if (seconds_to_wait_for_stop)
{
- TimeValue timeout;
- if (seconds_to_wait_for_stop)
- {
- timeout = TimeValue::Now();
- timeout.OffsetWithSeconds (seconds_to_wait_for_stop);
- }
- if (m_private_is_running.WaitForValueEqualTo (false, &timeout, &timed_out))
+ if (m_private_is_running.WaitForValueEqualTo(false, std::chrono::seconds(seconds_to_wait_for_stop),
+ &timed_out))
{
if (log)
log->PutCString ("SendInterrupt () - sent interrupt, private state stopped");
@@ -3653,10 +3651,10 @@
GDBRemoteCommunicationClient::GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
bool &sequence_mutex_unavailable)
{
- Mutex::Locker locker;
+ std::unique_lock<std::recursive_mutex> lock;
thread_ids.clear();
-
- if (GetSequenceMutex (locker, "ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex"))
+
+ if (GetSequenceMutex(lock, "ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex"))
{
sequence_mutex_unavailable = false;
StringExtractorGDBRemote response;
@@ -4203,8 +4201,8 @@
bool
GDBRemoteCommunicationClient::ReadRegister(lldb::tid_t tid, uint32_t reg, StringExtractorGDBRemote &response)
{
- Mutex::Locker locker;
- if (GetSequenceMutex (locker, "Didn't get sequence mutex for p packet."))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(lock, "Didn't get sequence mutex for p packet."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
@@ -4228,8 +4226,8 @@
bool
GDBRemoteCommunicationClient::ReadAllRegisters (lldb::tid_t tid, StringExtractorGDBRemote &response)
{
- Mutex::Locker locker;
- if (GetSequenceMutex (locker, "Didn't get sequence mutex for g packet."))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(lock, "Didn't get sequence mutex for g packet."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
@@ -4256,8 +4254,8 @@
return false;
m_supports_QSaveRegisterState = eLazyBoolYes;
- Mutex::Locker locker;
- if (GetSequenceMutex (locker, "Didn't get sequence mutex for QSaveRegisterState."))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(lock, "Didn't get sequence mutex for QSaveRegisterState."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
if (thread_suffix_supported || SetCurrentThread(tid))
@@ -4298,9 +4296,9 @@
// order to be useful
if (m_supports_QSaveRegisterState == eLazyBoolNo)
return false;
-
- Mutex::Locker locker;
- if (GetSequenceMutex (locker, "Didn't get sequence mutex for QRestoreRegisterState."))
+
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(lock, "Didn't get sequence mutex for QRestoreRegisterState."))
{
const bool thread_suffix_supported = GetThreadSuffixSupported();
if (thread_suffix_supported || SetCurrentThread(tid))
@@ -4530,8 +4528,10 @@
if (m_supports_qSymbol && m_qSymbol_requests_done == false)
{
- Mutex::Locker locker;
- if (GetSequenceMutex(locker, "GDBRemoteCommunicationClient::ServeSymbolLookups() failed due to not getting the sequence mutex"))
+ std::unique_lock<std::recursive_mutex> lock;
+ if (GetSequenceMutex(
+ lock,
+ "GDBRemoteCommunicationClient::ServeSymbolLookups() failed due to not getting the sequence mutex"))
{
StreamString packet;
packet.PutCString ("qSymbol::");