diff options
Diffstat (limited to 'lldb/source/Target/Process.cpp')
-rw-r--r-- | lldb/source/Target/Process.cpp | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index f156d086d28..a880782663a 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -726,7 +726,6 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP listener_sp, const UnixSig m_private_state_broadcaster(nullptr, "lldb.process.internal_state_broadcaster"), m_private_state_control_broadcaster(nullptr, "lldb.process.internal_state_control_broadcaster"), m_private_state_listener_sp (Listener::MakeListener("lldb.process.internal_state_listener")), - m_private_state_control_wait(), m_mod_id (), m_process_unique_id(0), m_thread_index_id (0), @@ -4109,44 +4108,46 @@ Process::ControlPrivateStateThread (uint32_t signal) // Signal the private state thread. First we should copy this is case the // thread starts exiting since the private state thread will NULL this out // when it exits - HostThread private_state_thread(m_private_state_thread); - if (private_state_thread.IsJoinable()) { - TimeValue timeout_time; - bool timed_out; - - m_private_state_control_broadcaster.BroadcastEvent(signal, nullptr); - - timeout_time = TimeValue::Now(); - timeout_time.OffsetWithSeconds(2); - if (log) - log->Printf ("Sending control event of type: %d.", signal); - m_private_state_control_wait.WaitForValueEqualTo (true, &timeout_time, &timed_out); - m_private_state_control_wait.SetValue (false, eBroadcastNever); - - if (signal == eBroadcastInternalStateControlStop) + HostThread private_state_thread(m_private_state_thread); + if (private_state_thread.IsJoinable()) { - if (timed_out) + if (log) + log->Printf ("Sending control event of type: %d.", signal); + // Send the control event and wait for the receipt or for the private state + // thread to exit + std::shared_ptr<EventDataReceipt> event_receipt_sp(new EventDataReceipt()); + m_private_state_control_broadcaster.BroadcastEvent(signal, event_receipt_sp); + + bool receipt_received = false; + while (!receipt_received) { - Error error = private_state_thread.Cancel(); - if (log) - log->Printf ("Timed out responding to the control event, cancel got error: \"%s\".", error.AsCString()); + bool timed_out = false; + TimeValue timeout_time; + timeout_time = TimeValue::Now(); + timeout_time.OffsetWithSeconds(2); + // Check for a receipt for 2 seconds and then check if the private state + // thread is still around. + receipt_received = event_receipt_sp->WaitForEventReceived (&timeout_time, &timed_out); + if (!receipt_received) + { + // Check if the private state thread is still around. If it isn't then we are done waiting + if (!m_private_state_thread.IsJoinable()) + break; // Private state thread exited, we are done + } } - else + + if (signal == eBroadcastInternalStateControlStop) { - if (log) - log->Printf ("The control event killed the private state thread without having to cancel."); + thread_result_t result = NULL; + private_state_thread.Join(&result); } - - thread_result_t result = NULL; - private_state_thread.Join(&result); - m_private_state_thread.Reset(); } - } - else - { - if (log) - log->Printf ("Private state thread already dead, no need to signal it to stop."); + else + { + if (log) + log->Printf ("Private state thread already dead, no need to signal it to stop."); + } } } @@ -4311,7 +4312,6 @@ thread_result_t Process::RunPrivateStateThread (bool is_secondary_thread) { bool control_only = true; - m_private_state_control_wait.SetValue (false, eBroadcastNever); Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); if (log) @@ -4346,7 +4346,6 @@ Process::RunPrivateStateThread (bool is_secondary_thread) break; } - m_private_state_control_wait.SetValue (true, eBroadcastAlways); continue; } else if (event_sp->GetType() == eBroadcastBitInterrupt) @@ -4442,7 +4441,6 @@ Process::RunPrivateStateThread (bool is_secondary_thread) // try to change it on the way out. if (!is_secondary_thread) m_public_run_lock.SetStopped(); - m_private_state_control_wait.SetValue (true, eBroadcastAlways); m_private_state_thread.Reset(); return NULL; } |