From 573f2a8993f681e2941a1c2f1f7c6b08289ff125 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 25 Sep 2015 10:02:02 +0200 Subject: [PATCH] Deal with multi pyevaluator objects in containers + manage multi thread invokation. --- src/Container/Container_i.cxx | 94 ++++++++++++++++++++-------- src/Container/SALOME_Container_i.hxx | 6 +- 2 files changed, 72 insertions(+), 28 deletions(-) diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 0b8b19116..e18381210 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -254,10 +254,18 @@ Engines_Container_i::~Engines_Container_i() delete _id; if(_NS) delete _NS; - if(!CORBA::is_nil(_dftPyNode)) - _dftPyNode->UnRegister(); - if(!CORBA::is_nil(_dftPyScriptNode)) - _dftPyScriptNode->UnRegister(); + for(std::map::iterator it=_dftPyNode.begin();it!=_dftPyNode.end();it++) + { + Engines::PyNode_var tmpVar((*it).second); + if(!CORBA::is_nil(tmpVar)) + tmpVar->UnRegister(); + } + for(std::map::iterator it=_dftPyScriptNode.begin();it!=_dftPyScriptNode.end();it++) + { + Engines::PyScriptNode_var tmpVar((*it).second); + if(!CORBA::is_nil(tmpVar)) + tmpVar->UnRegister(); + } } //============================================================================= @@ -1679,16 +1687,25 @@ Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, cons std::string astr=PyString_AsString(result); Py_DECREF(res); PyGILState_Release(gstate); - if(ierr==0) { - CORBA::Object_var obj = _orb->string_to_object(astr.c_str()); - node = Engines::PyNode::_narrow(obj); - if(!CORBA::is_nil(_dftPyNode)) - _dftPyNode->UnRegister(); - _dftPyNode = node; - if(!CORBA::is_nil(_dftPyNode)) - _dftPyNode->Register(); + Utils_Locker lck(&_mutexForDftPy); + CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); + node=Engines::PyNode::_narrow(obj); + std::map::iterator it(_dftPyNode.find(nodeName)); + if(it==_dftPyNode.end()) + { + _dftPyNode[nodeName]=node; + } + else + { + Engines::PyNode_var oldNode((*it).second); + if(!CORBA::is_nil(oldNode)) + oldNode->UnRegister(); + (*it).second=node; + } + if(!CORBA::is_nil(node)) + node->Register(); return node._retn(); } else @@ -1698,7 +1715,6 @@ Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, cons es.text = astr.c_str(); throw SALOME::SALOME_Exception(es); } - } //============================================================================= @@ -1708,10 +1724,18 @@ Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, cons //============================================================================= Engines::PyNode_ptr Engines_Container_i::getDefaultPyNode(const char *nodeName) { - if(!CORBA::is_nil(_dftPyNode)) - return Engines::PyNode::_duplicate(_dftPyNode); - else + Utils_Locker lck(&_mutexForDftPy); + std::map::iterator it(_dftPyNode.find(nodeName)); + if(it==_dftPyNode.end()) return Engines::PyNode::_nil(); + else + { + Engines::PyNode_var tmpVar((*it).second); + if(!CORBA::is_nil(tmpVar)) + return Engines::PyNode::_duplicate(tmpVar); + else + return Engines::PyNode::_nil(); + } } //============================================================================= @@ -1749,13 +1773,23 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no if(ierr==0) { - CORBA::Object_var obj = _orb->string_to_object(astr.c_str()); - node = Engines::PyScriptNode::_narrow(obj); - if(!CORBA::is_nil(_dftPyScriptNode)) - _dftPyScriptNode->UnRegister(); - _dftPyScriptNode = node; - if(!CORBA::is_nil(_dftPyScriptNode)) - _dftPyScriptNode->Register(); + Utils_Locker lck(&_mutexForDftPy); + CORBA::Object_var obj=_orb->string_to_object(astr.c_str()); + node=Engines::PyScriptNode::_narrow(obj); + std::map::iterator it(_dftPyScriptNode.find(nodeName)); + if(it==_dftPyScriptNode.end()) + { + _dftPyScriptNode[nodeName]=node; + } + else + { + Engines::PyScriptNode_var oldNode((*it).second); + if(!CORBA::is_nil(oldNode)) + oldNode->UnRegister(); + (*it).second=node; + } + if(!CORBA::is_nil(node)) + node->Register(); return node._retn(); } else @@ -1774,10 +1808,18 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no //============================================================================= Engines::PyScriptNode_ptr Engines_Container_i::getDefaultPyScriptNode(const char *nodeName) { - if(!CORBA::is_nil(_dftPyScriptNode)) - return Engines::PyScriptNode::_duplicate(_dftPyScriptNode); - else + Utils_Locker lck(&_mutexForDftPy); + std::map::iterator it(_dftPyScriptNode.find(nodeName)); + if(it==_dftPyScriptNode.end()) return Engines::PyScriptNode::_nil(); + else + { + Engines::PyScriptNode_var tmpVar((*it).second); + if(!CORBA::is_nil(tmpVar)) + return Engines::PyScriptNode::_duplicate(tmpVar); + else + return Engines::PyScriptNode::_nil(); + } } //============================================================================= diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 83d8f4fe9..9a49dd04d 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -30,6 +30,7 @@ #define _SALOME_CONTAINER_I_HXX_ #include "SALOME_Container.hxx" +#include "Utils_Mutex.hxx" #include #include CORBA_SERVER_HEADER(SALOME_Component) @@ -161,8 +162,9 @@ protected: std::map _listInstances_map; std::map _fileRef_map; std::map _Salome_file_map; - Engines::PyScriptNode_var _dftPyScriptNode; - Engines::PyNode_var _dftPyNode; + std::map _dftPyScriptNode; + std::map _dftPyNode; + Utils_Mutex _mutexForDftPy; std::list _tmp_files; Engines::fileTransfer_var _fileTransfer; -- 2.39.2