[lldb] Add parts accidentally left out of 769d704: Recommit "[lldb/Core] Fix a race in the Communication class"

I went to a great length to explain the reason why these changes were
needed, but I did not actually ammend the patch to include them. :(
This commit is contained in:
Pavel Labath 2020-04-09 14:41:51 +02:00
parent db91a6b800
commit a9406daaa6

View File

@ -362,10 +362,17 @@ lldb::thread_result_t Communication::ReadThread(lldb::thread_arg_t p) {
if (log)
LLDB_LOGF(log, "%p Communication::ReadThread () thread exiting...", p);
comm->BroadcastEvent(eBroadcastBitNoMorePendingInput);
// Handle threads wishing to synchronize with us.
{
std::lock_guard<std::mutex> guard(comm->m_synchronize_mutex);
// Prevent new ones from showing up.
comm->m_read_thread_did_exit = true;
// Unblock any existing thread waiting for the synchronization signal.
comm->BroadcastEvent(eBroadcastBitNoMorePendingInput);
// Wait for the thread to finish...
std::lock_guard<std::mutex> guard(comm->m_synchronize_mutex);
// ... and disconnect.
if (disconnect)
comm->Disconnect();
}