From d9896733c78d9633b5da0febbaeb0e02f49aebca Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Thu, 31 May 2012 16:54:51 +0000 Subject: [PATCH] Fixed a case where multiple threads can be asking to send a packet to the GDB server and one of three things will happen: 1 - everything works 2 - one thread will fail to send the packet due to not being able to get the sequence mutex 3 - one thread will try and interrupt the other packet sending and fail and not send the packet Now the flow is a bit different. Prior to this fix we did: if (try_get_sequence_mutex()) { send_packet() return success; } else { if (async_ok) { interrupt() send_packet() resume() return success; } } return fail The issue is that the call to "try_get_sequence_mutex()" could fail if another thread was sending a packet and could cause us to just not send the packet and an error would be returned. What we really want is to try and get the sequence mutex, and if this succeeds, send the packet. Else check if we are running and if we are, do what we used to do. The big difference is when we aren't running, we wait for the sequence mutex so we don't drop packets. Pseudo code is: if (try_get_sequence_mutex()) { // Safe to send the packet right away send_packet() return success; } else { if (running) { // We are running, interrupt and send async packet if ok to do so, // else it is ok to fail if (async_ok) { interrupt() send_packet() resume() return success; } } else { // Not running, wait for the sequence mutex so we don't drop packets get_sequence_mutex() send_packet() return success; } } return fail llvm-svn: 157751 --- .../Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index e55328b93e77..c5fc4affe32c 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -264,7 +264,11 @@ GDBRemoteCommunication::GetAck () bool GDBRemoteCommunication::GetSequenceMutex (Mutex::Locker& locker) { - return locker.TryLock (m_sequence_mutex); + if (IsRunning()) + return locker.TryLock (m_sequence_mutex); + + locker.Lock (m_sequence_mutex); + return true; }