changeset 130:671f60cd0250 v2

fixed Resove method bug when calling it on already cancelled promise
author cin
date Fri, 30 Jan 2015 17:07:17 +0300
parents 471f596b2603
children b5c2d609d71b
files Implab.Diagnostics.Interactive/InteractiveListener.cs Implab/AbstractPromise.cs Implab/Parallels/AsyncQueue.cs Implab/Parallels/SharedLock.cs Implab/PromiseT.cs
diffstat 5 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Implab.Diagnostics.Interactive/InteractiveListener.cs	Thu Jan 29 18:31:06 2015 +0300
+++ b/Implab.Diagnostics.Interactive/InteractiveListener.cs	Fri Jan 30 17:07:17 2015 +0300
@@ -14,7 +14,7 @@
         TraceForm m_form;
         
         SynchronizationContext m_syncGuiThread;
-        readonly Promise<object> m_guiStarted = new Promise<object>();
+        readonly Promise m_guiStarted = new Promise();
         
         readonly IPromise m_guiFinished;
         //        readonly IPromise m_workerFinished = new Promise<object>();
@@ -30,8 +30,8 @@
         readonly ManualResetEvent m_pauseEvent = new ManualResetEvent(true);
 
         public InteractiveListener(bool global) : base(global) {
-            m_guiFinished = AsyncPool.InvokeNewThread(GuiThread);
-            /*m_workerFinished = */AsyncPool.InvokeNewThread(QueueThread);
+            m_guiFinished = AsyncPool.RunThread(GuiThread);
+            /*m_workerFinished = */AsyncPool.RunThread(QueueThread);
 
             m_guiStarted.Join();
         }
--- a/Implab/AbstractPromise.cs	Thu Jan 29 18:31:06 2015 +0300
+++ b/Implab/AbstractPromise.cs	Fri Jan 30 17:07:17 2015 +0300
@@ -39,12 +39,14 @@
             }
         }
 
-        protected void BeginSetResult() {
+        protected bool BeginSetResult() {
             if (!BeginTransit()) {
                 WaitTransition();
                 if (m_state != CANCELLED_STATE)
                     throw new InvalidOperationException("The promise is already resolved");
+                return false;
             }
+            return true;
         }
 
         protected void EndSetResult() {
--- a/Implab/Parallels/AsyncQueue.cs	Thu Jan 29 18:31:06 2015 +0300
+++ b/Implab/Parallels/AsyncQueue.cs	Fri Jan 30 17:07:17 2015 +0300
@@ -187,6 +187,8 @@
         public void EnqueueRange(T[] data, int offset, int length) {
             if (data == null)
                 throw new ArgumentNullException("data");
+            if (length == 0)
+                return;
             if (offset < 0)
                 throw new ArgumentOutOfRangeException("offset");
             if (length < 1 || offset + length > data.Length)
--- a/Implab/Parallels/SharedLock.cs	Thu Jan 29 18:31:06 2015 +0300
+++ b/Implab/Parallels/SharedLock.cs	Fri Jan 30 17:07:17 2015 +0300
@@ -17,6 +17,7 @@
                     return false;
                 m_exclusive = true;
                 m_locks = 1;
+                return true;
             }
         }
 
@@ -31,7 +32,7 @@
                     return true;
                 }
 
-                if (m_lock == 0) {
+                if (m_locks == 0) {
                     m_exclusive = false;
                     m_locks = 1;
                     return true;
--- a/Implab/PromiseT.cs	Thu Jan 29 18:31:06 2015 +0300
+++ b/Implab/PromiseT.cs	Fri Jan 30 17:07:17 2015 +0300
@@ -302,9 +302,10 @@
         T m_result;
 
         public virtual void Resolve(T value) {
-            BeginSetResult();
-            m_result = value;
-            EndSetResult();
+            if (BeginSetResult()) {
+                m_result = value;
+                EndSetResult();
+            }
         }
 
         public void Reject(Exception error) {