comparison Implab/Parallels/WorkerPool.cs @ 21:6a56df4ec59e promises

DispatchPool works again, but performance is poor in some cases
author cin
date Tue, 12 Nov 2013 19:52:10 +0400
parents 1c3b3d518480
children dabf79fde388
comparison
equal deleted inserted replaced
20:1c3b3d518480 21:6a56df4ec59e
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 ExtendPool(); 60 if (len > m_threshold*ActiveThreads)
61 } 61 GrowPool();
62
63 protected override bool ExtendPool() {
64 if (m_queueLength <= m_threshold*ActiveThreads)
65 // in this case we are in active thread and it request for additional workers
66 // satisfy it only when queue is longer than threshold
67 return false;
68 return base.ExtendPool();
69 } 62 }
70 63
71 protected override bool TryDequeue(out Action unit) { 64 protected override bool TryDequeue(out Action unit) {
72 if (m_queue.TryDequeue(out unit)) { 65 if (m_queue.TryDequeue(out unit)) {
73 Interlocked.Decrement(ref m_queueLength); 66 Interlocked.Decrement(ref m_queueLength);
78 71
79 protected override void InvokeUnit(Action unit) { 72 protected override void InvokeUnit(Action unit) {
80 unit(); 73 unit();
81 } 74 }
82 75
83 protected override bool Suspend() {
84 if (m_queueLength == 0)
85 return base.Suspend();
86 else
87 return true; // spin again without locks...
88 }
89 } 76 }
90 } 77 }