Skip to content
Snippets Groups Projects
Commit f4aa3aec authored by Francois Keith's avatar Francois Keith
Browse files

Correct rosPublish.rm method.

Deregister the signal formerly added.
Add a mutex system to prevent removing a signal while triggering it,
 to avoid a crash (especially if the topic was listened to).
parent 625c1c79
No related branches found
No related tags found
No related merge requests found
...@@ -203,7 +203,14 @@ namespace dynamicgraph ...@@ -203,7 +203,14 @@ namespace dynamicgraph
void RosPublish::rm (const std::string& signal) void RosPublish::rm (const std::string& signal)
{ {
if(bindedSignal_.find(signal) == bindedSignal_.end())
return;
//lock the mutex to avoid deleting the signal during a call to trigger
while(! mutex_.try_lock() ){}
bindedSignal_.erase (signal); bindedSignal_.erase (signal);
signalDeregistration(signal);
mutex_.unlock();
} }
std::string RosPublish::list () const std::string RosPublish::list () const
...@@ -230,11 +237,13 @@ namespace dynamicgraph ...@@ -230,11 +237,13 @@ namespace dynamicgraph
if (dt < rate_) if (dt < rate_)
return dummy; return dummy;
while(! mutex_.try_lock() ){}
for (iterator_t it = bindedSignal_.begin (); for (iterator_t it = bindedSignal_.begin ();
it != bindedSignal_.end (); ++it) it != bindedSignal_.end (); ++it)
{ {
boost::get<1>(it->second) (t); boost::get<1>(it->second) (t);
} }
mutex_.unlock();
return dummy; return dummy;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# include <boost/shared_ptr.hpp> # include <boost/shared_ptr.hpp>
# include <boost/tuple/tuple.hpp> # include <boost/tuple/tuple.hpp>
# include <boost/interprocess/sync/interprocess_mutex.hpp>
# include <dynamic-graph/entity.h> # include <dynamic-graph/entity.h>
# include <dynamic-graph/signal-time-dependent.h> # include <dynamic-graph/signal-time-dependent.h>
...@@ -94,6 +95,7 @@ namespace dynamicgraph ...@@ -94,6 +95,7 @@ namespace dynamicgraph
dynamicgraph::SignalTimeDependent<int,int> trigger_; dynamicgraph::SignalTimeDependent<int,int> trigger_;
ros::Duration rate_; ros::Duration rate_;
ros::Time lastPublicated_; ros::Time lastPublicated_;
boost::interprocess::interprocess_mutex mutex_;
}; };
} // end of namespace dynamicgraph. } // end of namespace dynamicgraph.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment