##// END OF EJS Templates
Promises rewritten, added improved version of AsyncQueue
Promises rewritten, added improved version of AsyncQueue

File last commit:

r119:2573b562e328 v2
r119:2573b562e328 v2
Show More
WorkerPool.cs
82 lines | 2.3 KiB | text/x-csharp | CSharpLexer
cin
refactoring, added WorkerPool
r12 using System;
using System.Threading;
using System.Diagnostics;
cin
initial log capabilities
r35 using Implab.Diagnostics;
cin
refactoring, added WorkerPool
r12
namespace Implab.Parallels {
cin
implemented parallel map and foreach for arrays...
r15 public class WorkerPool : DispatchPool<Action> {
cin
refactoring, added WorkerPool
r12
cin
Promises rewritten, added improved version of AsyncQueue
r119 AsyncQueue<Action> m_queue = new AsyncQueue<Action>();
cin
implemented parallel map and foreach for arrays...
r15 int m_queueLength = 0;
cin
sync
r16 readonly int m_threshold = 1;
cin
small fixes, WorkerPool still incomplete
r13
cin
sync
r16 public WorkerPool(int minThreads, int maxThreads, int threshold)
cin
implemented parallel map and foreach for arrays...
r15 : base(minThreads, maxThreads) {
cin
sync
r16 m_threshold = threshold;
InitPool();
}
public WorkerPool(int minThreads, int maxThreads) :
base(minThreads, maxThreads) {
InitPool();
cin
small fixes, WorkerPool still incomplete
r13 }
cin
implemented parallel map and foreach for arrays...
r15 public WorkerPool(int threads)
: base(threads) {
cin
sync
r16 InitPool();
cin
small fixes, WorkerPool still incomplete
r13 }
cin
rewritten tracing
r92 public WorkerPool() {
cin
sync
r16 InitPool();
cin
small fixes, WorkerPool still incomplete
r13 }
cin
refactoring, added WorkerPool
r12 public Promise<T> Invoke<T>(Func<T> task) {
if (task == null)
throw new ArgumentNullException("task");
cin
implemented parallel map and foreach for arrays...
r15 if (IsDisposed)
throw new ObjectDisposedException(ToString());
cin
refactoring, added WorkerPool
r12
var promise = new Promise<T>();
cin
rewritten tracing
r92 var lop = TraceContext.Instance.CurrentOperation;
cin
initial log capabilities
r35
cin
implemented parallel map and foreach for arrays...
r15 EnqueueTask(delegate() {
cin
rewritten tracing
r92 TraceContext.Instance.EnterLogicalOperation(lop, false);
try {
promise.Resolve(task());
} catch (Exception e) {
promise.Reject(e);
} finally {
TraceContext.Instance.Leave();
}
cin
small fixes, WorkerPool still incomplete
r13 });
cin
refactoring, added WorkerPool
r12
return promise;
}
cin
implemented parallel map and foreach for arrays...
r15 protected void EnqueueTask(Action unit) {
Debug.Assert(unit != null);
cin
sync
r16 var len = Interlocked.Increment(ref m_queueLength);
cin
implemented parallel map and foreach for arrays...
r15 m_queue.Enqueue(unit);
cin
sync
r16
cin
dispatch pool rewritten
r81 if (len > m_threshold * PoolSize) {
StartWorker();
cin
added memory barriers
r80 }
cin
dispatch pool rewritten
r81
SignalThread();
cin
refactoring, added WorkerPool
r12 }
cin
implemented parallel map and foreach for arrays...
r15 protected override bool TryDequeue(out Action unit) {
if (m_queue.TryDequeue(out unit)) {
Interlocked.Decrement(ref m_queueLength);
return true;
cin
refactoring, added WorkerPool
r12 }
cin
implemented parallel map and foreach for arrays...
r15 return false;
cin
refactoring, added WorkerPool
r12 }
cin
implemented parallel map and foreach for arrays...
r15 protected override void InvokeUnit(Action unit) {
unit();
cin
refactoring, added WorkerPool
r12 }
cin
sync
r16
cin
refactoring, added WorkerPool
r12 }
}