Author: Augusto Noronha Date: 2023-08-22T11:14:04-07:00 New Revision: fef609d2d1da573150121a6ee897e1d90f235eb1
URL: https://github.com/llvm/llvm-project/commit/fef609d2d1da573150121a6ee897e1d90f235eb1 DIFF: https://github.com/llvm/llvm-project/commit/fef609d2d1da573150121a6ee897e1d90f235eb1.diff LOG: Revert "[lldb] Fix data race in ThreadList" This reverts commit bb90063249707e3ae081bfbd8e3512566abb7df6. Added: Modified: lldb/include/lldb/Target/Process.h lldb/include/lldb/Target/ThreadCollection.h lldb/include/lldb/Target/ThreadList.h lldb/source/Target/Process.cpp lldb/source/Target/ThreadList.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 8e75ed85229429..44cda6d2ce1aad 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -2970,6 +2970,7 @@ void PruneThreadPlans(); std::string m_exit_string; ///< A textual description of why a process exited. std::mutex m_exit_status_mutex; ///< Mutex so m_exit_status m_exit_string can ///be safely accessed from multiple threads + std::recursive_mutex m_thread_mutex; ThreadList m_thread_list_real; ///< The threads for this process as are known ///to the protocol we are debugging with ThreadList m_thread_list; ///< The threads for this process as the user will diff --git a/lldb/include/lldb/Target/ThreadCollection.h b/lldb/include/lldb/Target/ThreadCollection.h index dc7d8f13eee037..29f5103e7eec7c 100644 --- a/lldb/include/lldb/Target/ThreadCollection.h +++ b/lldb/include/lldb/Target/ThreadCollection.h @@ -47,7 +47,7 @@ class ThreadCollection { return ThreadIterable(m_threads, GetMutex()); } - std::recursive_mutex &GetMutex() const { return m_mutex; } + virtual std::recursive_mutex &GetMutex() const { return m_mutex; } protected: collection m_threads; diff --git a/lldb/include/lldb/Target/ThreadList.h b/lldb/include/lldb/Target/ThreadList.h index 8aaff6e4cba0d4..6af04f8ffc3767 100644 --- a/lldb/include/lldb/Target/ThreadList.h +++ b/lldb/include/lldb/Target/ThreadList.h @@ -133,6 +133,8 @@ class ThreadList : public ThreadCollection { void SetStopID(uint32_t stop_id); + std::recursive_mutex &GetMutex() const override; + void Update(ThreadList &rhs); protected: diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 57864a8a5da922..85ca0f6ab8d153 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -435,7 +435,7 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP listener_sp, Listener::MakeListener("lldb.process.internal_state_listener")), m_mod_id(), m_process_unique_id(0), m_thread_index_id(0), m_thread_id_to_index_id_map(), m_exit_status(-1), m_exit_string(), - m_exit_status_mutex(), m_thread_list_real(this), + m_exit_status_mutex(), m_thread_mutex(), m_thread_list_real(this), m_thread_list(this), m_thread_plans(*this), m_extended_thread_list(this), m_extended_thread_stop_id(0), m_queue_list(this), m_queue_list_stop_id(0), m_notifications(), m_image_tokens(), @@ -2455,7 +2455,7 @@ Process::WaitForProcessStopPrivate(EventSP &event_sp, } void Process::LoadOperatingSystemPlugin(bool flush) { - std::lock_guard<std::recursive_mutex> guard(GetThreadList().GetMutex()); + std::lock_guard<std::recursive_mutex> guard(m_thread_mutex); if (flush) m_thread_list.Clear(); m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr)); diff --git a/lldb/source/Target/ThreadList.cpp b/lldb/source/Target/ThreadList.cpp index fc6cbd48cf8653..1ba0c435b993d3 100644 --- a/lldb/source/Target/ThreadList.cpp +++ b/lldb/source/Target/ThreadList.cpp @@ -736,8 +736,7 @@ void ThreadList::Update(ThreadList &rhs) { if (this != &rhs) { // Lock both mutexes to make sure neither side changes anyone on us while // the assignment occurs - std::scoped_lock<std::recursive_mutex, std::recursive_mutex> guard( - GetMutex(), rhs.GetMutex()); + std::scoped_lock<std::recursive_mutex, std::recursive_mutex> guard(GetMutex(), rhs.GetMutex()); m_process = rhs.m_process; m_stop_id = rhs.m_stop_id; @@ -782,6 +781,10 @@ void ThreadList::Flush() { (*pos)->Flush(); } +std::recursive_mutex &ThreadList::GetMutex() const { + return m_process->m_thread_mutex; +} + ThreadList::ExpressionExecutionThreadPusher::ExpressionExecutionThreadPusher( lldb::ThreadSP thread_sp) : m_thread_list(nullptr), m_tid(LLDB_INVALID_THREAD_ID) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits