diff Implab/Diagnostics/OperationContext.cs @ 134:04d4c92d0f28 v2

Improved logging
author cin
date Wed, 11 Feb 2015 02:12:15 +0300
parents dc4942d09e74
children ea485487a424
line wrap: on
line diff
--- a/Implab/Diagnostics/OperationContext.cs	Mon Feb 09 00:28:13 2015 +0300
+++ b/Implab/Diagnostics/OperationContext.cs	Wed Feb 11 02:12:15 2015 +0300
@@ -1,9 +1,10 @@
 namespace Implab.Diagnostics {
     struct OperationContext {
-        readonly LogicalOperation m_initial;
         public readonly static OperationContext EMPTY = new OperationContext(LogicalOperation.EMPTY, false);
+
+        LogicalOperation m_initial;
         LogicalOperation m_current;
-        readonly bool m_ownership;
+        bool m_ownership;
 
         public OperationContext(LogicalOperation operation, bool ownership) {
             Safe.ArgumentNotNull(operation, "operation");
@@ -39,14 +40,19 @@
             return detached;
         }
 
-        public void EndLogicalOperation() {
-            if (m_current != m_initial) {
+        public LogicalOperation EndLogicalOperation() {
+            var current = m_current;
+            if (m_current != LogicalOperation.EMPTY && (m_current != m_initial || m_ownership)) {
                 m_current = m_current.Parent;
-            } else if (m_current != LogicalOperation.EMPTY && m_ownership) {
-                m_current = LogicalOperation.EMPTY;
+                if (current == m_initial) {
+                    // we have complete the owned operation
+                    m_initial = m_current;
+                    m_ownership = false;
+                }
             } else {
                 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
             }
+            return current;
         }
 
         public void Leave() {