comparison Implab/Parallels/WorkerPool.cs @ 23:f0568ff069a5

Слияние с promises
author cin
date Wed, 13 Nov 2013 14:03:20 +0400
parents 6a56df4ec59e
children dabf79fde388
comparison
equal deleted inserted replaced
18:0c924dff5498 23:f0568ff069a5
55 protected void EnqueueTask(Action unit) { 55 protected void EnqueueTask(Action unit) {
56 Debug.Assert(unit != null); 56 Debug.Assert(unit != null);
57 var len = Interlocked.Increment(ref m_queueLength); 57 var len = Interlocked.Increment(ref m_queueLength);
58 m_queue.Enqueue(unit); 58 m_queue.Enqueue(unit);
59 59
60 if(!ExtendPool()) 60 if (len > m_threshold*ActiveThreads)
61 WakePool(); 61 GrowPool();
62 }
63
64 protected override bool ExtendPool() {
65 if (m_queueLength <= m_threshold*ThreadCount)
66 // in this case we are in active thread and it request for additional workers
67 // satisfy it only when queue is longer than threshold
68 return false;
69 return base.ExtendPool();
70 } 62 }
71 63
72 protected override bool TryDequeue(out Action unit) { 64 protected override bool TryDequeue(out Action unit) {
73 if (m_queue.TryDequeue(out unit)) { 65 if (m_queue.TryDequeue(out unit)) {
74 Interlocked.Decrement(ref m_queueLength); 66 Interlocked.Decrement(ref m_queueLength);
79 71
80 protected override void InvokeUnit(Action unit) { 72 protected override void InvokeUnit(Action unit) {
81 unit(); 73 unit();
82 } 74 }
83 75
84 protected override void Suspend() {
85 if (m_queueLength == 0)
86 base.Suspend();
87 }
88 } 76 }
89 } 77 }