[Lldb-commits] [lldb] r178189 - Implementing the notion of externally-acquirable ScriptInterpreter lock
Enrico Granata
egranata at apple.com
Wed Mar 27 15:38:11 PDT 2013
Author: enrico
Date: Wed Mar 27 17:38:11 2013
New Revision: 178189
URL: http://llvm.org/viewvc/llvm-project?rev=178189&view=rev
Log:
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 :-)
Modified:
lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
lldb/trunk/include/lldb/lldb-forward.h
lldb/trunk/source/Interpreter/ScriptInterpreter.cpp
lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=178189&r1=178188&r2=178189&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Wed Mar 27 17:38:11 2013
@@ -61,6 +61,22 @@ public:
protected:
void* m_object;
};
+
+class ScriptInterpreterLocker
+{
+public:
+
+ ScriptInterpreterLocker ()
+ {
+ }
+
+ virtual ~ScriptInterpreterLocker ()
+ {
+ }
+private:
+ DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterLocker);
+};
+
class ScriptInterpreter
{
@@ -409,6 +425,9 @@ public:
return lldb::ScriptInterpreterObjectSP(new ScriptInterpreterObject(object));
}
+ virtual std::auto_ptr<ScriptInterpreterLocker>
+ AcquireInterpreterLock ();
+
const char *
GetScriptInterpreterPtyName ();
Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=178189&r1=178188&r2=178189&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Wed Mar 27 17:38:11 2013
@@ -181,6 +181,9 @@ public:
virtual lldb::ScriptInterpreterObjectSP
MakeScriptObject (void* object);
+ virtual std::auto_ptr<ScriptInterpreterLocker>
+ AcquireInterpreterLock ();
+
void
CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
CommandReturnObject &result);
@@ -271,7 +274,7 @@ private:
DISALLOW_COPY_AND_ASSIGN (ScriptInterpreterPythonObject);
};
- class Locker
+ class Locker : public ScriptInterpreterLocker
{
public:
Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=178189&r1=178188&r2=178189&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Wed Mar 27 17:38:11 2013
@@ -178,6 +178,7 @@ class RegisterValue;
class RegularExpression;
class Scalar;
class ScriptInterpreter;
+class ScriptInterpreterLocker;
class ScriptInterpreterObject;
#ifndef LLDB_DISABLE_PYTHON
class ScriptInterpreterPython;
Modified: lldb/trunk/source/Interpreter/ScriptInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreter.cpp?rev=178189&r1=178188&r2=178189&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreter.cpp Wed Mar 27 17:38:11 2013
@@ -81,6 +81,12 @@ ScriptInterpreter::LanguageToString (lld
return return_value;
}
+std::auto_ptr<ScriptInterpreterLocker>
+ScriptInterpreter::AcquireInterpreterLock ()
+{
+ return std::auto_ptr<ScriptInterpreterLocker>(new ScriptInterpreterLocker());
+}
+
void
ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback)
{
Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=178189&r1=178188&r2=178189&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Wed Mar 27 17:38:11 2013
@@ -135,6 +135,7 @@ ScriptInterpreterPython::Locker::Locker
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::GetDocumentatio
}
}
+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)
{
More information about the lldb-commits
mailing list