[chronojump] Better init cancel/finish variables to avoid problems with 2 chronopics



commit 3c4cc19be766b204bd00298c1c02680c385fda93
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jan 4 17:54:54 2017 +0100

    Better init cancel/finish variables to avoid problems with 2 chronopics

 src/chronopic.cs              |   16 ++++++++++++++--
 src/execute/jump.cs           |   10 +++++++++-
 src/execute/multiChronopic.cs |    4 ++++
 src/execute/pulse.cs          |    4 ++++
 src/execute/reactionTime.cs   |    4 ++++
 src/execute/run.cs            |    8 ++++++++
 6 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/src/chronopic.cs b/src/chronopic.cs
index a17ec47..d28a1e4 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -306,8 +306,6 @@ public class Chronopic {
                //-- esperados para la trama. (En el caso de id son 4). Si hay un 
                //-- timeout se aborta
                count=0;
-               cancellingTest = false;
-               finishingTest = false;
                do {
                        //try, catch done because mono-1.2.3 throws an exception when there's a timeout
                        //http://bugzilla.gnome.org/show_bug.cgi?id=420520
@@ -373,6 +371,20 @@ public class Chronopic {
                finishingTest = true;
        }
 
+       /*
+          on <= 1.6.2 we could have this problem with static variables:
+          on thread 1 finishingTest is marked as true
+          just at the moment on thread 2 read_event is called and read_cambio is called and finishingTest = 
false
+          so thread 2 does not end
+          solution is to not define finishingTest on read_cambio
+          define it on the beginning and will affect both chronopics
+          */
+       public static void InitCancelAndFinish()
+       {
+               cancellingTest = false;
+               finishingTest = false;
+       }
+
        //-- Vaciar buffer de entrada
        //-- De momento se hace leyendo muchos datos y descartando
        private void flush()
diff --git a/src/execute/jump.cs b/src/execute/jump.cs
index 135f3b1..86070da 100644
--- a/src/execute/jump.cs
+++ b/src/execute/jump.cs
@@ -273,7 +273,11 @@ public class JumpExecute : EventExecute
                
                bool ok;
                int phase = 0;
-               
+
+               //prepare variables to allow being cancelled or finished
+               if(! simulated)
+                       Chronopic.InitCancelAndFinish();
+
                do {
                        if(simulated)
                                ok = true;
@@ -698,6 +702,10 @@ public class JumpRjExecute : JumpExecute
 
                int countForSavingTempTable = 0;
        
+               //prepare variables to allow being cancelled or finished
+               if(! simulated)
+                       Chronopic.InitCancelAndFinish();
+
                do {
                        if(simulated) 
                                ok = true;
diff --git a/src/execute/multiChronopic.cs b/src/execute/multiChronopic.cs
index 3e0eed4..babc401 100644
--- a/src/execute/multiChronopic.cs
+++ b/src/execute/multiChronopic.cs
@@ -317,6 +317,10 @@ public class MultiChronopicExecute : EventExecute
 
                        //start thread
                        if(chronopics > 0) {
+                               //prepare variables to allow being cancelled or finished
+                               if(! simulated)
+                                       Chronopic.InitCancelAndFinish();
+
                                thread = new Thread(new ThreadStart(waitEventPre));
                                if(chronopics > 1) {
                                        thread2 = new Thread(new ThreadStart(waitEventPre2));
diff --git a/src/execute/pulse.cs b/src/execute/pulse.cs
index 4d9745a..9ac118a 100644
--- a/src/execute/pulse.cs
+++ b/src/execute/pulse.cs
@@ -187,6 +187,10 @@ public class PulseExecute : EventExecute
 
                        bool ok;
 
+                       //prepare variables to allow being cancelled or finished
+                       if(! simulated)
+                               Chronopic.InitCancelAndFinish();
+
                        do {
                                if(simulated) 
                                        ok = true;
diff --git a/src/execute/reactionTime.cs b/src/execute/reactionTime.cs
index bdfae62..bed08d6 100644
--- a/src/execute/reactionTime.cs
+++ b/src/execute/reactionTime.cs
@@ -178,6 +178,10 @@ public class ReactionTimeExecute : EventExecute
                
                bool ok;
        
+               //prepare variables to allow being cancelled or finished
+               if(! simulated)
+                       Chronopic.InitCancelAndFinish();
+
                LogB.Information("Inside waitEvent");   
                do {
                        if(simulated)
diff --git a/src/execute/run.cs b/src/execute/run.cs
index b236434..d8365e6 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -192,6 +192,10 @@ public class RunExecute : EventExecute
                bool success = false;
                bool ok;
 
+               //prepare variables to allow being cancelled or finished
+               if(! simulated)
+                       Chronopic.InitCancelAndFinish();
+
                do {
                        if(simulated)
                                ok = true;
@@ -546,6 +550,10 @@ public class RunIntervalExecute : RunExecute
                double timestampDCContactTimes = -1;//sum of the contact times that happen in small time
                double timestampDCn = 0; //number of flight times
                
+               //prepare variables to allow being cancelled or finished
+               if(! simulated)
+                       Chronopic.InitCancelAndFinish();
+
                do {
                        if(simulated) 
                                ok = true;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]