More robust retain buffer validity management
authoredouard
Wed, 16 Mar 2011 17:26:54 +0100
changeset 580 9dd978e6537c
parent 579 554ba6df4ee0
child 581 57605e8e89f0
More robust retain buffer validity management
targets/LPC/plc_LPC_main.c
targets/Linux/plc_Linux_main.c
targets/Win32/plc_Win32_main.c
targets/plc_debug.c
--- a/targets/LPC/plc_LPC_main.c	Thu Feb 24 15:54:45 2011 +0100
+++ b/targets/LPC/plc_LPC_main.c	Wed Mar 16 17:26:54 2011 +0100
@@ -48,7 +48,6 @@
 {
 	if(__init(argc,argv) == 0){
         /* sign retain buffer */
-        memcpy(RetainedIdBuf, idBuf, idLen);
 		PLC_SetTimer(0, common_ticktime__);
 		return 0;
 	}else{
@@ -112,15 +111,23 @@
     debug_locked = 0;
 }
 
+void ValidateRetainBuffer(void)
+{
+        memcpy(RetainedIdBuf, idBuf, idLen);
+}
+
+void InValidateRetainBuffer(void)
+{
+    /* invalidate that buffer */
+    RetainedIdBuf[0] = 0;
+}
+
 int CheckRetainBuffer(void)
 {
 	/* compare RETAIN ID buffer with MD5 */
     /* return true if identical */
     int res = memcmp(RetainedIdBuf, idBuf, idLen) == 0;
-    /* invalidate that buffer, might help when value cause PLC crash before next publish */
-    RetainedIdBuf[0] = 0;
     return res;
-
 }
 
 void Retain(unsigned int offset, unsigned int count, void *p)
--- a/targets/Linux/plc_Linux_main.c	Thu Feb 24 15:54:45 2011 +0100
+++ b/targets/Linux/plc_Linux_main.c	Wed Mar 16 17:26:54 2011 +0100
@@ -206,6 +206,14 @@
 	return 1;
 }
 
+void ValidateRetainBuffer(void)
+{
+}
+
+void InValidateRetainBuffer(void)
+{
+}
+
 void Retain(unsigned int offset, unsigned int count, void *p)
 {
 }
--- a/targets/Win32/plc_Win32_main.c	Thu Feb 24 15:54:45 2011 +0100
+++ b/targets/Win32/plc_Win32_main.c	Wed Mar 16 17:26:54 2011 +0100
@@ -234,6 +234,14 @@
 	return 1;
 }
 
+void ValidateRetainBuffer(void)
+{
+}
+
+void InValidateRetainBuffer(void)
+{
+}
+
 void Retain(unsigned int offset, unsigned int count, void * p)
 {
     unsigned int position;
--- a/targets/plc_debug.c	Thu Feb 24 15:54:45 2011 +0100
+++ b/targets/plc_debug.c	Wed Mar 16 17:26:54 2011 +0100
@@ -101,7 +101,7 @@
     }
 }
 
-int CheckRetainBuffer(void);
+extern int CheckRetainBuffer(void);
 
 void __init_debug(void)
 {
@@ -187,10 +187,13 @@
 extern int TryEnterDebugSection(void);
 extern long AtomicCompareExchange(long*, long, long);
 extern void LeaveDebugSection(void);
+extern void ValidateRetainBuffer(void);
+extern void InValidateRetainBuffer(void);
 
 void __publish_debug(void)
 {
     retain_offset = 0;
+    InValidateRetainBuffer();
     /* Check there is no running debugger re-configuration */
     if(TryEnterDebugSection()){
         /* Lock buffer */
@@ -217,6 +220,7 @@
         /* when not debugging, do only retain */
         __for_each_variable_do(RetainIterator);
     }
+    ValidateRetainBuffer();
 }
 
 #define __RegisterDebugVariable_case_t(TYPENAME) \