Mercurial > pub > ImplabNet
comparison Implab/Parallels/WorkerPool.cs @ 17:7cd4a843b4e4 promises
Improved worker pool
author | cin |
---|---|
date | Fri, 08 Nov 2013 01:25:42 +0400 |
parents | 5a4b735ba669 |
children | 1c3b3d518480 |
comparison
equal
deleted
inserted
replaced
16:5a4b735ba669 | 17:7cd4a843b4e4 |
---|---|
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 (ThreadCount == 0) | 60 if(!ExtendPool()) |
61 // force to start | 61 WakePool(); |
62 WakeNewWorker(false); | |
63 } | 62 } |
64 | 63 |
65 protected override void WakeNewWorker(bool extend) { | 64 protected override bool ExtendPool() { |
66 if (extend && m_queueLength <= m_threshold) | 65 if (m_queueLength <= m_threshold*ThreadCount) |
67 // in this case we are in active thread and it request for additional workers | 66 // in this case we are in active thread and it request for additional workers |
68 // satisfy it only when queue is longer than threshold | 67 // satisfy it only when queue is longer than threshold |
69 return; | 68 return false; |
70 base.WakeNewWorker(extend); | 69 return base.ExtendPool(); |
71 } | 70 } |
72 | 71 |
73 protected override bool TryDequeue(out Action unit) { | 72 protected override bool TryDequeue(out Action unit) { |
74 if (m_queue.TryDequeue(out unit)) { | 73 if (m_queue.TryDequeue(out unit)) { |
75 Interlocked.Decrement(ref m_queueLength); | 74 Interlocked.Decrement(ref m_queueLength); |