diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-05 23:30:31 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-05 23:30:31 +0000 |
commit | c298b01922ab03d078f33ec1ceb3e7471277f48c (patch) | |
tree | fbeebb3c73b23b841ebe3d1be9cab397e80bf0fd /sca-cpp/trunk/modules/python/mod-python.cpp | |
parent | 31ed46ac8dab9abaee7c74b8d8fb53bde49a317e (diff) |
Support multithreaded execution of Python components with the HTTPD event MPM.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1165452 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/python/mod-python.cpp')
-rw-r--r-- | sca-cpp/trunk/modules/python/mod-python.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/sca-cpp/trunk/modules/python/mod-python.cpp b/sca-cpp/trunk/modules/python/mod-python.cpp index 8561a1fbf4..24e0b3bcb0 100644 --- a/sca-cpp/trunk/modules/python/mod-python.cpp +++ b/sca-cpp/trunk/modules/python/mod-python.cpp @@ -39,23 +39,37 @@ namespace modeval { /** * Apply a lifecycle start or restart event. */ +struct pythonLifecycle { + python::PythonRuntime& py; + pythonLifecycle(python::PythonRuntime& py) : py(py) { + } + const value operator()(const list<value>& params) const { + const value func = car(params); + if (func == "pythonRuntime") + return (gc_ptr<value>)(value*)(void*)&py; + return lambda<value(const list<value>&)>(); + } +}; + const value applyLifecycle(unused const list<value>& params) { // Create a Python runtime - new (gc_new<python::PythonRuntime>()) python::PythonRuntime(); + python::PythonRuntime& py = *(new (gc_new<python::PythonRuntime>()) python::PythonRuntime()); - // Return a nil function as we don't need to handle the stop event - return failable<value>(lambda<value(const list<value>&)>()); + // Return the function to invoke on subsequent events + return failable<value>(lambda<value(const list<value>&)>(pythonLifecycle(py))); } /** * Evaluate a Python component implementation and convert it to an applicable * lambda function. */ -const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, unused const lambda<value(const list<value>&)>& lifecycle) { +const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, const lambda<value(const list<value>&)>& lifecycle) { const string itype(elementName(impl)); - if (contains(itype, ".python")) - return modpython::evalImplementation(path, impl, px); + if (contains(itype, ".python")) { + const void* p = (gc_ptr<value>)lifecycle(mklist<value>("pythonRuntime")); + return modpython::evalImplementation(path, impl, px, *(python::PythonRuntime*)p); + } if (contains(itype, ".cpp")) return modcpp::evalImplementation(path, impl, px); return mkfailure<lambda<value(const list<value>&)> >(string("Unsupported implementation type: ") + itype); |