Mercurial > pub > ImplabNet
changeset 89:ce0171cacec4 v2
improved performance of a chained map operation
author | cin |
---|---|
date | Wed, 08 Oct 2014 02:19:45 +0400 |
parents | c4877ae77cee |
children | efcb076407a7 |
files | Implab/Parallels/ArrayTraits.cs Implab/Parallels/DispatchPool.cs |
diffstat | 2 files changed, 10 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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) {
--- 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;