From cd468d954c49132c2dd19a765cb4479d09c1e227 Mon Sep 17 00:00:00 2001
From: Mirko Waechter <mirko.waechter@kit.edu>
Date: Wed, 13 Jan 2016 14:33:01 +0100
Subject: [PATCH] fixed tcp control unit crashes

---
 .../components/units/TCPControlUnit.cpp       | 31 ++++++++++---------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/source/RobotAPI/components/units/TCPControlUnit.cpp b/source/RobotAPI/components/units/TCPControlUnit.cpp
index 0ab4790e9..c9279c4ed 100644
--- a/source/RobotAPI/components/units/TCPControlUnit.cpp
+++ b/source/RobotAPI/components/units/TCPControlUnit.cpp
@@ -88,7 +88,7 @@ namespace armarx
             {
                 auto nodesets = localReportRobot->getRobotNodeSets();
 
-                for (RobotNodeSetPtr & set : nodesets)
+                for (RobotNodeSetPtr& set : nodesets)
                 {
                     if (set->getTCP())
                     {
@@ -104,7 +104,7 @@ namespace armarx
                              boost::is_any_of(","),
                              boost::token_compress_on);
 
-                for (auto & name : nodesetNames)
+                for (auto& name : nodesetNames)
                 {
                     auto node = localReportRobot->getRobotNode(name);
 
@@ -256,20 +256,20 @@ namespace armarx
 
     void TCPControlUnit::request(const Ice::Current& c)
     {
-        ARMARX_IMPORTANT << "Requesting TCPControlUnit";
-        ScopedLock lock(dataMutex);
-        requested = true;
-
         if (execTask)
         {
-            while (calculationRunning)
-            {
-                IceUtil::ThreadControl::yield();
-            }
+            //            while (calculationRunning)
+            //            {
+            //                IceUtil::ThreadControl::yield();
+            //            }
 
             execTask->stop();
         }
 
+        ARMARX_IMPORTANT << "Requesting TCPControlUnit";
+        ScopedLock lock(dataMutex);
+        requested = true;
+
         lastCommandTime = IceUtil::Time::now();
         execTask = new PeriodicTask<TCPControlUnit>(this, &TCPControlUnit::periodicExec, cycleTime, false, "TCPVelocityCalculator");
         execTask->start();
@@ -282,10 +282,10 @@ namespace armarx
         ARMARX_IMPORTANT << "Releasing TCPControlUnit";
         ScopedLock lock(dataMutex);
 
-        while (calculationRunning)
-        {
-            IceUtil::ThreadControl::yield();
-        }
+        //        while (calculationRunning)
+        //        {
+        //            IceUtil::ThreadControl::yield();
+        //        }
 
         tcpVelocitiesMap.clear();
         localTcpVelocitiesMap.clear();
@@ -304,8 +304,9 @@ namespace armarx
 
     void TCPControlUnit::periodicExec()
     {
+        ScopedTryLock lock(dataMutex);
+
         {
-            ScopedTryLock lock(dataMutex);
 
             if (lock.owns_lock())
             {
-- 
GitLab