# HG changeset patch # User cin # Date 2015-01-30 14:07:17 # Node ID 671f60cd0250319594901aa43a488dd8a70dba60 # Parent 471f596b26037cfda5566b4b505fcd2ba38b452d fixed Resove method bug when calling it on already cancelled promise diff --git a/Implab.Diagnostics.Interactive/InteractiveListener.cs b/Implab.Diagnostics.Interactive/InteractiveListener.cs --- a/Implab.Diagnostics.Interactive/InteractiveListener.cs +++ b/Implab.Diagnostics.Interactive/InteractiveListener.cs @@ -14,7 +14,7 @@ namespace Implab.Diagnostics.Interactive TraceForm m_form; SynchronizationContext m_syncGuiThread; - readonly Promise m_guiStarted = new Promise(); + readonly Promise m_guiStarted = new Promise(); readonly IPromise m_guiFinished; // readonly IPromise m_workerFinished = new Promise(); @@ -30,8 +30,8 @@ namespace Implab.Diagnostics.Interactive 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(); } diff --git a/Implab/AbstractPromise.cs b/Implab/AbstractPromise.cs --- a/Implab/AbstractPromise.cs +++ b/Implab/AbstractPromise.cs @@ -39,12 +39,14 @@ namespace Implab { } } - 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() { diff --git a/Implab/Parallels/AsyncQueue.cs b/Implab/Parallels/AsyncQueue.cs --- a/Implab/Parallels/AsyncQueue.cs +++ b/Implab/Parallels/AsyncQueue.cs @@ -187,6 +187,8 @@ namespace Implab.Parallels { 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) diff --git a/Implab/Parallels/SharedLock.cs b/Implab/Parallels/SharedLock.cs --- a/Implab/Parallels/SharedLock.cs +++ b/Implab/Parallels/SharedLock.cs @@ -17,6 +17,7 @@ namespace Implab.Parallels { return false; m_exclusive = true; m_locks = 1; + return true; } } @@ -31,7 +32,7 @@ namespace Implab.Parallels { return true; } - if (m_lock == 0) { + if (m_locks == 0) { m_exclusive = false; m_locks = 1; return true; diff --git a/Implab/PromiseT.cs b/Implab/PromiseT.cs --- a/Implab/PromiseT.cs +++ b/Implab/PromiseT.cs @@ -302,9 +302,10 @@ namespace Implab { 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) {