Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cd14b9

Browse files
authored
Merge pull request swiftlang#7048 from medismailben/swift/release/5.9
[lldb] Fix data race when interacting with python scripts
2 parents 2ac8da0 + f0cbf4d commit 5cd14b9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,18 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
375375

376376
void LeaveSession();
377377

378-
uint32_t IsExecutingPython() const { return m_lock_count > 0; }
378+
uint32_t IsExecutingPython() {
379+
std::lock_guard<std::mutex> guard(m_mutex);
380+
return m_lock_count > 0;
381+
}
379382

380-
uint32_t IncrementLockCount() { return ++m_lock_count; }
383+
uint32_t IncrementLockCount() {
384+
std::lock_guard<std::mutex> guard(m_mutex);
385+
return ++m_lock_count;
386+
}
381387

382388
uint32_t DecrementLockCount() {
389+
std::lock_guard<std::mutex> guard(m_mutex);
383390
if (m_lock_count > 0)
384391
--m_lock_count;
385392
return m_lock_count;
@@ -419,6 +426,7 @@ class ScriptInterpreterPythonImpl : public ScriptInterpreterPython {
419426
bool m_pty_secondary_is_open;
420427
bool m_valid_session;
421428
uint32_t m_lock_count;
429+
std::mutex m_mutex;
422430
PyThreadState *m_command_thread_state;
423431
};
424432

lldb/source/Target/Process.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2609,6 +2609,7 @@ Process::WaitForProcessStopPrivate(EventSP &event_sp,
26092609
}
26102610

26112611
void Process::LoadOperatingSystemPlugin(bool flush) {
2612+
std::lock_guard<std::recursive_mutex> guard(m_thread_mutex);
26122613
if (flush)
26132614
m_thread_list.Clear();
26142615
m_os_up.reset(OperatingSystem::FindPlugin(this, nullptr));

0 commit comments

Comments
 (0)