# HG changeset patch # User cin # Date 1412720385 -14400 # Node ID ce0171cacec4901ab67b30524551fea7a4f0cf8c # Parent c4877ae77cee283c6d29af0718bab276f09aa91b improved performance of a chained map operation diff -r c4877ae77cee -r ce0171cacec4 Implab/Parallels/ArrayTraits.cs --- a/Implab/Parallels/ArrayTraits.cs Tue Oct 07 10:58:38 2014 +0400 +++ b/Implab/Parallels/ArrayTraits.cs Wed Oct 08 02:19:45 2014 +0400 @@ -163,16 +163,18 @@ 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 @@ if (left == 0) promise.Resolve(res); }, - e => promise.Reject(e) + promise.Reject ); } catch (Exception e) { diff -r c4877ae77cee -r ce0171cacec4 Implab/Parallels/DispatchPool.cs --- a/Implab/Parallels/DispatchPool.cs Tue Oct 07 10:58:38 2014 +0400 +++ b/Implab/Parallels/DispatchPool.cs Wed Oct 08 02:19:45 2014 +0400 @@ -69,7 +69,7 @@ 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;