@@ -48,6 +48,8 @@ Localization2D_nws_yarp::Localization2D_nws_yarp() : PeriodicThread(DEFAULT_THRE
48
48
49
49
bool Localization2D_nws_yarp::attach (PolyDriver* driver)
50
50
{
51
+ std::lock_guard<std::mutex> lock (m_mutex);
52
+
51
53
if (driver->isValid ())
52
54
{
53
55
driver->view (iLoc);
@@ -83,15 +85,17 @@ bool Localization2D_nws_yarp::attach(PolyDriver* driver)
83
85
return false ;
84
86
}
85
87
86
- PeriodicThread:: setPeriod (m_GENERAL_period);
87
- return PeriodicThread:: start ();
88
+ this -> setPeriod (m_GENERAL_period);
89
+ return this -> start ();
88
90
}
89
91
90
92
bool Localization2D_nws_yarp::detach ()
91
93
{
92
- if (PeriodicThread::isRunning ())
94
+ std::lock_guard<std::mutex> lock (m_mutex);
95
+
96
+ if (this ->isRunning ())
93
97
{
94
- PeriodicThread:: stop ();
98
+ this -> stop ();
95
99
}
96
100
m_rpcPort.interrupt ();
97
101
m_rpcPort.close ();
@@ -186,8 +190,11 @@ bool Localization2D_nws_yarp::close()
186
190
187
191
bool Localization2D_nws_yarp::read (yarp::os::ConnectionReader& connection)
188
192
{
193
+ if (!connection.isValid ()) { return false ;}
189
194
if (!m_RPC) { return false ;}
190
195
196
+ std::lock_guard<std::mutex> lock (m_mutex);
197
+
191
198
bool b = m_RPC->read (connection);
192
199
if (b)
193
200
{
@@ -202,6 +209,8 @@ bool Localization2D_nws_yarp::read(yarp::os::ConnectionReader& connection)
202
209
203
210
void Localization2D_nws_yarp::run ()
204
211
{
212
+ std::lock_guard<std::mutex> lock (m_mutex);
213
+
205
214
double m_stats_time_curr = yarp::os::Time::now ();
206
215
if (m_stats_time_curr - m_stats_time_last > 5.0 )
207
216
{
0 commit comments