# HG changeset patch
# User Edouard Tisserant
# Date 1316989444 -7200
# Node ID 7c23fac40a2a58e9c02a3566c5781a4f451ee788
# Parent  b9271faec96e796178dc192e12d2525603ed3d81
fixed debug with xenomai, fixed unprotected access to ___debug_tick

diff -r b9271faec96e -r 7c23fac40a2a targets/Linux/plc_Linux_main.c
--- a/targets/Linux/plc_Linux_main.c	Sun Sep 25 22:51:51 2011 +0200
+++ b/targets/Linux/plc_Linux_main.c	Mon Sep 26 00:24:04 2011 +0200
@@ -142,9 +142,11 @@
 
 int WaitDebugData(unsigned long *tick)
 {
+    int res;
+    /* Wait signal from PLC thread */
+    res = pthread_mutex_lock(&debug_wait_mutex);
     *tick = __debug_tick;
-    /* Wait signal from PLC thread */
-    return pthread_mutex_lock(&debug_wait_mutex);
+    return res;
 }
 
 /* Called by PLC thread when debug_publish finished
diff -r b9271faec96e -r 7c23fac40a2a targets/Xenomai/plc_Xenomai_main.c
--- a/targets/Xenomai/plc_Xenomai_main.c	Sun Sep 25 22:51:51 2011 +0200
+++ b/targets/Xenomai/plc_Xenomai_main.c	Mon Sep 26 00:24:04 2011 +0200
@@ -256,11 +256,12 @@
 {
     char cmd;
     int res;
-    *tick = __debug_tick;
     /* Wait signal from PLC thread */
     res = read(WaitDebug_pipe_fd, &cmd, sizeof(cmd));
-    if (res == sizeof(cmd) && cmd == DEBUG_PENDING_DATA)
+    if (res == sizeof(cmd) && cmd == DEBUG_PENDING_DATA){
+        *tick = __debug_tick;
         return 0;
+    }
     return -1;
 }
 
@@ -288,6 +289,8 @@
        }
     }
     __DEBUG = !disable;
+    if (disable)
+        AtomicCompareExchange( &debug_state, DEBUG_BUSY, DEBUG_FREE);
     return 0;
 }