##// END OF EJS Templates
improved performance of a chained map operation
cin -
r89:ce0171cacec4 v2
parent child
Show More
@@ -163,16 +163,18 namespace Implab.Parallels {
163 163 break; // stop processing in case of error or cancellation
164 164 var idx = i;
165 165
166 lock(locker) {
167 while(slots == 0)
168 Monitor.Wait(locker);
169 slots--;
166 if (Interlocked.Decrement(ref slots) < 0) {
167 lock(locker) {
168 while(slots < 0)
169 Monitor.Wait(locker);
170 }
170 171 }
172
171 173 try {
172 174 transform(source[i])
173 175 .Anyway(() => {
174 lock(locker) {
175 slots ++;
176 Interlocked.Increment(ref slots);
177 lock (locker) {
176 178 Monitor.Pulse(locker);
177 179 }
178 180 })
@@ -183,7 +185,7 namespace Implab.Parallels {
183 185 if (left == 0)
184 186 promise.Resolve(res);
185 187 },
186 e => promise.Reject(e)
188 promise.Reject
187 189 );
188 190
189 191 } catch (Exception e) {
@@ -69,7 +69,7 namespace Implab.Parallels {
69 69
70 70 protected abstract bool TryDequeue(out TUnit unit);
71 71
72 private bool Dequeue(out TUnit unit, int timeout) {
72 bool Dequeue(out TUnit unit, int timeout) {
73 73 int ts = Environment.TickCount;
74 74 if (TryDequeue(out unit))
75 75 return true;
General Comments 0
You need to be logged in to leave comments. Login now