comparison Implab/Parallels/WorkerPool.cs @ 129:471f596b2603 v2

Added SharedLock to synchronization routines
author cin
date Thu, 29 Jan 2015 18:31:06 +0300
parents 2573b562e328
children eb793fbbe4ea
comparison
equal deleted inserted replaced
128:6241bff0cd64 129:471f596b2603
5 5
6 namespace Implab.Parallels { 6 namespace Implab.Parallels {
7 public class WorkerPool : DispatchPool<Action> { 7 public class WorkerPool : DispatchPool<Action> {
8 8
9 AsyncQueue<Action> m_queue = new AsyncQueue<Action>(); 9 AsyncQueue<Action> m_queue = new AsyncQueue<Action>();
10 int m_queueLength = 0; 10 int m_queueLength;
11 readonly int m_threshold = 1; 11 readonly int m_threshold = 1;
12 12
13 public WorkerPool(int minThreads, int maxThreads, int threshold) 13 public WorkerPool(int minThreads, int maxThreads, int threshold)
14 : base(minThreads, maxThreads) { 14 : base(minThreads, maxThreads) {
15 m_threshold = threshold; 15 m_threshold = threshold;
38 38
39 var promise = new Promise<T>(); 39 var promise = new Promise<T>();
40 40
41 var lop = TraceContext.Instance.CurrentOperation; 41 var lop = TraceContext.Instance.CurrentOperation;
42 42
43 EnqueueTask(delegate() { 43 EnqueueTask(delegate {
44 TraceContext.Instance.EnterLogicalOperation(lop, false); 44 TraceContext.Instance.EnterLogicalOperation(lop, false);
45 try { 45 try {
46 promise.Resolve(task()); 46 promise.Resolve(task());
47 } catch (Exception e) { 47 } catch (Exception e) {
48 promise.Reject(e); 48 promise.Reject(e);