diff options
author | Mark Spruiell <mes@zeroc.com> | 2008-04-29 15:11:05 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2008-04-29 15:11:05 -0700 |
commit | 4719067208249b3239c57fd1dc5e9636926e20cb (patch) | |
tree | 7fb209361e6b91feb25b00a150edf60f2209b4ce /py/modules/IcePy/ObjectFactory.cpp | |
parent | Inserted missing entries (string converter, lenient vs string conversion, Ice... (diff) | |
download | ice-4719067208249b3239c57fd1dc5e9636926e20cb.tar.bz2 ice-4719067208249b3239c57fd1dc5e9636926e20cb.tar.xz ice-4719067208249b3239c57fd1dc5e9636926e20cb.zip |
fixing deadlock bug in Python
Diffstat (limited to 'py/modules/IcePy/ObjectFactory.cpp')
-rw-r--r-- | py/modules/IcePy/ObjectFactory.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/py/modules/IcePy/ObjectFactory.cpp b/py/modules/IcePy/ObjectFactory.cpp index 065a2c3c542..9f5043fc5ab 100644 --- a/py/modules/IcePy/ObjectFactory.cpp +++ b/py/modules/IcePy/ObjectFactory.cpp @@ -30,7 +30,20 @@ IcePy::ObjectFactory::~ObjectFactory() Ice::ObjectPtr IcePy::ObjectFactory::create(const string& id) { - Lock sync(*this); + PyObject* factory = 0; + + // + // Check if the application has registered a factory for this id. + // + { + Lock sync(*this); + + FactoryMap::iterator p = _factoryMap.find(id); + if(p != _factoryMap.end()) + { + factory = p->second; + } + } // // Get the type information. @@ -41,16 +54,12 @@ IcePy::ObjectFactory::create(const string& id) return 0; } - // - // Check if the application has registered a factory for this id. - // - FactoryMap::iterator p = _factoryMap.find(id); - if(p != _factoryMap.end()) + if(factory) { // // Invoke the create method on the Python factory object. // - PyObjectHandle obj = PyObject_CallMethod(p->second, STRCAST("create"), STRCAST("s"), id.c_str()); + PyObjectHandle obj = PyObject_CallMethod(factory, STRCAST("create"), STRCAST("s"), id.c_str()); if(!obj.get()) { throw AbortMarshaling(); @@ -87,7 +96,13 @@ IcePy::ObjectFactory::create(const string& id) void IcePy::ObjectFactory::destroy() { - Lock sync(*this); + FactoryMap factories; + + { + Lock sync(*this); + factories = _factoryMap; + _factoryMap.clear(); + } // // We release the GIL before calling communicator->destroy(), so we must @@ -95,7 +110,7 @@ IcePy::ObjectFactory::destroy() // AdoptThread adoptThread; - for(FactoryMap::iterator p = _factoryMap.begin(); p != _factoryMap.end(); ++p) + for(FactoryMap::iterator p = factories.begin(); p != factories.end(); ++p) { // // Invoke the destroy method on each registered Python factory. @@ -104,7 +119,6 @@ IcePy::ObjectFactory::destroy() PyErr_Clear(); Py_DECREF(p->second); } - _factoryMap.clear(); } bool |