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
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user