mirror of
https://github.com/intel/llvm.git
synced 2026-01-23 07:58:23 +08:00
[lldb] Fix data race when interacting with python scripts
This patch should fix some data races when a python script (i.e. a Scripted Process) has a nested call to another python script (i.e. a OperatingSystem Plugin), which can cause concurrent writes to the python lock count. This patch also fixes a data race happening when resetting the operating system unique pointer. To address these issues, both accesses is guarded by a mutex. rdar://109413039 Differential Revision: https://reviews.llvm.org/D154271 Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
This commit is contained in:
@@ -378,11 +378,18 @@ public:
|
||||
|
||||
void LeaveSession();
|
||||
|
||||
uint32_t IsExecutingPython() const { return m_lock_count > 0; }
|
||||
uint32_t IsExecutingPython() {
|
||||
std::lock_guard<std::mutex> guard(m_mutex);
|
||||
return m_lock_count > 0;
|
||||
}
|
||||
|
||||
uint32_t IncrementLockCount() { return ++m_lock_count; }
|
||||
uint32_t IncrementLockCount() {
|
||||
std::lock_guard<std::mutex> guard(m_mutex);
|
||||
return ++m_lock_count;
|
||||
}
|
||||
|
||||
uint32_t DecrementLockCount() {
|
||||
std::lock_guard<std::mutex> guard(m_mutex);
|
||||
if (m_lock_count > 0)
|
||||
--m_lock_count;
|
||||
return m_lock_count;
|
||||
@@ -422,6 +429,7 @@ public:
|
||||
bool m_pty_secondary_is_open;
|
||||
bool m_valid_session;
|
||||
uint32_t m_lock_count;
|
||||
std::mutex m_mutex;
|
||||
PyThreadState *m_command_thread_state;
|
||||
};
|
||||
|
||||
|
||||
@@ -2467,6 +2467,7 @@ Process::WaitForProcessStopPrivate(EventSP &event_sp,
|
||||
}
|
||||
|
||||
void Process::LoadOperatingSystemPlugin(bool flush) {
|
||||
std::lock_guard<std::recursive_mutex> guard(m_thread_mutex);
|
||||
if (flush)
|
||||
m_thread_list.Clear();
|
||||
m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr));
|
||||
|
||||
Reference in New Issue
Block a user