diff options
author | Enrico Granata <egranata@apple.com> | 2013-03-27 22:38:11 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2013-03-27 22:38:11 +0000 |
commit | 360cc3188db5f5b65c7fcddba0b2e38fd3483d15 (patch) | |
tree | 818fcc83e29393c1c824d48b9977d7cbcdfc5e0d /lldb/source | |
parent | 459d3ee1ddea63b61f495fd8d5335ad0290990ed (diff) | |
download | bcm5719-llvm-360cc3188db5f5b65c7fcddba0b2e38fd3483d15.tar.gz bcm5719-llvm-360cc3188db5f5b65c7fcddba0b2e38fd3483d15.zip |
Implementing the notion of externally-acquirable ScriptInterpreter lock
With this notion, if parties outside the ScriptInterpreter itself need to acquire a lock on script APIs, they can do so by a pattern like this:
{
auto lock = interpeter->AcquireInterpreterLock();
// do whatever you need to do...
} // lock will automatically be released here
This might be useful for classes that use the Python convenience objects (e.g. PythonDictionary) to ensure they keep the underlying interpreter in a safe and controlled condition while they call through the C API functions
Of course, the ScriptInterpreter still manages its internal locking correctly when necessary :-)
llvm-svn: 178189
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreter.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 10 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreter.cpp b/lldb/source/Interpreter/ScriptInterpreter.cpp index 6bc6cd0d2ad..0e85902cff2 100644 --- a/lldb/source/Interpreter/ScriptInterpreter.cpp +++ b/lldb/source/Interpreter/ScriptInterpreter.cpp @@ -81,6 +81,12 @@ ScriptInterpreter::LanguageToString (lldb::ScriptLanguage language) return return_value; } +std::auto_ptr<ScriptInterpreterLocker> +ScriptInterpreter::AcquireInterpreterLock () +{ + return std::auto_ptr<ScriptInterpreterLocker>(new ScriptInterpreterLocker()); +} + void ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback) { diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 5a97107ac10..68e984c1e6b 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -135,6 +135,7 @@ ScriptInterpreterPython::Locker::Locker (ScriptInterpreterPython *py_interpreter uint16_t on_entry, uint16_t on_leave, FILE* wait_msg_handle) : + ScriptInterpreterLocker (), m_teardown_session( (on_leave & TearDownSession) == TearDownSession ), m_python_interpreter(py_interpreter), m_tmp_fh(wait_msg_handle) @@ -2806,6 +2807,15 @@ ScriptInterpreterPython::GetDocumentationForItem(const char* item, std::string& } } +std::auto_ptr<ScriptInterpreterLocker> +ScriptInterpreterPython::AcquireInterpreterLock () +{ + std::auto_ptr<ScriptInterpreterLocker> py_lock(new Locker(this, + Locker::AcquireLock | Locker::InitSession, + Locker::FreeLock | Locker::TearDownSession)); + return py_lock; +} + void ScriptInterpreterPython::InitializeInterpreter (SWIGInitCallback python_swig_init_callback) { |