# HG changeset patch # User cin # Date 2014-10-07 22:19:45 # Node ID ce0171cacec4901ab67b30524551fea7a4f0cf8c # Parent c4877ae77cee283c6d29af0718bab276f09aa91b improved performance of a chained map operation diff --git a/Implab/Parallels/ArrayTraits.cs b/Implab/Parallels/ArrayTraits.cs --- a/Implab/Parallels/ArrayTraits.cs +++ b/Implab/Parallels/ArrayTraits.cs @@ -163,16 +163,18 @@ namespace Implab.Parallels { break; // stop processing in case of error or cancellation var idx = i; - lock(locker) { - while(slots == 0) - Monitor.Wait(locker); - slots--; + if (Interlocked.Decrement(ref slots) < 0) { + lock(locker) { + while(slots < 0) + Monitor.Wait(locker); + } } + try { transform(source[i]) .Anyway(() => { - lock(locker) { - slots ++; + Interlocked.Increment(ref slots); + lock (locker) { Monitor.Pulse(locker); } }) @@ -183,7 +185,7 @@ namespace Implab.Parallels { if (left == 0) promise.Resolve(res); }, - e => promise.Reject(e) + promise.Reject ); } catch (Exception e) { diff --git a/Implab/Parallels/DispatchPool.cs b/Implab/Parallels/DispatchPool.cs --- a/Implab/Parallels/DispatchPool.cs +++ b/Implab/Parallels/DispatchPool.cs @@ -69,7 +69,7 @@ namespace Implab.Parallels { protected abstract bool TryDequeue(out TUnit unit); - private bool Dequeue(out TUnit unit, int timeout) { + bool Dequeue(out TUnit unit, int timeout) { int ts = Environment.TickCount; if (TryDequeue(out unit)) return true;