aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
diff options
context:
space:
mode:
authorMed Ismail Bennani <ismail@bennani.ma>2023-07-03 11:48:11 -0700
committerMed Ismail Bennani <ismail@bennani.ma>2023-07-03 11:49:11 -0700
commit9987646057d9748514662f96c869a5f87e463bc6 (patch)
tree0d513445bd3d22068cfd0557d70cd416bdc088a7 /lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
parentb709149b76277e8bea4a3d7977ccb4e818499b7b (diff)
downloadllvm-9987646057d9748514662f96c869a5f87e463bc6.zip
llvm-9987646057d9748514662f96c869a5f87e463bc6.tar.gz
llvm-9987646057d9748514662f96c869a5f87e463bc6.tar.bz2
[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>
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
index fe75f69..55ade49 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -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;
};