From fcede046a8bac4b0698f3f09376fedac47ccd528 Mon Sep 17 00:00:00 2001 From: Nikolaus Vahrenkamp <vahrenkamp@kit.edu> Date: Thu, 4 Sep 2014 10:07:53 +0200 Subject: [PATCH] Added mutex to avoid crash on concurrent robot cloning --- source/RobotAPI/robotstate/SharedRobotServants.cpp | 4 ++++ source/RobotAPI/robotstate/SharedRobotServants.h | 1 + source/RobotAPI/robotstate/remote/RemoteRobot.cpp | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/RobotAPI/robotstate/SharedRobotServants.cpp b/source/RobotAPI/robotstate/SharedRobotServants.cpp index fe78f4a15..a87910fe6 100644 --- a/source/RobotAPI/robotstate/SharedRobotServants.cpp +++ b/source/RobotAPI/robotstate/SharedRobotServants.cpp @@ -236,6 +236,8 @@ SharedRobotServant::~SharedRobotServant() #ifdef VERBOSE ARMARX_WARNING_S << "destruct " << this << flush; #endif + boost::recursive_mutex::scoped_lock cloneLock(m); + BOOST_FOREACH(NodeCache::value_type value, this->_cachedNodes) value.second->unref(); } @@ -244,6 +246,7 @@ SharedRobotNodeInterfacePrx SharedRobotServant::getRobotNode(const string &name, { // ARMARX_LOG_S << "Looking for node: " << name << flush; assert(_robot); + boost::recursive_mutex::scoped_lock cloneLock(m); if (this->_cachedNodes.find(name) == this->_cachedNodes.end()){ RobotNodePtr robotNode = _robot->getRobotNode(name); @@ -264,6 +267,7 @@ SharedRobotNodeInterfacePrx SharedRobotServant::getRobotNode(const string &name, SharedRobotNodeInterfacePrx SharedRobotServant::getRootNode(const Current ¤t) { assert(_robot); + boost::recursive_mutex::scoped_lock cloneLock(m); string name = _robot->getRootNode()/*,current*/->getName(); return this->getRobotNode(name, current); } diff --git a/source/RobotAPI/robotstate/SharedRobotServants.h b/source/RobotAPI/robotstate/SharedRobotServants.h index e52797cd9..735682fbb 100644 --- a/source/RobotAPI/robotstate/SharedRobotServants.h +++ b/source/RobotAPI/robotstate/SharedRobotServants.h @@ -118,6 +118,7 @@ namespace armarx { protected: VirtualRobot::RobotPtr _robot; + boost::recursive_mutex m; std::map<std::string, SharedRobotNodeInterfacePrx> _cachedNodes; }; } diff --git a/source/RobotAPI/robotstate/remote/RemoteRobot.cpp b/source/RobotAPI/robotstate/remote/RemoteRobot.cpp index dc2be4c3c..b8d771e7e 100644 --- a/source/RobotAPI/robotstate/remote/RemoteRobot.cpp +++ b/source/RobotAPI/robotstate/remote/RemoteRobot.cpp @@ -63,7 +63,7 @@ bool RemoteRobot::hasRobotNode( RobotNodePtr robotNode ) return this->hasRobotNode(robotNode->getName()); /* - * This just does nost work. because you cannot tell wheter RemoteRobotNode<RobotNodeRevolute> or another type is used + * This just does not work. because you cannot tell wheter RemoteRobotNode<RobotNodeRevolute> or another type is used * perhaps you can infer the actual RobotNodeType somehow. Until now we just check for names which is * much faster! * @@ -255,6 +255,7 @@ VirtualRobot::RobotNodePtr RemoteRobot::createLocalNode(SharedRobotNodeInterface VirtualRobot::RobotPtr RemoteRobot::createLocalClone() { + //ARMARX_IMPORTANT_S << "RemoteRobot local clone" << flush; boost::recursive_mutex::scoped_lock cloneLock(m); std::string robotType = getName(); std::string robotName = getName(); @@ -263,7 +264,6 @@ VirtualRobot::RobotPtr RemoteRobot::createLocalClone() //RobotNodePtr SharedRobotNodeInterfacePrx root = _robot->getRootNode(); - std::vector<VirtualRobot::RobotNodePtr> allNodes; std::map< VirtualRobot::RobotNodePtr, std::vector<std::string> > childrenMap; @@ -276,13 +276,14 @@ VirtualRobot::RobotPtr RemoteRobot::createLocalClone() return VirtualRobot::RobotPtr(); } - // clone rns + // clone rns std::vector<std::string> rns = _robot->getRobotNodeSets(); for (size_t i=0;i<rns.size();i++) { RobotNodeSetInfoPtr rnsInfo = _robot->getRobotNodeSet(rns[i]); RobotNodeSet::createRobotNodeSet(robo,rnsInfo->name,rnsInfo->names,rnsInfo->rootName,rnsInfo->tcpName,true); } + //ARMARX_IMPORTANT_S << "RemoteRobot local clone end" << flush; return robo; } -- GitLab