[chronojump] execute run capture/gtk threads more robust



commit 6eca238d19abdd484fc3b49d4afd3ec8f4005def
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Mar 27 18:21:12 2018 +0200

    execute run capture/gtk threads more robust

 .../photocells-double-contact-workflow.dia         |  Bin 9168 -> 9644 bytes
 .../photocells-double-contact-workflow.png         |  Bin 182431 -> 197711 bytes
 src/execute/event.cs                               |    6 +++
 src/execute/run.cs                                 |    9 ++++
 src/execute/runObjects.cs                          |   41 ++++++++++++++++++--
 5 files changed, 52 insertions(+), 4 deletions(-)
---
diff --git a/diagrams/processes/photocells-double-contact-workflow.dia 
b/diagrams/processes/photocells-double-contact-workflow.dia
index f710fad..a254eca 100644
Binary files a/diagrams/processes/photocells-double-contact-workflow.dia and 
b/diagrams/processes/photocells-double-contact-workflow.dia differ
diff --git a/diagrams/processes/photocells-double-contact-workflow.png 
b/diagrams/processes/photocells-double-contact-workflow.png
index b545a7e..e9dc8d7 100644
Binary files a/diagrams/processes/photocells-double-contact-workflow.png and 
b/diagrams/processes/photocells-double-contact-workflow.png differ
diff --git a/src/execute/event.cs b/src/execute/event.cs
index cfd3874..96a9bd1 100644
--- a/src/execute/event.cs
+++ b/src/execute/event.cs
@@ -319,6 +319,8 @@ public class EventExecute
 
                // races specific --------------------------------->
 
+               updateRunPhaseInfoManage();
+
                //Race track with DoubleContacts mode NONE
                if(needCallTrackDone)
                {
@@ -368,6 +370,10 @@ public class EventExecute
                return true;
        }
 
+       protected virtual void updateRunPhaseInfoManage()
+       {
+       }
+
        protected virtual void trackDone()
        {
        }
diff --git a/src/execute/run.cs b/src/execute/run.cs
index 913e4e9..905b34a 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -864,6 +864,11 @@ public class RunIntervalExecute : RunExecute
                return false;
        }
 
+       protected override void updateRunPhaseInfoManage()
+       {
+               runDC.UpdateList();
+       }
+
        //this will be protected and in run simple execute class
        //big change in 1.8.1: this will be called from GTK thread
        //so don't write to SQL here
@@ -878,6 +883,10 @@ public class RunIntervalExecute : RunExecute
                        myTrackTime = lastTc + lastTf/1000.0;
                }
 
+               //solve possible problems of bad copied data between threads on start
+               if(myTrackTime == 0)
+                       return;
+
                //runEI.ChangePhase(RunExecuteInspector.Phases.IN, runEIString +
                runEI.ChangePhase(RunExecuteInspector.Phases.IN, //runEIString +
                                string.Format("; timestamp: {0}; <b>trackTime: {1}</b>",
diff --git a/src/execute/runObjects.cs b/src/execute/runObjects.cs
index b4e80a0..a30a017 100644
--- a/src/execute/runObjects.cs
+++ b/src/execute/runObjects.cs
@@ -68,11 +68,19 @@ public class RunPhaseInfoManage
                list = new List<RunPhaseInfo>();
                startPos = 0;
        }
-               
+
+       /*
        public void Add (RunPhaseInfo rpi)
        {
                list.Add(rpi);
        }
+       */
+
+       public void UpdateListUsing (List<RunPhaseInfo> listCaptureThread)
+       {
+               for(int i = list.Count; i < listCaptureThread.Count ; i ++)
+                       list.Add(listCaptureThread[i]);
+       }
 
        public int GetPosOfBiggestTC ()
        {
@@ -137,7 +145,7 @@ public class RunPhaseInfoManage
                else
                        startPos = bigTCPosition;
        }
-                       
+
        public string PrintList()
        {
                string str = "\n";
@@ -181,6 +189,8 @@ public class RunDoubleContact
        
        private double timeAcumulated;
 
+       private List<RunPhaseInfo> listCaptureThread; //this list contains TCs and TFs from capture thread
+
        //constructor ------------------------------------------
        public RunDoubleContact (Constants.DoubleContact mode, int checkTime)
        {
@@ -190,10 +200,15 @@ public class RunDoubleContact
                lastTc = 0;
                timeAcumulated = 0;
                rpim = new RunPhaseInfoManage();
+               listCaptureThread = new List<RunPhaseInfo>();
        }
 
        //public methods ---------------------------------------
 
+       /*
+        * ---------------------- start of called by capture thread -------------->
+        */
+
        public bool UseDoubleContacts ()
        {
                return (mode != Constants.DoubleContact.NONE);
@@ -202,7 +217,7 @@ public class RunDoubleContact
        public void DoneTC (double timestamp)
        {
                lastTc = timestamp;
-               rpim.Add(new RunPhaseInfo(RunPhaseInfo.Types.CONTACT, timeAcumulated, timestamp));
+               listCaptureThread.Add(new RunPhaseInfo(RunPhaseInfo.Types.CONTACT, timeAcumulated, 
timestamp));
                timeAcumulated += timestamp;
                LogB.Information(string.Format("DoneTC -> lastTc: {0}", lastTc));
        }
@@ -213,10 +228,24 @@ public class RunDoubleContact
                                        "lastTc + timestamp <= checkTime ?, lastTc: {0}; timestamp: {1}; 
checkTime: {2}",
                                        lastTc, timestamp, checkTime));
 
-               rpim.Add(new RunPhaseInfo(RunPhaseInfo.Types.FLIGHT, timeAcumulated, timestamp));
+               listCaptureThread.Add(new RunPhaseInfo(RunPhaseInfo.Types.FLIGHT, timeAcumulated, timestamp));
                timeAcumulated += timestamp;
        }
 
+       /*
+        * <---------------------- end of called by capture thread --------------
+        */
+
+       /*
+        * ---------------------- start of called by GTK thread ---------------->
+        */
+
+       //Copies from listWill to list
+       public void UpdateList()
+       {
+               rpim.UpdateListUsing (listCaptureThread);
+       }
+
        //this wait will be done by C#
        public double GetTrackTimeInSecondsAndUpdateStartPos()
        {
@@ -239,6 +268,10 @@ public class RunDoubleContact
                return trackTime;
        }
 
+       /*
+        * <---------------------- end of called by GTK thread --------------
+        */
+
        //private methods --------------------------------------
        
        private double getDCBiggestTC()


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